Skip to content

Commit

Permalink
Sanitize filenames with dash
Browse files Browse the repository at this point in the history
  • Loading branch information
infojunkie committed Jun 24, 2024
1 parent 670405d commit 3b175a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/discogs_tag/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_discogs_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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'],
Expand Down

0 comments on commit 3b175a1

Please sign in to comment.