Made -p cli argument create only that folder and not the default one

Moved default download folder inside music
Check XDG first, then fallback to untranslated 'Music' folder
This fixes #82
This commit is contained in:
RemixDev 2020-10-29 13:00:58 +01:00
parent 97f9258de9
commit 7fd0bfaa07
4 changed files with 49 additions and 20 deletions

View File

@ -4,8 +4,8 @@ from deemix.app.queuemanager import QueueManager
from deemix.app.spotifyhelper import SpotifyHelper from deemix.app.spotifyhelper import SpotifyHelper
class deemix: class deemix:
def __init__(self, configFolder=None): def __init__(self, configFolder=None, overwriteDownloadFolder=None):
self.set = Settings(configFolder) self.set = Settings(configFolder, overwriteDownloadFolder=overwriteDownloadFolder)
self.dz = Deezer() self.dz = Deezer()
self.dz.set_accept_language(self.set.settings.get('tagsLanguage')) self.dz.set_accept_language(self.set.settings.get('tagsLanguage'))
self.sp = SpotifyHelper(configFolder) self.sp = SpotifyHelper(configFolder)

View File

@ -6,10 +6,8 @@ from deemix.utils import checkFolder
class cli(deemix): class cli(deemix):
def __init__(self, downloadpath, configFolder=None): def __init__(self, downloadpath, configFolder=None):
super().__init__(configFolder) super().__init__(configFolder, overwriteDownloadFolder=downloadpath)
if downloadpath: if downloadpath:
if checkFolder(downloadpath):
self.set.settings['downloadLocation'] = str(downloadpath)
print("Using folder: "+self.set.settings['downloadLocation']) print("Using folder: "+self.set.settings['downloadLocation'])
def downloadLink(self, url, bitrate=None): def downloadLink(self, url, bitrate=None):

View File

@ -47,7 +47,7 @@ class FeaturesOption():
"""Move to track title""" """Move to track title"""
DEFAULT_SETTINGS = { DEFAULT_SETTINGS = {
"downloadLocation": str(localpaths.getHomeFolder() / 'deemix Music'), "downloadLocation": str(localpaths.getMusicFolder()),
"tracknameTemplate": "%artist% - %title%", "tracknameTemplate": "%artist% - %title%",
"albumTracknameTemplate": "%tracknumber% - %title%", "albumTracknameTemplate": "%tracknumber% - %title%",
"playlistTracknameTemplate": "%position% - %artist% - %title%", "playlistTracknameTemplate": "%position% - %artist% - %title%",
@ -128,7 +128,7 @@ DEFAULT_SETTINGS = {
} }
class Settings: class Settings:
def __init__(self, configFolder=None): def __init__(self, configFolder=None, overwriteDownloadFolder=None):
self.settings = {} self.settings = {}
self.configFolder = Path(configFolder or localpaths.getConfigFolder()) self.configFolder = Path(configFolder or localpaths.getConfigFolder())
@ -144,11 +144,27 @@ class Settings:
with open(self.configFolder / 'config.json', 'r') as configFile: with open(self.configFolder / 'config.json', 'r') as configFile:
self.settings = json.load(configFile) self.settings = json.load(configFile)
# Make sure the download path exsits # Check for overwriteDownloadFolder
if not checkFolder(self.settings['downloadLocation']) and self.settings['downloadLocation'] != "": # This prevents the creation of the original download folder when
self.settings['downloadLocation'] = "" # using overwriteDownloadFolder
originalDownloadFolder = self.settings['downloadLocation']
if overwriteDownloadFolder:
overwriteDownloadFolder = str(overwriteDownloadFolder)
self.settings['downloadLocation'] = overwriteDownloadFolder
self.settingsCheck() # Make sure the download path exsits, fallback to default
invalidDownloadFolder = False
if self.settings['downloadLocation'] == "" or not checkFolder(self.settings['downloadLocation']):
self.settings['downloadLocation'] = DEFAULT_SETTINGS['downloadLocation']
originalDownloadFolder = self.settings['downloadLocation']
invalidDownloadFolder = True
# Check the settings and save them if something changed
if self.settingsCheck() > 0 or invalidDownloadFolder:
makedirs(self.settings['downloadLocation'], exist_ok=True)
self.settings['downloadLocation'] = originalDownloadFolder # Prevents the saving of the overwritten path
self.saveSettings()
self.settings['downloadLocation'] = overwriteDownloadFolder or originalDownloadFolder # Restores the correct path
# LOGFILES # LOGFILES
@ -196,11 +212,9 @@ class Settings:
changes += 1 changes += 1
if self.settings['downloadLocation'] == "": if self.settings['downloadLocation'] == "":
self.settings['downloadLocation'] = DEFAULT_SETTINGS['downloadLocation'] self.settings['downloadLocation'] = DEFAULT_SETTINGS['downloadLocation']
makedirs(self.settings['downloadLocation'], exist_ok=True)
changes += 1 changes += 1
for template in ['tracknameTemplate', 'albumTracknameTemplate', 'playlistTracknameTemplate', 'playlistNameTemplate', 'artistNameTemplate', 'albumNameTemplate', 'playlistFilenameTemplate', 'coverImageTemplate', 'artistImageTemplate', 'paddingSize']: for template in ['tracknameTemplate', 'albumTracknameTemplate', 'playlistTracknameTemplate', 'playlistNameTemplate', 'artistNameTemplate', 'albumNameTemplate', 'playlistFilenameTemplate', 'coverImageTemplate', 'artistImageTemplate', 'paddingSize']:
if self.settings[template] == "": if self.settings[template] == "":
self.settings[template] = DEFAULT_SETTINGS[template] self.settings[template] = DEFAULT_SETTINGS[template]
changes += 1 changes += 1
if changes > 0: return changes
self.saveSettings()

View File

@ -1,21 +1,38 @@
from pathlib import Path from pathlib import Path
import sys import sys
from os import getenv import os
userdata = ""
homedata = Path.home() homedata = Path.home()
userdata = ""
musicdata = ""
if getenv("APPDATA"):
userdata = Path(getenv("APPDATA")) / "deemix" if os.getenv("XDG_CONFIG_HOME"):
userdata = Path(os.getenv("XDG_CONFIG_HOME")) / 'deemix'
elif os.getenv("APPDATA"):
userdata = Path(os.getenv("APPDATA")) / "deemix"
elif sys.platform.startswith('darwin'): elif sys.platform.startswith('darwin'):
userdata = homedata / 'Library' / 'Application Support' / 'deemix' userdata = homedata / 'Library' / 'Application Support' / 'deemix'
elif getenv("XDG_CONFIG_HOME"):
userdata = Path(getenv("XDG_CONFIG_HOME")) / 'deemix'
else: else:
userdata = homedata / '.config' / 'deemix' userdata = homedata / '.config' / 'deemix'
if os.getenv("XDG_MUSIC_DIR"):
musicdata = Path(os.getenv("XDG_MUSIC_DIR")) / "deemix Music"
elif os.name == 'nt':
import winreg
sub_key = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
music_guid = '{4BD8D571-6D19-48D3-BE97-422220080E43}'
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key) as key:
location = winreg.QueryValueEx(key, music_guid)[0]
musicdata = Path(location) / "deemix Music"
else:
musicdata = homedata / "Music" / "deemix Music"
def getHomeFolder(): def getHomeFolder():
return homedata return homedata
def getConfigFolder(): def getConfigFolder():
return userdata return userdata
def getMusicFolder():
return musicdata