mirror of
https://gitlab.com/RemixDev/deemix-js.git
synced 2025-01-29 17:18:27 +00:00
Added check for windows music folder
This commit is contained in:
parent
84be4730af
commit
d3ab8e72e6
|
@ -1,4 +1,5 @@
|
|||
const { TrackFormats } = require('deezer-js')
|
||||
const { getMusicFolder } = require('./utils/localpaths.js')
|
||||
|
||||
// Should the lib overwrite files?
|
||||
const OverwriteOption = {
|
||||
|
@ -18,7 +19,7 @@ const FeaturesOption = {
|
|||
}
|
||||
|
||||
const DEFAULTS = {
|
||||
downloadLocation: "",
|
||||
downloadLocation: getMusicFolder(),
|
||||
tracknameTemplate: "%artist% - %title%",
|
||||
albumTracknameTemplate: "%tracknumber% - %title%",
|
||||
playlistTracknameTemplate: "%position% - %artist% - %title%",
|
||||
|
|
|
@ -13,51 +13,73 @@ function checkPath(path){
|
|||
return path
|
||||
}
|
||||
|
||||
if (process.env.XDG_CONFIG_HOME && userdata === ""){
|
||||
userdata = `${process.env.XDG_CONFIG_HOME}${sep}`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (process.env.APPDATA && userdata === ""){
|
||||
userdata = `${process.env.APPDATA}${sep}`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (process.platform == "darwin" && userdata === ""){
|
||||
userdata = `${homedata}/Library/Application Support/`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (userdata === ""){
|
||||
userdata = `${homedata}${sep}.config${sep}`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (userdata === "") userdata = `${process.cwd()}${sep}config${sep}`
|
||||
else userdata += `deemix${sep}`
|
||||
function getConfigFolder(){
|
||||
if (userdata != "") return userdata
|
||||
if (process.env.XDG_CONFIG_HOME && userdata === ""){
|
||||
userdata = `${process.env.XDG_CONFIG_HOME}${sep}`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (process.env.APPDATA && userdata === ""){
|
||||
userdata = `${process.env.APPDATA}${sep}`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (process.platform == "darwin" && userdata === ""){
|
||||
userdata = `${homedata}/Library/Application Support/`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (userdata === ""){
|
||||
userdata = `${homedata}${sep}.config${sep}`
|
||||
userdata = checkPath(userdata)
|
||||
}
|
||||
if (userdata === "") userdata = `${process.cwd()}${sep}config${sep}`
|
||||
else userdata += `deemix${sep}`
|
||||
|
||||
|
||||
if (process.env.XDG_MUSIC_DIR && musicdata === ""){
|
||||
musicdata = `${process.env.XDG_MUSIC_DIR}${sep}`
|
||||
musicdata = checkPath(musicdata)
|
||||
}
|
||||
if (fs.existsSync(`${homedata}${sep}.config${sep}user-dirs.dirs`)){
|
||||
const userDirs = fs.readFileSync(`${homedata}${sep}.config${sep}user-dirs.dirs`).toString()
|
||||
musicdata = userDirs.match(/XDG_MUSIC_DIR="(.*)"/)[1]
|
||||
musicdata = musicdata.replace(/\$([A-Z_]+[A-Z0-9_]*)/ig, (_, envName) => process.env[envName])
|
||||
musicdata = checkPath(musicdata)
|
||||
}
|
||||
if (process.platform == 'win32'){
|
||||
const musicKeys = ["My Music", "{4BD8D571-6D19-48D3-BE97-422220080E43}"]
|
||||
}
|
||||
if (musicdata === ""){
|
||||
musicdata = `${homedata}${sep}Music${sep}`
|
||||
musicdata = checkPath(musicdata)
|
||||
if (process.env.DEEMIX_DATA_DIR) userdata = process.env.DEEMIX_DATA_DIR
|
||||
return userdata
|
||||
}
|
||||
|
||||
if (musicdata === "") musicdata = `${process.cwd()}${sep}music${sep}`
|
||||
else musicdata += `deemix Music${sep}`
|
||||
function getMusicFolder(){
|
||||
if (musicdata != "") return musicdata
|
||||
if (process.env.XDG_MUSIC_DIR && musicdata === ""){
|
||||
musicdata = `${process.env.XDG_MUSIC_DIR}${sep}`
|
||||
musicdata = checkPath(musicdata)
|
||||
}
|
||||
if (fs.existsSync(`${homedata}${sep}.config${sep}user-dirs.dirs`)){
|
||||
const userDirs = fs.readFileSync(`${homedata}${sep}.config${sep}user-dirs.dirs`).toString()
|
||||
musicdata = userDirs.match(/XDG_MUSIC_DIR="(.*)"/)[1]
|
||||
musicdata = musicdata.replace(/\$([A-Z_]+[A-Z0-9_]*)/ig, (_, envName) => process.env[envName])
|
||||
musicdata += sep
|
||||
musicdata = checkPath(musicdata)
|
||||
}
|
||||
if (process.platform == 'win32' && musicdata === ""){
|
||||
const { execSync } = require('child_process')
|
||||
const musicKeys = ["My Music", "{4BD8D571-6D19-48D3-BE97-422220080E43}"]
|
||||
let regData = execSync('reg.exe query "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"').toString().split('\r\n')
|
||||
for (let i = 0; i < regData.length; i++){
|
||||
let line = regData[i]
|
||||
if (line === "") continue
|
||||
if (i == 1) continue
|
||||
line = line.split(' ')
|
||||
if (musicKeys.includes(line[1])){
|
||||
musicdata = line[3] + sep
|
||||
break;
|
||||
}
|
||||
}
|
||||
musicdata = checkPath(musicdata)
|
||||
}
|
||||
if (musicdata === ""){
|
||||
musicdata = `${homedata}${sep}Music${sep}`
|
||||
musicdata = checkPath(musicdata)
|
||||
}
|
||||
|
||||
if (process.env.DEEMIX_DATA_DIR) userdata = process.env.DEEMIX_DATA_DIR
|
||||
if (process.env.DEEMIX_MUSIC_DIR) musicdata = process.env.DEEMIX_MUSIC_DIR
|
||||
if (musicdata === "") musicdata = `${process.cwd()}${sep}music${sep}`
|
||||
else musicdata += `deemix Music${sep}`
|
||||
|
||||
if (process.env.DEEMIX_MUSIC_DIR) musicdata = process.env.DEEMIX_MUSIC_DIR
|
||||
return musicdata
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
userdata,
|
||||
musicdata
|
||||
getConfigFolder,
|
||||
getMusicFolder
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue