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:
@@ -10,6 +10,7 @@ before_install:
|
|||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
|
- xdg-user-dirs
|
||||||
- automake
|
- automake
|
||||||
- autoconf
|
- autoconf
|
||||||
- build-essential
|
- build-essential
|
||||||
@@ -36,6 +37,7 @@ install:
|
|||||||
- pip install -e .
|
- pip install -e .
|
||||||
- tinydownload 22684734659253158385 -o ~/bin/ffmpeg
|
- tinydownload 22684734659253158385 -o ~/bin/ffmpeg
|
||||||
- chmod 755 ~/bin/ffmpeg
|
- chmod 755 ~/bin/ffmpeg
|
||||||
|
- xdg-user-dirs-update
|
||||||
script: python -m pytest test --cov=.
|
script: python -m pytest test --cov=.
|
||||||
after_success:
|
after_success:
|
||||||
- pip install codecov
|
- pip install codecov
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ default_conf = { 'spotify-downloader':
|
|||||||
{ 'manual' : False,
|
{ 'manual' : False,
|
||||||
'no-metadata' : False,
|
'no-metadata' : False,
|
||||||
'avconv' : False,
|
'avconv' : False,
|
||||||
'folder' : os.path.join(sys.path[0], 'Music'),
|
'folder' : internals.get_music_dir(),
|
||||||
'overwrite' : 'prompt',
|
'overwrite' : 'prompt',
|
||||||
'input-ext' : '.m4a',
|
'input-ext' : '.m4a',
|
||||||
'output-ext' : '.mp3',
|
'output-ext' : '.mp3',
|
||||||
|
|||||||
@@ -141,3 +141,27 @@ def get_splits(url):
|
|||||||
else:
|
else:
|
||||||
splits = url.split(':')
|
splits = url.split(':')
|
||||||
return splits
|
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')
|
||||||
|
|||||||
@@ -1,6 +1,20 @@
|
|||||||
from core import internals
|
from core import internals
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def test_default_music_directory():
|
||||||
|
if sys.platform.startswith('linux'):
|
||||||
|
output = subprocess.check_output(['xdg-user-dir', 'MUSIC'])
|
||||||
|
expect_directory = output.decode('utf-8').rstrip()
|
||||||
|
else:
|
||||||
|
home = os.path.expanduser('~')
|
||||||
|
expect_directory = os.path.join(home, 'Music')
|
||||||
|
|
||||||
|
directory = internals.get_music_dir()
|
||||||
|
assert directory == expect_directory
|
||||||
|
|
||||||
|
|
||||||
class TestPathFilterer:
|
class TestPathFilterer:
|
||||||
|
|||||||
Reference in New Issue
Block a user