diff --git a/deezer_downloader/cli/deezer-downloader.ini.template b/deezer_downloader/cli/deezer-downloader.ini.template index 08ae05d..3d1049a 100644 --- a/deezer_downloader/cli/deezer-downloader.ini.template +++ b/deezer_downloader/cli/deezer-downloader.ini.template @@ -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 diff --git a/deezer_downloader/configuration.py b/deezer_downloader/configuration.py index 2e7f14e..a61e53d 100644 --- a/deezer_downloader/configuration.py +++ b/deezer_downloader/configuration.py @@ -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']): @@ -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") diff --git a/deezer_downloader/web/music_backend.py b/deezer_downloader/web/music_backend.py index 633874e..a072421 100644 --- a/deezer_downloader/web/music_backend.py +++ b/deezer_downloader/web/music_backend.py @@ -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'], @@ -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