From 3b175a126541580ef3a9849a30ec473b64b5521f Mon Sep 17 00:00:00 2001 From: infojunkie Date: Sun, 23 Jun 2024 17:42:29 -0700 Subject: [PATCH] Sanitize filenames with dash --- pyproject.toml | 2 +- src/discogs_tag/cli.py | 4 ++-- tests/test_discogs_tag.py | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a845935..47dfadc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "discogs-tag" -version = "0.4.0" +version = "0.4.1" description = "A rudimentary audio tagger based on Discogs metadata." authors = ["infojunkie "] readme = "README.md" diff --git a/src/discogs_tag/cli.py b/src/discogs_tag/cli.py index 4c3cb55..75f2b4b 100644 --- a/src/discogs_tag/cli.py +++ b/src/discogs_tag/cli.py @@ -248,7 +248,7 @@ def rename_path(src_root, audio, format, options): # Expand tags in each path component. paths = [] for dir in format.split('/')[:-1]: - paths.append(sanitize_filename(rename_component(audio, dir, options))) + paths.append(sanitize_filename(rename_component(audio, dir, options), replacement_text='-')) if not paths: return src_root, src_root @@ -276,7 +276,7 @@ def rename_file(src_file, dst_path, audio, format, options): filename += ext # Sanitize the filename. - filename = sanitize_filename(filename) + filename = sanitize_filename(filename, replacement_text='-') # Add the original path. dst_file = os.path.join(dst_path, filename) diff --git a/tests/test_discogs_tag.py b/tests/test_discogs_tag.py index 7b7352e..51eefeb 100644 --- a/tests/test_discogs_tag.py +++ b/tests/test_discogs_tag.py @@ -108,6 +108,17 @@ def test_rename_path(): 'title': ['Title'], 'date': ['2024'] }, '%z - (%y) %b/%d-%n %t', parse_options({ 'dry': True, 'ignore': False })) + assert ('/src/path/Album Artist - (2024) Album1 - Album2', '/src/path/Album Artist - (2024) Album1 - Album2') == rename_path('/src/path/from', { + 'artist': ['Artist'], + 'albumartist': ['Album Artist'], + 'album': ['Album1 / Album2'], + 'composer': ['Composer'], + 'discnumber': ['1'], + 'genre': ['Genre'], + 'tracknumber': [2], + 'title': ['Title'], + 'date': ['2024'] + }, '%z - (%y) %b/%d-%n %t', parse_options({ 'dry': True, 'ignore': False })) assert ('/src/path/from', '/src/path/from') == rename_path('/src/path/from', { 'artist': ['Artist'], 'albumartist': ['Album Artist'], @@ -143,6 +154,17 @@ def test_rename_file(): 'title': ['Title'], 'date': ['2024'] }, '%z - (%y) %b/%d-%n %t', parse_options({ 'dry': True, 'ignore': False })) + assert '/dest/path/to/1-02 Artist1 - Artist2 - Title1 - Title2.flac' == rename_file('/src/path/from/test.flac', '/dest/path/to', { + 'artist': ['Artist1 / Artist2'], + 'albumartist': ['Album Artist'], + 'album': ['Album'], + 'composer': ['Composer'], + 'discnumber': ['1'], + 'genre': ['Genre'], + 'tracknumber': [2], + 'title': ['Title1 / Title2'], + 'date': ['2024'] + }, '%z - (%y) %b/%d-%n %a - %t', parse_options({ 'dry': True, 'ignore': False })) assert '/dest/path/to/test.flac' == rename_file('/src/path/from/test.flac', '/dest/path/to', { 'artist': ['Artist'], 'albumartist': ['Album Artist'],