From f6ac3db67b264ce37a5b3c9b7ff8b77a621c5fcb Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 27 Oct 2025 21:18:49 -0700 Subject: [PATCH] add to index.rest, fix links, reformat, lint --- beetsplug/titlecase.py | 62 +++++++++++++++++++--------------- docs/plugins/index.rst | 1 + docs/plugins/titlecase.rst | 4 +-- test/plugins/test_titlecase.py | 22 ++++++------ 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/beetsplug/titlecase.py b/beetsplug/titlecase.py index 7115ad919..eb54e0bd6 100644 --- a/beetsplug/titlecase.py +++ b/beetsplug/titlecase.py @@ -17,7 +17,7 @@ Title case logic is derived from the python-titlecase library. Provides a template function and a tag modification function.""" import re -from typing import Pattern, Optional +from typing import Optional, Pattern from titlecase import titlecase @@ -33,34 +33,34 @@ __version__ = "1.0" # that may be case sensistive, or important to database # function EXCLUDED_INFO_FIELDS: set[str] = { - "acoustid_fingerprint", - "acoustid_id", - "artists_ids", - "asin", - "deezer_track_id", - "format", - "id", - "isrc", - "mb_workid", - "mb_trackid", - "mb_albumid", - "mb_artistid", - "mb_artistids", - "mb_albumartistid", - "mb_albumartistids", - "mb_releasetrackid", - "mb_releasegroupid", - "bitrate_mode", - "encoder_info", - "encoder_settings", - } + "acoustid_fingerprint", + "acoustid_id", + "artists_ids", + "asin", + "deezer_track_id", + "format", + "id", + "isrc", + "mb_workid", + "mb_trackid", + "mb_albumid", + "mb_artistid", + "mb_artistids", + "mb_albumartistid", + "mb_albumartistids", + "mb_releasetrackid", + "mb_releasegroupid", + "bitrate_mode", + "encoder_info", + "encoder_settings", +} class TitlecasePlugin(BeetsPlugin): preserve: dict[str, str] = {} preserve_phrases: dict[str, Pattern[str]] = {} force_lowercase: bool = True - fields_to_process: set[str] = {} + fields_to_process: set[str] def __init__(self) -> None: super().__init__() @@ -150,10 +150,18 @@ class TitlecasePlugin(BeetsPlugin): for field in self.fields_to_process: init_field = getattr(item, field, "") if init_field: - if isinstance(init_field, list) and isinstance(init_field[0], str): - cased_list: list[str] = [self.titlecase(i) for i in init_field] - self._log.info((f"{field}: {', '.join(init_field)} -> " - f"{', '.join(cased_list)}")) + if isinstance(init_field, list) and isinstance( + init_field[0], str + ): + cased_list: list[str] = [ + self.titlecase(i) for i in init_field + ] + self._log.info( + ( + f"{field}: {', '.join(init_field)} -> " + f"{', '.join(cased_list)}" + ) + ) setattr(item, field, cased_list) elif isinstance(init_field, str): cased: str = self.titlecase(init_field) diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 2c9d94dfd..6cebb4250 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -126,6 +126,7 @@ databases. They share the following configuration options: substitute the thumbnails + titlecase types unimported web diff --git a/docs/plugins/titlecase.rst b/docs/plugins/titlecase.rst index 61dbdeae7..0bbf4528f 100644 --- a/docs/plugins/titlecase.rst +++ b/docs/plugins/titlecase.rst @@ -8,12 +8,12 @@ titlecase guidelines in the `New York Times Manual of Style`_ and uses the Motivation for this plugin comes from a desire to resolve differences in style between databases sources. For example, `MusicBrainz style`_ follows standard title case rules, except in the case of terms that are deemed generic, like -"mix" and "remix". On the other hand, `Discogs guidlines`_ recommend +"mix" and "remix". On the other hand, `Discogs guidelines`_ recommend capitalizing the first letter of each word, even for small words like "of" and "a". This plugin aims to achieve a middle ground between disparate approaches to casing, and bring more consistency to titles in your library. -.. _discogs style: https://support.discogs.com/hc/en-us/articles/360005006334-Database-Guidelines-1-General-Rules#Capitalization_And_Grammar +.. _discogs guidelines: https://support.discogs.com/hc/en-us/articles/360005006334-Database-Guidelines-1-General-Rules#Capitalization_And_Grammar .. _musicbrainz style: https://musicbrainz.org/doc/Style diff --git a/test/plugins/test_titlecase.py b/test/plugins/test_titlecase.py index 3b2fc9a1d..ef8f72cb2 100644 --- a/test/plugins/test_titlecase.py +++ b/test/plugins/test_titlecase.py @@ -70,10 +70,14 @@ titlecase_test_cases = [ { "config": { "preserve": [""], - "fields": ["artist", "albumartist", + "fields": [ + "artist", + "albumartist", "title", "album", - "mb_albumd", "year"], + "mb_albumd", + "year", + ], "force_lowercase": True, "small_first_last": True, }, @@ -97,25 +101,21 @@ titlecase_test_cases = [ { "config": { "preserve": [""], - "fields": [ - "artists", - "artists_ids", - "discogs_artistid" - ], + "fields": ["artists", "artists_ids", "discogs_artistid"], "force_lowercase": False, "small_first_last": True, }, "item": Item( artists=["artist_one", "artist_two"], artists_ids=["aBcDeF32", "aBcDeF12"], - discogs_artistid=21 + discogs_artistid=21, ), "expected": Item( artists=["Artist_One", "Artist_Two"], artists_ids=["aBcDeF32", "aBcDeF12"], - discogs_artistid=21 + discogs_artistid=21, ), - } + }, ] @@ -195,4 +195,4 @@ class TitlecasePluginTest(PluginTestCase): output == f"{expected.artist} - {expected.album} - {expected.title}\n" ) - self.run_command(f"remove", expected.artist, "-f") + self.run_command("remove", expected.artist, "-f")