mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 13:07:09 +01:00
add to index.rest, fix links, reformat, lint
This commit is contained in:
parent
2bb072fde1
commit
f6ac3db67b
4 changed files with 49 additions and 40 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ databases. They share the following configuration options:
|
|||
substitute
|
||||
the
|
||||
thumbnails
|
||||
titlecase
|
||||
types
|
||||
unimported
|
||||
web
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue