Skip to content

Commit

Permalink
Feature: support title substitution (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Dec 26, 2023
1 parent 55b848b commit 9298ebe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
13 changes: 9 additions & 4 deletions MetaTube.bundle/Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,19 @@ def update(self, metadata, media, lang, force=False):
if Prefs[KEY_ENABLE_REAL_ACTOR_NAMES]:
self.convert_to_real_actor_names(m)

if Prefs[KEY_ENABLE_ACTOR_SUBSTITUTION] and Prefs[KEY_ACTOR_SUBSTITUTION]:
if Prefs[KEY_ENABLE_TITLE_SUBSTITUTION] and Prefs[KEY_TITLE_SUBSTITUTION_TABLE]:
for k, v in utils.parse_table(Prefs[KEY_TITLE_SUBSTITUTION_TABLE],
sep='\n', b64=True).items():
m.title = m.title.replace(k, v)

if Prefs[KEY_ENABLE_ACTOR_SUBSTITUTION] and Prefs[KEY_ACTOR_SUBSTITUTION_TABLE]:
m.actors = utils.table_substitute(
utils.parse_table(Prefs[KEY_ACTOR_SUBSTITUTION],
utils.parse_table(Prefs[KEY_ACTOR_SUBSTITUTION_TABLE],
sep='\n', b64=True), m.actors)

if Prefs[KEY_ENABLE_GENRE_SUBSTITUTION] and Prefs[KEY_GENRE_SUBSTITUTION]:
if Prefs[KEY_ENABLE_GENRE_SUBSTITUTION] and Prefs[KEY_GENRE_SUBSTITUTION_TABLE]:
m.genres = utils.table_substitute(
utils.parse_table(Prefs[KEY_GENRE_SUBSTITUTION],
utils.parse_table(Prefs[KEY_GENRE_SUBSTITUTION_TABLE],
sep='\n', b64=True), m.genres)

# Translate Info
Expand Down
6 changes: 4 additions & 2 deletions MetaTube.bundle/Contents/Code/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@
KEY_MOVIE_PROVIDER_FILTER = 'movie_provider_filter'
KEY_ENABLE_TITLE_TEMPLATE = 'enable_title_template'
KEY_TITLE_TEMPLATE = 'title_template'
KEY_ENABLE_TITLE_SUBSTITUTION = 'enable_title_substitution'
KEY_TITLE_SUBSTITUTION_TABLE = 'title_substitution_table'
KEY_ENABLE_ACTOR_SUBSTITUTION = 'enable_actor_substitution'
KEY_ACTOR_SUBSTITUTION = 'actor_substitution_table'
KEY_ACTOR_SUBSTITUTION_TABLE = 'actor_substitution_table'
KEY_ENABLE_GENRE_SUBSTITUTION = 'enable_genre_substitution'
KEY_GENRE_SUBSTITUTION = 'genre_substitution_table'
KEY_GENRE_SUBSTITUTION_TABLE = 'genre_substitution_table'
KEY_TRANSLATION_MODE = 'translation_mode'
KEY_TRANSLATION_ENGINE = 'translation_engine'
KEY_TRANSLATION_ENGINE_PARAMETERS = 'translation_engine_parameters'
Expand Down
12 changes: 12 additions & 0 deletions MetaTube.bundle/Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
"type": "text",
"default": "{number} {title}"
},
{
"id": "enable_title_substitution",
"label": "Enable title substitution",
"type": "bool",
"default": "false"
},
{
"id": "title_substitution_table",
"label": "Title substitution table (Base64 encoding required)",
"type": "text",
"default": ""
},
{
"id": "enable_actor_substitution",
"label": "Enable actor substitution",
Expand Down

0 comments on commit 9298ebe

Please sign in to comment.