Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion picard/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,29 @@ def _customize_metadata(self):

@staticmethod
def _genres_to_metadata(genres, limit=None, minusage=0, filters='', join_with=None):
def titlize(text):
"""Converts text to title case using custom rules.

Capitalizes the first character of each word while converting remaining
characters to lowercase. Handles contractions properly by keeping the
apostrophe intact.

Args:
text (str): The input string to be converted to title case.

Returns:
str: The input text converted to title case format.

Examples:
>>> titlize("children's music")
'Children's Music'
>>> titlize("blues")
"Blues"
"""
return re.sub(r"[A-Za-z]+('[A-Za-z]+)?",
lambda m: m.group(0)[0].upper() + m.group(0)[1:].lower(),
text)

if limit is not None and limit < 1:
return []

Expand All @@ -335,7 +358,7 @@ def _genres_to_metadata(genres, limit=None, minusage=0, filters='', join_with=No

# Find most common genres
most_common_genres = genres.most_common(limit)
genres_list = [name.title() for name, _count in most_common_genres]
genres_list = [titlize(name) for name, _count in most_common_genres]
genres_list.sort()

# And generate the genre metadata tag
Expand Down
Loading