mirror of
https://gitlab.com/RemixDev/deemix-js.git
synced 2024-12-29 10:56:18 +00:00
Added localpaths.js
This commit is contained in:
parent
a6a4491f42
commit
84be4730af
|
@ -72,6 +72,7 @@ module.exports = {
|
|||
parseLink,
|
||||
generateDownloadObject,
|
||||
types: {
|
||||
...require('./types/index.js'),
|
||||
...require('./types/Album.js'),
|
||||
...require('./types/Artist.js'),
|
||||
...require('./types/Date.js'),
|
||||
|
@ -79,6 +80,23 @@ module.exports = {
|
|||
...require('./types/Picture.js'),
|
||||
...require('./types/Playlist.js'),
|
||||
...require('./types/Track.js'),
|
||||
downloadObjects: require('./types/DownloadObjects.js')
|
||||
},
|
||||
downloader: require('./downloader.js')
|
||||
itemgen: {
|
||||
generateTrackItem,
|
||||
generateAlbumItem,
|
||||
generatePlaylistItem,
|
||||
generateArtistItem,
|
||||
generateArtistDiscographyItem,
|
||||
generateArtistTopItem
|
||||
},
|
||||
settings: require('./settings.js'),
|
||||
downloader: require('./downloader.js'),
|
||||
decryption: require('./decryption.js'),
|
||||
tagger: require('./tagger.js'),
|
||||
utils: {
|
||||
...require('./utils/index.js'),
|
||||
localpaths: require('./utils/localpaths.js'),
|
||||
pathtemplates: require('./utils/pathtemplates.js')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
const stream = require('stream')
|
||||
const {promisify} = require('util')
|
||||
const pipeline = promisify(stream.pipeline)
|
||||
const { accessSync, constants } = require('fs')
|
||||
|
||||
const USER_AGENT_HEADER = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
|
||||
|
||||
function canWrite(path){
|
||||
try{
|
||||
accessSync(path, constants.R_OK | constants.W_OK)
|
||||
}catch{
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function generateReplayGainString(trackGain){
|
||||
return `${Math.round((parseFloat(trackGain) + 18.4)*-100)/100} dB`
|
||||
}
|
||||
|
@ -63,5 +73,6 @@ module.exports = {
|
|||
andCommaConcat,
|
||||
uniqueArray,
|
||||
removeDuplicateArtists,
|
||||
pipeline
|
||||
pipeline,
|
||||
canWrite
|
||||
}
|
||||
|
|
63
deemix/utils/localpaths.js
Normal file
63
deemix/utils/localpaths.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
const { sep } = require('path')
|
||||
const { homedir } = require('os')
|
||||
const fs = require('fs')
|
||||
const { canWrite } = require('./index.js')
|
||||
|
||||
let homedata = homedir()
|
||||
let userdata = ""
|
||||
let musicdata = ""
|
||||
|
||||
function checkPath(path){
|
||||
if (!fs.existsSync(path)) return ""
|
||||
if (!canWrite(path)) return ""
|
||||
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}`
|
||||
|
||||
|
||||
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 (musicdata === "") musicdata = `${process.cwd()}${sep}music${sep}`
|
||||
else musicdata += `deemix Music${sep}`
|
||||
|
||||
if (process.env.DEEMIX_DATA_DIR) userdata = process.env.DEEMIX_DATA_DIR
|
||||
if (process.env.DEEMIX_MUSIC_DIR) musicdata = process.env.DEEMIX_MUSIC_DIR
|
||||
|
||||
module.exports = {
|
||||
userdata,
|
||||
musicdata
|
||||
}
|
3678
package-lock.json
generated
3678
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue