mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Change default music folder (#225)
* Get default music folder via xdg-user-dirs * Add a test
This commit is contained in:
@@ -14,7 +14,7 @@ default_conf = { 'spotify-downloader':
|
||||
{ 'manual' : False,
|
||||
'no-metadata' : False,
|
||||
'avconv' : False,
|
||||
'folder' : os.path.join(sys.path[0], 'Music'),
|
||||
'folder' : internals.get_music_dir(),
|
||||
'overwrite' : 'prompt',
|
||||
'input-ext' : '.m4a',
|
||||
'output-ext' : '.mp3',
|
||||
|
||||
@@ -141,3 +141,27 @@ def get_splits(url):
|
||||
else:
|
||||
splits = url.split(':')
|
||||
return splits
|
||||
|
||||
|
||||
# a hacky way to user's localized music directory
|
||||
# (thanks @linusg, issue #203)
|
||||
def get_music_dir():
|
||||
home = os.path.expanduser('~')
|
||||
|
||||
# On Linux, the localized folder names are the actual ones.
|
||||
# It's a freedesktop standard though.
|
||||
if sys.platform.startswith('linux'):
|
||||
for file_item in ('.config/user-dirs.dirs', 'user-dirs.dirs'):
|
||||
path = os.path.join(home, file_item)
|
||||
if os.path.isfile(path):
|
||||
with open(path, 'r') as f:
|
||||
for line in f:
|
||||
if line.startswith('XDG_MUSIC_DIR'):
|
||||
return os.path.expandvars(line.strip().split('=')[1].strip('"'))
|
||||
|
||||
# On both Windows and macOS, the localized folder names you see in
|
||||
# Explorer and Finder are actually in English on the file system.
|
||||
# So, defaulting to C:\Users\<user>\Music or /Users/<user>/Music
|
||||
# respectively is sufficient.
|
||||
# On Linux, default to /home/<user>/Music if the above method failed.
|
||||
return os.path.join(home, 'Music')
|
||||
|
||||
Reference in New Issue
Block a user