Skip to content

Commit

Permalink
feat: Add a simplify_title option to the preferences (#56)
Browse files Browse the repository at this point in the history
* feat: Add a `simplify_title` option to the preferences

Co-authored-by: David Dembeck <71412966+djdembeck@users.noreply.github.com>
  • Loading branch information
csandman and djdembeck committed Jul 26, 2022
1 parent 1f488a8 commit 2b2a82a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,12 @@ def compile_metadata(self, helper):
tagger.add_authors_to_moods()
# Series.
tagger.add_series_to_moods()
# Setup title + subtitle where available.
if helper.subtitle:

# If the `simplify_title` option is selected, don't append subtitle
# and remove extra endings on the title
if Prefs['simplify_title']:
album_title = helper.simplify_title()
elif helper.subtitle:
album_title = helper.title + ': ' + helper.subtitle
else:
album_title = helper.title
Expand Down
15 changes: 15 additions & 0 deletions Contents/Code/update_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ def writeInfo(self):

log.separator(log_level="info")

# Remove extra description text from the title
def simplify_title(self):
# If the title ends with a series part, remove it
# works for "Book 1" and "Book One"
album_title = re.sub(
r", book [\w\s-]+\s*$", "", self.title, flags=re.IGNORECASE)
# If the title ends with "unabridged"/"abridged", with or without parenthesis
# remove them; case insensitive
album_title = re.sub(r" *\(?(un)?abridged\)?$", "",
album_title, flags=re.IGNORECASE)
# Trim any leading/trailing spaces just in case
album_title = album_title.strip()

return album_title


class ArtistUpdateTool:
UPDATE_URL = 'https://api.audnex.us/authors/'
Expand Down
7 changes: 6 additions & 1 deletion Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"label": "Sort artist by name [Last, First]",
"type": "bool",
"default": "true"
},{
"id": "simplify_title",
"label": "Simplify book titles (remove subtitle, series part, (un)abridged, etc.)",
"type": "bool",
"default": "false"
},{
"id": "logging_level",
"label": "Level of plugin logging: ",
Expand All @@ -24,4 +29,4 @@
"ERROR"
],
"default": "WARN"
}]
}]

0 comments on commit 2b2a82a

Please sign in to comment.