Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions deezer_downloader/cli/deezer-downloader.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ quality = mp3
; command = /home/kmille/projects/deezer-downloader/app/venv/bin/yt-dlp
command = /usr/bin/yt-dlp

[filename]
; n = Track number on 2 digit
; b = Album name
; a = Artist name
; t = Song title
; d = Disk number
song_name = "{n} - {t}"
album_name = "{a}/{b}"

; vim: syntax=dosini
4 changes: 2 additions & 2 deletions deezer_downloader/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def load_config(config_abs):
config = ConfigParser()
config.read(config_abs)

assert list(config.keys()) == ['DEFAULT', 'mpd', 'download_dirs', 'debug', 'http', 'proxy', 'threadpool', 'deezer', 'youtubedl'], f"Validating config file failed. Check {config_abs}"
assert list(config.keys()) == ['DEFAULT', 'mpd', 'download_dirs', 'debug', 'http', 'proxy', 'threadpool', 'deezer', 'youtubedl', 'filename'], f"Validating config file failed. Check {config_abs}"

if config['mpd'].getboolean('use_mpd'):
if not config['mpd']['music_dir_root'].startswith(config['download_dirs']['base']):
Expand All @@ -43,7 +43,7 @@ def load_config(config_abs):

if "DEEZER_QUALITY" in os.environ.keys():
config["deezer"]["quality"] = os.environ["DEEZER_QUALITY"]

if "quality" in config['deezer']:
if config['deezer']["quality"] not in ("mp3", "flac"):
print("ERROR: quality must be mp3 or flac in config file")
Expand Down
22 changes: 13 additions & 9 deletions deezer_downloader/web/music_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,25 @@ def clean_filename(path):
path = path.replace("\t", " ")
if any(platform.win32_ver()):
path.replace("\"", "'")
array_of_special_characters = ['<', '>', ':', '"', '/', '\\', '|', '?', '*']
array_of_special_characters = ['<', '>', ':', '"', '\\', '|', '?', '*']
else:
array_of_special_characters = ['/', ':', '"', '?']
array_of_special_characters = [':', '"', '?']

return ''.join([c for c in path if c not in array_of_special_characters])


def download_song_and_get_absolute_filename(search_type, song, playlist_name=None):

file_extension = get_file_extension()
pattern = {
"n": str(song['TRACK_NUMBER']).zfill(2),
"b": song['ALB_TITLE'],
"a": song['ART_NAME'],
"t": song['SNG_TITLE'],
"d": song['DISK_NUMBER'],
}

if search_type == TYPE_ALBUM:
song_filename = "{:02d} - {} {}.{}".format(int(song['TRACK_NUMBER']),
song['ART_NAME'],
song['SNG_TITLE'],
file_extension)
song_filename = config['filename']['song_name'].format(**pattern) + f'''.{file_extension}'''
else:
song_filename = "{} - {}.{}".format(song['ART_NAME'],
song['SNG_TITLE'],
Expand All @@ -94,11 +98,11 @@ def download_song_and_get_absolute_filename(search_type, song, playlist_name=Non
if search_type == TYPE_TRACK:
absolute_filename = os.path.join(config["download_dirs"]["songs"], song_filename)
elif search_type == TYPE_ALBUM:
album_name = "{} - {}".format(song['ART_NAME'], song['ALB_TITLE'])
album_name = config['filename']['album_name'].format(**pattern)
album_name = clean_filename(album_name)
album_dir = os.path.join(config["download_dirs"]["albums"], album_name)
if not os.path.exists(album_dir):
os.mkdir(album_dir)
os.makedirs(album_dir)
absolute_filename = os.path.join(album_dir, song_filename)
elif search_type == TYPE_PLAYLIST:
assert type(playlist_name) is str
Expand Down