From 6295bc2380ab0b53aaff606291f4d2fcc152af82 Mon Sep 17 00:00:00 2001 From: Josef Friedrich Date: Fri, 15 Nov 2024 13:50:29 +0100 Subject: [PATCH] Fix all tests --- README.rst | 96 ++++++++++++++++++++++++++++------------ audiorename/meta.py | 18 +++++--- poetry.lock | 44 +++++++++--------- tests/test_all_fields.py | 2 +- tests/test_meta.py | 91 ++++--------------------------------- 5 files changed, 111 insertions(+), 140 deletions(-) diff --git a/README.rst b/README.rst index 7820b38..0fb6efb 100644 --- a/README.rst +++ b/README.rst @@ -65,9 +65,14 @@ Usage :: - usage: audiorenamer [-h] [--config CONFIG] [-v] [-t TARGET] [-a] [-p BACKUP_FOLDER] [-B] [-d] [-C | -M | -n] [-A | -D] [-F] [-m ALBUM_MIN] [-e EXTENSION] - [--genre-classical GENRE_CLASSICAL] [-s FIELD_SKIP] [-k] [-S] [--no-soundtrack] [-f PATH_TEMPLATE] [-c PATH_TEMPLATE] [--soundtrack PATH_TEMPLATE] - [--format-classical PATH_TEMPLATE] [-K | --no-color] [-b] [-j] [-l] [-o] [-T] [-V] [-E] [-r] + usage: audiorenamer [-h] [--config CONFIG] [-v] [-t TARGET] [-a] + [-p BACKUP_FOLDER] [-B] [-d] [-C | -M | -n] [-A | -D] [-F] + [-m ALBUM_MIN] [-e EXTENSION] + [--genre-classical GENRE_CLASSICAL] [-s FIELD_SKIP] [-k] + [-S] [--no-soundtrack] [-f PATH_TEMPLATE] + [-c PATH_TEMPLATE] [--soundtrack PATH_TEMPLATE] + [--format-classical PATH_TEMPLATE] [-K | --no-color] [-b] + [-j] [-l] [-o] [-T] [-V] [-E] [-r] source Rename audio files from metadata tags. @@ -698,8 +703,11 @@ Usage [selection]: The following arguments are intended to select the audio files. - source A folder containing audio files or a single audio file. If you specify a folder, the program will search for audio files in all subfolders. If you want to - rename the audio files in the current working directory, then specify a dot (“.”). + source A folder containing audio files or a single audio + file. If you specify a folder, the program will search + for audio files in all subfolders. If you want to + rename the audio files in the current working + directory, then specify a dot (“.”). -t TARGET, --target TARGET Target directory -a, --source-as-target @@ -710,19 +718,27 @@ Usage -p BACKUP_FOLDER, --backup-folder BACKUP_FOLDER Folder to store the backup files in. - -B, --best-format Use the best format. This option only takes effect if the target file already exists. `audiorename` now checks the qualtity of the two audio files (source and - target). The tool first examines the format. For example a FLAC file wins over a MP3 file. Then `audiorename` checks the bitrate. + -B, --best-format Use the best format. This option only takes effect if + the target file already exists. `audiorename` now + checks the qualtity of the two audio files (source and + target). The tool first examines the format. For + example a FLAC file wins over a MP3 file. Then + `audiorename` checks the bitrate. -d, --dry-run Don’t rename or copy the audio files. move action: -C, --copy Copy files instead of rename / move. - -M, --move Move / rename a file. This is the default action. The option can be omitted. - -n, --no-rename Don’t rename, move, copy or perform a dry run. Do nothing. + -M, --move Move / rename a file. This is the default action. The + option can be omitted. + -n, --no-rename Don’t rename, move, copy or perform a dry run. Do + nothing. cleaning action: The cleaning actions are only executed if the target file already exists. - -A, --backup Backup the audio files instead of deleting them. The backup directory can be specified with the --backup-folder option. + -A, --backup Backup the audio files instead of deleting them. The + backup directory can be specified with the --backup- + folder option. -D, --delete Delete the audio files instead of creating a backup. [filters]: @@ -739,43 +755,67 @@ Usage Skip renaming if field is empty. [template_settings]: - -k, --classical Use the default format for classical music. If you use this option, both parameters (--default and --compilation) have no effect. Classical music is sorted by - the lastname of the composer. - -S, --shell-friendly Rename audio files “shell friendly”, this means without whitespaces, parentheses etc. - --no-soundtrack Do not use the path template for soundtracks. Use instead the default path template. + -k, --classical Use the default format for classical music. If you use + this option, both parameters (--default and + --compilation) have no effect. Classical music is + sorted by the lastname of the composer. + -S, --shell-friendly Rename audio files “shell friendly”, this means + without whitespaces, parentheses etc. + --no-soundtrack Do not use the path template for soundtracks. Use + instead the default path template. [path_templates]: audiorename provides default path templates. You can specify your own path templates using the following options. -f PATH_TEMPLATE, --default PATH_TEMPLATE, --format PATH_TEMPLATE - The default path template for audio files that are not compilations or compilations. Use metadata fields and functions to build the path template. + The default path template for audio files that are not + compilations or compilations. Use metadata fields and + functions to build the path template. -c PATH_TEMPLATE, --compilation PATH_TEMPLATE - Path template for compilations. Use metadata fields and functions to build the path template. + Path template for compilations. Use metadata fields + and functions to build the path template. --soundtrack PATH_TEMPLATE - Path template for a soundtrack audio file. Use metadata fields and functions to build the path template. + Path template for a soundtrack audio file. Use + metadata fields and functions to build the path + template. --format-classical PATH_TEMPLATE - Path template for classical audio file. Use metadata fields and functions to build the path template. + Path template for classical audio file. Use metadata + fields and functions to build the path template. [cli_output]: This group contains all options that affect the output on the command line interface (cli). - -K, --color Colorize the standard output of the program with ANSI colors. - --no-color Don’t colorize the standard output of the program with ANSI colors. - -b, --debug Print debug informations about the single metadata fields. - -j, --job-info Display informations about the current job. This informations are printted out before any actions on the audio files are executed. + -K, --color Colorize the standard output of the program with ANSI + colors. + --no-color Don’t colorize the standard output of the program with + ANSI colors. + -b, --debug Print debug informations about the single metadata + fields. + -j, --job-info Display informations about the current job. This + informations are printted out before any actions on + the audio files are executed. -l, --mb-track-listing - Print track listing for Musicbrainz website: Format: track. title (duration), e. g.: 1. He, Zigeuner (1:31) 2. Hochgetürmte Rimaflut (1:21) - -o, --one-line Display the rename / copy action status on one line instead of two. + Print track listing for Musicbrainz website: Format: + track. title (duration), e. g.: 1. He, Zigeuner (1:31) + 2. Hochgetürmte Rimaflut (1:21) + -o, --one-line Display the rename / copy action status on one line + instead of two. -T, --stats Show statistics at the end of the execution. -V, --verbose Make the command line output more verbose. [metadata_actions]: -E, --enrich-metadata - Fetch the tag fields “work” and “mb_workid” from Musicbrainz and save this fields into the audio file. The audio file must have the tag field “mb_trackid”. The - give audio file is not renamed. + Fetch the tag fields “work” and “mb_workid” from + Musicbrainz and save this fields into the audio file. + The audio file must have the tag field “mb_trackid”. + The give audio file is not renamed. -r, --remap-classical - Remap some fields to fit better for classical music: “composer” becomes “artist”, “work” becomes “album”, from the “title” the work prefix is removed - (“Symphonie No. 9: I. Allegro” -> “I. Allegro”) and “track” becomes the movement number. All overwritten fields are safed in the “comments” field. + Remap some fields to fit better for classical music: + “composer” becomes “artist”, “work” becomes “album”, + from the “title” the work prefix is removed + (“Symphonie No. 9: I. Allegro” -> “I. Allegro”) and + “track” becomes the movement number. All overwritten + fields are safed in the “comments” field. Configuration files =================== diff --git a/audiorename/meta.py b/audiorename/meta.py index cb814f0..0229fd9 100644 --- a/audiorename/meta.py +++ b/audiorename/meta.py @@ -625,13 +625,19 @@ def ar_performer_short(self): return ", ".join(out) @property - def ar_combined_soundtrack(self): - if ( - self.releasegroup_types and "soundtrack" in self.releasegroup_types.lower() - ) or (self.albumtype and "soundtrack" in self.albumtype.lower()): + def ar_combined_soundtrack(self) -> bool: + if self.releasegroup_types and "soundtrack" in self.releasegroup_types.lower(): return True - else: - return False + + if self.albumtype and "soundtrack" in self.albumtype.lower(): + return True + + if self.albumtypes: + for type in self.albumtypes: + if "soundtrack" in type.lower(): + return True + + return False @property def ar_classical_title(self) -> Optional[str]: diff --git a/poetry.lock b/poetry.lock index 2f57845..6d0dd1d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -699,29 +699,29 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.7.3" +version = "0.7.4" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.7.3-py3-none-linux_armv6l.whl", hash = "sha256:34f2339dc22687ec7e7002792d1f50712bf84a13d5152e75712ac08be565d344"}, - {file = "ruff-0.7.3-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:fb397332a1879b9764a3455a0bb1087bda876c2db8aca3a3cbb67b3dbce8cda0"}, - {file = "ruff-0.7.3-py3-none-macosx_11_0_arm64.whl", hash = "sha256:37d0b619546103274e7f62643d14e1adcbccb242efda4e4bdb9544d7764782e9"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d59f0c3ee4d1a6787614e7135b72e21024875266101142a09a61439cb6e38a5"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:44eb93c2499a169d49fafd07bc62ac89b1bc800b197e50ff4633aed212569299"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6d0242ce53f3a576c35ee32d907475a8d569944c0407f91d207c8af5be5dae4e"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:6b6224af8b5e09772c2ecb8dc9f3f344c1aa48201c7f07e7315367f6dd90ac29"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c50f95a82b94421c964fae4c27c0242890a20fe67d203d127e84fbb8013855f5"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7f3eff9961b5d2644bcf1616c606e93baa2d6b349e8aa8b035f654df252c8c67"}, - {file = "ruff-0.7.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8963cab06d130c4df2fd52c84e9f10d297826d2e8169ae0c798b6221be1d1d2"}, - {file = "ruff-0.7.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:61b46049d6edc0e4317fb14b33bd693245281a3007288b68a3f5b74a22a0746d"}, - {file = "ruff-0.7.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:10ebce7696afe4644e8c1a23b3cf8c0f2193a310c18387c06e583ae9ef284de2"}, - {file = "ruff-0.7.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:3f36d56326b3aef8eeee150b700e519880d1aab92f471eefdef656fd57492aa2"}, - {file = "ruff-0.7.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5d024301109a0007b78d57ab0ba190087b43dce852e552734ebf0b0b85e4fb16"}, - {file = "ruff-0.7.3-py3-none-win32.whl", hash = "sha256:4ba81a5f0c5478aa61674c5a2194de8b02652f17addf8dfc40c8937e6e7d79fc"}, - {file = "ruff-0.7.3-py3-none-win_amd64.whl", hash = "sha256:588a9ff2fecf01025ed065fe28809cd5a53b43505f48b69a1ac7707b1b7e4088"}, - {file = "ruff-0.7.3-py3-none-win_arm64.whl", hash = "sha256:1713e2c5545863cdbfe2cbce21f69ffaf37b813bfd1fb3b90dc9a6f1963f5a8c"}, - {file = "ruff-0.7.3.tar.gz", hash = "sha256:e1d1ba2e40b6e71a61b063354d04be669ab0d39c352461f3d789cac68b54a313"}, + {file = "ruff-0.7.4-py3-none-linux_armv6l.whl", hash = "sha256:a4919925e7684a3f18e18243cd6bea7cfb8e968a6eaa8437971f681b7ec51478"}, + {file = "ruff-0.7.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:cfb365c135b830778dda8c04fb7d4280ed0b984e1aec27f574445231e20d6c63"}, + {file = "ruff-0.7.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:63a569b36bc66fbadec5beaa539dd81e0527cb258b94e29e0531ce41bacc1f20"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0d06218747d361d06fd2fdac734e7fa92df36df93035db3dc2ad7aa9852cb109"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e0cea28d0944f74ebc33e9f934238f15c758841f9f5edd180b5315c203293452"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:80094ecd4793c68b2571b128f91754d60f692d64bc0d7272ec9197fdd09bf9ea"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:997512325c6620d1c4c2b15db49ef59543ef9cd0f4aa8065ec2ae5103cedc7e7"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:00b4cf3a6b5fad6d1a66e7574d78956bbd09abfd6c8a997798f01f5da3d46a05"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7dbdc7d8274e1422722933d1edddfdc65b4336abf0b16dfcb9dedd6e6a517d06"}, + {file = "ruff-0.7.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0e92dfb5f00eaedb1501b2f906ccabfd67b2355bdf117fea9719fc99ac2145bc"}, + {file = "ruff-0.7.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3bd726099f277d735dc38900b6a8d6cf070f80828877941983a57bca1cd92172"}, + {file = "ruff-0.7.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:2e32829c429dd081ee5ba39aef436603e5b22335c3d3fff013cd585806a6486a"}, + {file = "ruff-0.7.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:662a63b4971807623f6f90c1fb664613f67cc182dc4d991471c23c541fee62dd"}, + {file = "ruff-0.7.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:876f5e09eaae3eb76814c1d3b68879891d6fde4824c015d48e7a7da4cf066a3a"}, + {file = "ruff-0.7.4-py3-none-win32.whl", hash = "sha256:75c53f54904be42dd52a548728a5b572344b50d9b2873d13a3f8c5e3b91f5cac"}, + {file = "ruff-0.7.4-py3-none-win_amd64.whl", hash = "sha256:745775c7b39f914238ed1f1b0bebed0b9155a17cd8bc0b08d3c87e4703b990d6"}, + {file = "ruff-0.7.4-py3-none-win_arm64.whl", hash = "sha256:11bff065102c3ae9d3ea4dc9ecdfe5a5171349cdd0787c1fc64761212fc9cf1f"}, + {file = "ruff-0.7.4.tar.gz", hash = "sha256:cd12e35031f5af6b9b93715d8c4f40360070b2041f81273d0527683d5708fce2"}, ] [[package]] @@ -783,13 +783,13 @@ Unidecode = ">=1.3.7,<2.0.0" [[package]] name = "tomli" -version = "2.0.2" +version = "2.1.0" description = "A lil' TOML parser" optional = false python-versions = ">=3.8" files = [ - {file = "tomli-2.0.2-py3-none-any.whl", hash = "sha256:2ebe24485c53d303f690b0ec092806a085f07af5a5aa1464f3931eec36caaa38"}, - {file = "tomli-2.0.2.tar.gz", hash = "sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed"}, + {file = "tomli-2.1.0-py3-none-any.whl", hash = "sha256:a5c57c3d1c56f5ccdf89f6523458f60ef716e210fc47c4cfb188c5ba473e0391"}, + {file = "tomli-2.1.0.tar.gz", hash = "sha256:3f646cae2aec94e17d04973e4249548320197cfabdf130015d023de4b74d8ab8"}, ] [[package]] diff --git a/tests/test_all_fields.py b/tests/test_all_fields.py index b279995..99faa89 100644 --- a/tests/test_all_fields.py +++ b/tests/test_all_fields.py @@ -173,7 +173,7 @@ def test_yesterday(self): assert meta.rg_track_gain is None assert meta.rg_track_peak is None assert meta.samplerate == 24000 - assert meta.ar_combined_soundtrack is False + assert meta.ar_combined_soundtrack is True assert meta.script == "Latn" assert meta.title == "Yesterday" assert meta.ar_classical_title == "Yesterday" diff --git a/tests/test_meta.py b/tests/test_meta.py index 170f41f..c696fb1 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -646,26 +646,19 @@ def test_unify_list(self) -> None: all_fields = [ - # acoustid_fingerprint: None - # acoustid_id : None - # album : the album - # albumartist : the album artist - # albumartist_credit : None - # albumartist_sort : None - # albumartists : [] - # albumdisambig : None - # albumstatus : None - # albumtype : None "acoustid_fingerprint", "acoustid_id", "album", "albumartist_credit", "albumartist_sort", "albumartist", + "albumartists_credit", + "albumartists_sort", "albumartists", "albumdisambig", "albumstatus", "albumtype", + "albumtypes", "ar_classical_album", "ar_classical_performer", "ar_classical_title", @@ -684,39 +677,22 @@ def test_unify_list(self) -> None: "ar_performer_raw", "ar_performer_short", "ar_performer", - # arranger : None - # art : None - # artist : the artist - # artist_credit : None - # artist_sort : None - # artists : [] - # asin : None "arranger", "art", "artist_credit", "artist_sort", "artist", + "artists_credit", + "artists_sort", "artists", "asin", - # barcode : None - # bitdepth : 0 - # bitrate : 80000 - # bitrate_mode : - # bpm : 6 "barcode", "bitdepth", "bitrate_mode", "bitrate", "bpm", - # catalognum : None - # channels : 1 - # comments : the comments - # comp : True - # composer : the composer - # composer_sort : None - # copyright : None - # country : None "catalognum", + "catalognums", "channels", "comments", "comp", @@ -724,58 +700,27 @@ def test_unify_list(self) -> None: "composer", "copyright", "country", - # date : 2001-01-01 - # day : None - # disc : 4 - # disctitle : None - # disctotal : 5 "date", "day", "disc", "disctitle", "disctotal", - # encoder : iTunes v7.6.2 - # encoder_info : - # encoder_settings : - "encoder", "encoder_info", "encoder_settings", - # format : MP3 + "encoder", "format", - # genre : the genre - # genres : ['the genre'] - # grouping : the grouping "genre", "genres", "grouping", - # images : [] - # initial_key : None - # isrc : None "images", "initial_key", "isrc", - # label : the label - # language : None - # length : 1.071 - # lyricist : None - # lyrics : the lyrics "label", "language", + "languages", "length", "lyricist", "lyrics", - # mb_albumartistid : None - # mb_albumartistids : [] - # mb_albumid : 9e873859-8aa4-4790-b985-5a953e8ef628 - # mb_artistid : 7cf0ea9d-86b9-4dad-ba9e-2355a64899ea - # mb_artistids : ['7cf0ea9d-86b9-4dad-ba9e-2355a64899ea'] - # mb_releasegroupid : None - # mb_releasetrackid : c29f3a57-b439-46fd-a2e2-93776b1371e0 - # mb_trackid : 8b882575-08a5-4452-a7a7-cbb8a1531f9e - # mb_workhierarchy_ids: None - # mb_workid : None - # media : None - # month : None "mb_albumartistid", "mb_albumartistids", "mb_albumid", @@ -788,21 +733,10 @@ def test_unify_list(self) -> None: "mb_workid", "media", "month", - # original_date : None - # original_day : None - # original_month : None - # original_year : None "original_date", "original_day", "original_month", "original_year", - # r128_album_gain : None - # r128_track_gain : None - # releasegroup_types : None - # rg_album_gain : None - # rg_album_peak : None - # rg_track_gain : 0.0 - # rg_track_peak : 0.000244 "r128_album_gain", "r128_track_gain", "releasegroup_types", @@ -810,23 +744,14 @@ def test_unify_list(self) -> None: "rg_album_peak", "rg_track_gain", "rg_track_peak", - # samplerate : 44100 - # script : None "samplerate", "script", - # title : full - # track : 2 - # tracktotal : 3 "title", "track", "tracktotal", - # url : None "url", - # work : None - # work_hierarchy : None "work_hierarchy", "work", - # year : 2001 "year", ]