From 3af4af8f5a1e1d53bed22bcae22f9b0fbb5c36a2 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 26 Mar 2024 12:15:46 -0400 Subject: [PATCH] [44] update advance preferences --- CHANGELOG | 1 + VERSION | 2 +- docs/files/item_updates.md | 8 ++++++-- docs/files/metadata.md | 15 ++++++++------- modules/meta.py | 23 +++++++++++++++++++++++ modules/plex.py | 28 ++++++++++++++++++++-------- modules/util.py | 5 +++-- 7 files changed, 62 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d6f3b212..5018bae0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ Mass Update operations now can be given a list of sources to fall back on when o `plex` attributes `clean_bundles`, `empty_trash`, and `optimize` can now take any schedule options to be run only when desired. Allows users to use the Admin username when specifying playlist users. Thanks @benbou8231! Allows `verify_ssl` to be set specifically for plex. Thanks @FestiveKyle! +Updated Plex Item Advance Preferences # Defaults diff --git a/VERSION b/VERSION index c9d95cec..613185e6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.20.0-develop43 +1.20.0-develop44 diff --git a/docs/files/item_updates.md b/docs/files/item_updates.md index cfd2b942..5c3c12eb 100644 --- a/docs/files/item_updates.md +++ b/docs/files/item_updates.md @@ -27,12 +27,16 @@ All the following attributes update various details of the metadata for every it | `item_tmdb_season_titles` | **Description:** Changes the season titles of every show in the collection to match TMDb
**Default:** `false`
**Values:** `true` or `false` | | `item_episode_sorting`1 | **Description:** Changes the episode sorting of every show in the collection
**Values:**
`default`Library default
`oldest`Oldest first
`newest`Newest first
| | `item_keep_episodes`1 | **Description:** Changes the keep episodes of every show in the collection
**Values:**
`all`All episodes
`5_latest`5 latest episodes
`3_latest`3 latest episodes
`latest`Latest episodes
`past_3`Episodes added in the past 3 days
`past_7`Episodes added in the past 7 days
`past_30`Episodes added in the past 30 days
| -| `item_delete_episodes`1 | **Description:** Changes the delete episodes of every show in the collection
**Values:**
`never`Never
`day`After a day
`week`After a week
`refresh`On next refresh
| +| `item_delete_episodes`1 | **Description:** Changes the delete episodes of every show in the collection
**Values:**
`never`Never
`day`After a day
`week`After a week
`month`After a month
`refresh`On next refresh
| | `item_season_display`1 | **Description:** Changes the season display of every show in the collection
**Values:**
`default`Library default
`show`Show
`hide`Hide
| | `item_episode_ordering`1 | **Description:** Changes the episode ordering of every show in the collection
**Values:**
`default`Library default
`tmdb_aired`The Movie Database (Aired)
`tvdb_aired`TheTVDb (Aired)
`tvdb_dvd`TheTVDb (DVD)
`tvdb_absolute`TheTVDb (Absolute)
| | `item_metadata_language`2 | **Description:** Changes the metadata language of every movie/show in the collection
**Values:** `default`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | | `item_use_original_title`2 | **Description:** Changes the use original title of every movie/show in the collection
**Values:**
`default`Library default
`no`No
`yes`Yes
| +| `item_credits_detection`2 | **Description:** Changes the enable credits detection of every movie/show in the collection
**Values:**
`default`Library default
`disabled`Disabled
| +| `item_audio_language`2 | **Description:** Changes the preferred audio language of every movie/show in the collection
**Values:** `default`, `en`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | +| `item_subtitle_language`2 | **Description:** Changes the preferred subtitle language of every movie/show in the collection
**Values:** `default`, `en`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | +| `item_subtitle_mode`2 | **Description:** Changes the auto-select subtitle mode of every movie/show in the collection
**Values:**
`default`Account default
`manual`Manually selected
`foreign`Shown with foreign audio
`always`Always enabled
| 1 Only works with TV Show Libraries -2 Must be using the **New Plex Movie Agent** or the **New Plex TV Agent** +2 Must be using the **New Plex Movie Agent** or the **New Plex TV Agent** diff --git a/docs/files/metadata.md b/docs/files/metadata.md index 5efb8a9a..763d3b0e 100644 --- a/docs/files/metadata.md +++ b/docs/files/metadata.md @@ -465,16 +465,17 @@ You can add `.sync` to any tag attribute to sync all tags vs just appending the |
Attribute
| Allowed Values |
Item Types
| |:-----------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------| -| `metadata_language`1 | `default`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | `Movies` | -| `use_original_title`1 | `default`: Library default
`no`: No
`yes`: Yes | `Movies` | | `episode_sorting` |
`default`Library default
`oldest`Oldest first
`newest`Newest first
| `Shows` | | `keep_episodes` |
`all`All episodes
`5_latest`5 latest episodes
`3_latest`3 latest episodes
`latest`Latest episodes
`past_3`Episodes added in the past 3 days
`past_7`Episodes added in the past 7 days
`past_30`Episodes added in the past 30 days
| `Shows` | | `delete_episodes` |
`never`Never
`day`After a day
`week`After a week
`refresh`On next refresh
| `Shows` | | `season_display` |
`default`Library default
`show`Show
`hide`Hide
| `Shows` | | `episode_ordering` |
`default`Library default
`tmdb_aired`The Movie Database (Aired)
`tvdb_aired`TheTVDb (Aired)
`tvdb_dvd`TheTVDb (DVD)
`tvdb_absolute`TheTVDb (Absolute)
| `Shows` | -| `metadata_language`2 | `default`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | `Shows` | -| `use_original_title`2 |
`default`Library default
`no`No
`yes`Yes
| `Shows` | -| `album_sorting` |
`default`Library default
`oldest`Oldest first
`newest`Newest first
`name`Alphabetical
| `Artists` | +| `metadata_language`1 | `default`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | `Movies`, `Shows` | +| `use_original_title`1 |
`default`Library default
`no`No
`yes`Yes
| `Movies`, `Shows` | +| `credits_detection`1 |
`default`Library default
`disabled`Disabled
| `Movies`, `Shows` | +| `audio_language`1 | `default`, `en`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | `Shows`, `Seasons` | +| `subtitle_language`1 | `default`, `en`, `ar-SA`, `ca-ES`, `cs-CZ`, `da-DK`, `de-DE`, `el-GR`, `en-AU`, `en-CA`, `en-GB`, `en-US`, `es-ES`, `es-MX`, `et-EE`, `fa-IR`, `fi-FI`, `fr-CA`, `fr-FR`, `he-IL`, `hi-IN`, `hu-HU`, `id-ID`, `it-IT`, `ja-JP`, `ko-KR`, `lt-LT`, `lv-LV`, `nb-NO`, `nl-NL`, `pl-PL`, `pt-BR`, `pt-PT`, `ro-RO`, `ru-RU`, `sk-SK`, `sv-SE`, `th-TH`, `tr-TR`, `uk-UA`, `vi-VN`, `zh-CN`, `zh-HK`, `zh-TW` | `Shows`, `Seasons` | +| `subtitle_mode`1 |
`default`Account default
`no`No
`yes`Yes
| `Shows`, `Seasons` | +| `album_sorting` |
`default`Library default
`manual`Manually selected
`foreign`Shown with foreign audio
`always`Always enabled
| `Artists` | -1. Must be using the **New Plex Movie Agent**. -2. Must be using the **New Plex TV Agent** +1. Must be using the **New Plex Movie Agent** or the **New Plex TV Agent** diff --git a/modules/meta.py b/modules/meta.py index 17b247b7..d991cdb4 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -1924,6 +1924,29 @@ class MetadataFile(DataFile): title=f"{item.title} Season {season.seasonNumber}", image_name=f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}", folder_name=folder_name, style_data=season_style_data) + + advance_edits = {} + prefs = None + for advance_edit in util.advance_tags_to_edit["Season"]: + if advance_edit in season_methods: + if season_dict[season_methods[advance_edit]]: + ad_key, options = plex.item_advance_keys[f"item_{advance_edit}"] + method_data = str(season_dict[season_methods[advance_edit]]).lower() + if prefs is None: + prefs = [p.id for p in season.preferences()] + if method_data not in options: + logger.error(f"{self.type_str} Error: {meta[methods[advance_edit]]} {advance_edit} attribute invalid") + elif ad_key in prefs and getattr(season, ad_key) != options[method_data]: + advance_edits[ad_key] = options[method_data] + logger.info(f"Metadata: {advance_edit} updated to {method_data}") + else: + logger.error(f"{self.type_str} Error: {advance_edit} attribute is blank") + if advance_edits: + if self.library.edit_advance(season, advance_edits): + updated = True + logger.info("Advanced Metadata Update Successful") + else: + logger.error("Advanced Metadata Update Failed") if ups: updated = True logger.info(f"Season {season_id} of {mapping_name} Metadata Update {'Complete' if updated else 'Not Needed'}") diff --git a/modules/plex.py b/modules/plex.py index 1e341155..a8cf9fa8 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -209,7 +209,7 @@ date_sub_mods = {"s": "Seconds", "m": "Minutes", "h": "Hours", "d": "Days", "w": album_sorting_options = {"default": -1, "newest": 0, "oldest": 1, "name": 2} episode_sorting_options = {"default": -1, "oldest": 0, "newest": 1} keep_episodes_options = {"all": 0, "5_latest": 5, "3_latest": 3, "latest": 1, "past_3": -3, "past_7": -7, "past_30": -30} -delete_episodes_options = {"never": 0, "day": 1, "week": 7, "refresh": 100} +delete_episodes_options = {"never": 0, "day": 1, "week": 7, "month": 30, "refresh": 100} season_display_options = {"default": -1, "show": 0, "hide": 1} episode_ordering_options = {"default": None, "tmdb_aired": "tmdbAiring", "tvdb_aired": "aired", "tvdb_dvd": "dvd", "tvdb_absolute": "absolute"} plex_languages = ["default", "ar-SA", "ca-ES", "cs-CZ", "da-DK", "de-DE", "el-GR", "en-AU", "en-CA", "en-GB", "en-US", @@ -219,6 +219,12 @@ plex_languages = ["default", "ar-SA", "ca-ES", "cs-CZ", "da-DK", "de-DE", "el-GR metadata_language_options = {lang.lower(): lang for lang in plex_languages} metadata_language_options["default"] = None use_original_title_options = {"default": -1, "no": 0, "yes": 1} +credits_detection_options = {"default": -1, "disabled": 0} +audio_language_options = {lang.lower(): lang for lang in plex_languages} +audio_language_options["en"] = "en" +subtitle_language_options = {lang.lower(): lang for lang in plex_languages} +subtitle_language_options["en"] = "en" +subtitle_mode_options = {"default": -1, "manual": 0, "foreign": 1, "always": 2} collection_order_options = ["release", "alpha", "custom"] collection_filtering_options = ["user", "admin"] collection_mode_options = { @@ -239,7 +245,11 @@ item_advance_keys = { "item_season_display": ("flattenSeasons", season_display_options), "item_episode_ordering": ("showOrdering", episode_ordering_options), "item_metadata_language": ("languageOverride", metadata_language_options), - "item_use_original_title": ("useOriginalTitle", use_original_title_options) + "item_use_original_title": ("useOriginalTitle", use_original_title_options), + "item_credits_detection": ("enableCreditsMarkerGeneration", credits_detection_options), + "item_audio_language": ("audioLanguage", audio_language_options), + "item_subtitle_language": ("subtitleLanguage", subtitle_language_options), + "item_subtitle_mode": ("subtitleMode", subtitle_mode_options) } new_plex_agents = ["tv.plex.agents.movie", "tv.plex.agents.series"] and_searches = [ @@ -1514,7 +1524,9 @@ class Plex(Library): imdb_id = self.get_imdb_from_map(item) return tmdb_id, tvdb_id, imdb_id - def get_locked_attributes(self, item, titles=None, year_titles=None): + def get_locked_attributes(self, item, titles=None, year_titles=None, item_type=None): + if not item_type: + item_type = self.type item = self.reload(item) attrs = {} match_dict = {} @@ -1590,8 +1602,8 @@ class Plex(Library): check_field("mood", "mood", var_key="moods") check_field("style", "style", var_key="styles") check_field("similar", "similar_artist") - if self.type in util.advance_tags_to_edit: - for advance_edit in util.advance_tags_to_edit[self.type]: + if item_type in util.advance_tags_to_edit: + for advance_edit in util.advance_tags_to_edit[item_type]: key, options = item_advance_keys[f"item_{advance_edit}"] if advance_edit in self.metadata_backup["exclude"] or not hasattr(item, key): continue @@ -1599,10 +1611,10 @@ class Plex(Library): if keys[getattr(item, key)] not in ["default", "all", "never"]: attrs[advance_edit] = keys[getattr(item, key)] - def _recur(sub): + def _recur(sub, item_type_in=None): sub_items = {} for sub_item in getattr(item, sub)(): - sub_item_key, sub_item_attrs = self.get_locked_attributes(sub_item) + sub_item_key, sub_item_attrs = self.get_locked_attributes(sub_item, item_type=item_type_in) if sub_item_attrs: sub_items[sub_item_key] = sub_item_attrs if sub_items: @@ -1611,7 +1623,7 @@ class Plex(Library): if isinstance(item, Show): _recur("seasons") elif isinstance(item, Season): - _recur("episodes") + _recur("episodes", item_type_in="Season") elif isinstance(item, Artist): _recur("albums") elif isinstance(item, Album): diff --git a/modules/util.py b/modules/util.py index f0deff2c..a318b6e1 100644 --- a/modules/util.py +++ b/modules/util.py @@ -84,8 +84,9 @@ pretty_months = { lower_months = {v.lower(): k for k, v in pretty_months.items()} seasons = ["current", "winter", "spring", "summer", "fall"] advance_tags_to_edit = { - "Movie": ["metadata_language", "use_original_title"], - "Show": ["episode_sorting", "keep_episodes", "delete_episodes", "season_display", "episode_ordering", "metadata_language", "use_original_title"], + "Movie": ["metadata_language", "use_original_title", "credits_detection"], + "Show": ["episode_sorting", "keep_episodes", "delete_episodes", "season_display", "episode_ordering", "metadata_language", "use_original_title", "credits_detection", "audio_language", "subtitle_language", "subtitle_mode"], + "Season": ["audio_language", "subtitle_language", "subtitle_mode"], "Artist": ["album_sorting"] } tags_to_edit = {