[85] add run_definition, update_seasons, and update_episodes to metadata definitions

pull/1324/head
meisnate12 2 years ago
parent 064a85f2ce
commit 2a185a6962

@ -1 +1 @@
1.18.3-develop84 1.18.3-develop85

@ -30,7 +30,7 @@ All the following attributes serve various functions as how the definition funct
| `changes_webhooks` | **Description:** Used to specify a definition changes webhook for just this definition.<br>**Values:** List of webhooks | | `changes_webhooks` | **Description:** Used to specify a definition changes webhook for just this definition.<br>**Values:** List of webhooks |
| `sync_to_trakt_list` | **Description:** Used to specify a trakt list you want the definition synced to.<br>**Values:** Trakt List Slug you want to sync to | | `sync_to_trakt_list` | **Description:** Used to specify a trakt list you want the definition synced to.<br>**Values:** Trakt List Slug you want to sync to |
| `sync_missing_to_trakt_list` | **Description:** Used to also sync missing items to the Trakt List specified by `sync_to_trakt_list`.<br>**Default:** `false`<br>**Values:** `true` or `false` | | `sync_missing_to_trakt_list` | **Description:** Used to also sync missing items to the Trakt List specified by `sync_to_trakt_list`.<br>**Default:** `false`<br>**Values:** `true` or `false` |
| `run_definition` | **Description:** Used to specify if you want this definition to run.<br>Multiple can be used for one definition as a list or comma separated string. One `false` or unmatched library type will cause it to fail.<br>**Values:** `movie`, `show`, `artist`, `true`, `false` | | `run_definition` | **Description:** Used to specify if this definition runs.<br>Multiple can be used for one definition as a list or comma separated string. One `false` or unmatched library type will cause it to fail.<br>**Values:** `movie`, `show`, `artist`, `true`, `false` |
| `default_percent` | **Description:** Used to declare the default percent for `episodes`, `seasons`, `tracks`, and `albums` [special filters](../filters.md#special-filters). Default is 50.<br>**Values:** Integer between 1 and 100 | | `default_percent` | **Description:** Used to declare the default percent for `episodes`, `seasons`, `tracks`, and `albums` [special filters](../filters.md#special-filters). Default is 50.<br>**Values:** Integer between 1 and 100 |
| `ignore_blank_results` | **Description:** Used to not have Errors resulting from blank results from builders.<br>**Default:** `false`<br>**Values:** `true` or `false` | | `ignore_blank_results` | **Description:** Used to not have Errors resulting from blank results from builders.<br>**Default:** `false`<br>**Values:** `true` or `false` |
| `only_run_on_create` | **Description:** Used to only run the collection definition if the collection doesn't already exist.<br>**Default:** `false`<br>**Values:** `true` or `false` | | `only_run_on_create` | **Description:** Used to only run the collection definition if the collection doesn't already exist.<br>**Default:** `false`<br>**Values:** `true` or `false` |

@ -96,18 +96,21 @@ The available attributes for editing shows, seasons, and episodes are as follows
### Special Attributes ### Special Attributes
| Attribute | Values | Shows | Seasons | Episodes | | Attribute | Values | Shows | Seasons | Episodes |
|:---------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------:|:--------:|:--------:| |:------------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------:|:--------:|:--------:|
| `title` | Title if different from the mapping value useful when you have multiple shows with the same name. See the [Metadata Page](../metadata.md#metadata-attributes) for how searching for files works. | &#9989; | &#9989; | &#9989; | | `title` | Title if different from the mapping value useful when you have multiple shows with the same name. See the [Metadata Page](../metadata.md#metadata-attributes) for how searching for files works. | &#9989; | &#9989; | &#9989; |
| `alt_title` | Alternative title to look for and then change to the mapping name. See the [Metadata Page](../metadata.md#metadata-attributes) for how searching for files works. | &#9989; | &#10060; | &#10060; | | `alt_title` | Alternative title to look for and then change to the mapping name. See the [Metadata Page](../metadata.md#metadata-attributes) for how searching for files works. | &#9989; | &#10060; | &#10060; |
| `year` | Year of show for better identification. See the [Metadata Page](../metadata.md#metadata-attributes) for how searching for files works. | &#9989; | &#10060; | &#10060; | | `year` | Year of show for better identification. See the [Metadata Page](../metadata.md#metadata-attributes) for how searching for files works. | &#9989; | &#10060; | &#10060; |
| `tmdb_show` | TMDb Show ID to use for metadata useful for miniseries that have been compiled into a movie | &#9989; | &#10060; | &#10060; | | `tmdb_show` | TMDb Show ID to use for metadata useful for miniseries that have been compiled into a movie | &#9989; | &#10060; | &#10060; |
| `tmdb_movie` | TMDb Movie ID to use for metadata useful for movies that have been split into segments | &#9989; | &#10060; | &#10060; | | `tmdb_movie` | TMDb Movie ID to use for metadata useful for movies that have been split into segments | &#9989; | &#10060; | &#10060; |
| `f1_season` | F1 Season Year to make the Show represent a Season of F1 Races. See [Formula 1 Metadata Guide](../../home/guides/formula) for more information. | &#9989; | &#10060; | &#10060; | | `f1_season` | F1 Season Year to make the Show represent a Season of F1 Races. See [Formula 1 Metadata Guide](../../home/guides/formula) for more information. | &#9989; | &#10060; | &#10060; |
| `round_prefix` | Used only with `f1_season` to add the round as a prefix to the Season (Race) Titles i.e. `Australian Grand Prix` --> `01 - Australian Grand Prix` | &#9989; | &#10060; | &#10060; | | `round_prefix` | Used only with `f1_season` to add the round as a prefix to the Season (Race) Titles i.e. `Australian Grand Prix` --> `01 - Australian Grand Prix` | &#9989; | &#10060; | &#10060; |
| `shorten_gp` | Used only with `f1_season` to shorten `Grand Prix` to `GP` in the Season (Race) Titles i.e. `Australian Grand Prix` --> `Australian GP` | &#9989; | &#10060; | &#10060; | | `shorten_gp` | Used only with `f1_season` to shorten `Grand Prix` to `GP` in the Season (Race) Titles i.e. `Australian Grand Prix` --> `Australian GP` | &#9989; | &#10060; | &#10060; |
| `seasons` | Mapping to define Seasons | &#9989; | &#10060; | &#10060; | | `seasons` | Mapping to define Seasons | &#9989; | &#10060; | &#10060; |
| `episodes` | Mapping to define Episodes | &#10060; | &#9989; | &#10060; | | `episodes` | Mapping to define Episodes | &#10060; | &#9989; | &#10060; |
| `run_definition` | Used to specify if this definition runs.<br>Multiple can be used for one definition as a list or comma separated string. One `false` or unmatched library type will cause it to fail.<br>**Values:** `movie`, `show`, `artist`, `true`, `false` | &#9989; | &#10060; | &#10060; |
| `update_seasons` | Used to specify if this definition's seasons metadata will update.<br>Multiple can be used for one definition as a list or comma separated string. One `false` will cause it to fail.<br>**Values:** `true`, `false` | &#9989; | &#10060; | &#10060; |
| `update_episodes` | Used to specify if this definition's episodes metadata will update.<br>Multiple can be used for one definition as a list or comma separated string. One `false` will cause it to fail.<br>**Values:** `true`, `false` | &#9989; | &#10060; | &#10060; |
### General Attributes ### General Attributes

@ -1099,117 +1099,142 @@ class MetadataFile(DataFile):
logger.info("") logger.info("")
next_year = datetime.now().year + 1 next_year = datetime.now().year + 1
for mapping_name, meta in self.metadata.items(): for mapping_name, meta in self.metadata.items():
methods = {mm.lower(): mm for mm in meta} try:
methods = {mm.lower(): mm for mm in meta}
logger.info("")
item = None
if (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music:
if isinstance(mapping_name, int):
id_type = "TMDb" if self.library.is_movie else "TVDb"
else:
id_type = "IMDb"
logger.separator(f"{id_type} ID: {mapping_name} Metadata", space=False, border=False)
logger.info("") logger.info("")
item = [] item = None
if self.library.is_movie and mapping_name in self.library.movie_map: if (isinstance(mapping_name, int) or mapping_name.startswith("tt")) and not self.library.is_music:
for item_id in self.library.movie_map[mapping_name]: if isinstance(mapping_name, int):
item.append(self.library.fetchItem(item_id)) id_type = "TMDb" if self.library.is_movie else "TVDb"
elif self.library.is_show and mapping_name in self.library.show_map: else:
for item_id in self.library.show_map[mapping_name]: id_type = "IMDb"
item.append(self.library.fetchItem(item_id)) logger.separator(f"{id_type} ID: {mapping_name} Metadata", space=False, border=False)
elif mapping_name in self.library.imdb_map: logger.info("")
for item_id in self.library.imdb_map[mapping_name]: item = []
item.append(self.library.fetchItem(item_id)) if self.library.is_movie and mapping_name in self.library.movie_map:
for item_id in self.library.movie_map[mapping_name]:
item.append(self.library.fetchItem(item_id))
elif self.library.is_show and mapping_name in self.library.show_map:
for item_id in self.library.show_map[mapping_name]:
item.append(self.library.fetchItem(item_id))
elif mapping_name in self.library.imdb_map:
for item_id in self.library.imdb_map[mapping_name]:
item.append(self.library.fetchItem(item_id))
else:
logger.error(f"Metadata Error: {id_type} ID not mapped")
continue
title = None
else: else:
logger.error(f"Metadata Error: {id_type} ID not mapped") logger.separator(f"{mapping_name} Metadata", space=False, border=False)
continue logger.info("")
title = None title = mapping_name
else:
logger.separator(f"{mapping_name} Metadata", space=False, border=False) if "template" in methods:
logger.info("") logger.separator(f"Building Definition From Templates", space=False, border=False)
title = mapping_name
if "template" in methods:
logger.separator(f"Building Definition From Templates", space=False, border=False)
logger.debug("")
named_templates = []
for original_variables in util.get_list(meta[methods["template"]], split=False):
if not isinstance(original_variables, dict):
raise Failed(f"Metadata Error: template attribute is not a dictionary")
elif "name" not in original_variables:
raise Failed(f"Metadata Error: template sub-attribute name is required")
elif not original_variables["name"]:
raise Failed(f"Metadata Error: template sub-attribute name cannot be blank")
named_templates.append(original_variables["name"])
logger.debug(f"Templates Called: {', '.join(named_templates)}")
logger.debug("")
new_variables = {}
if "variables" in methods:
logger.debug("") logger.debug("")
logger.debug("Validating Method: variables") named_templates = []
if not isinstance(meta[methods["variables"]], dict): for original_variables in util.get_list(meta[methods["template"]], split=False):
raise Failed(f"Metadata Error: variables must be a dictionary (key: value pairs)") if not isinstance(original_variables, dict):
logger.trace(meta[methods["variables"]]) raise Failed(f"Metadata Error: template attribute is not a dictionary")
new_variables = meta[methods["variables"]] elif "name" not in original_variables:
name = meta[methods["name"]] if "name" in methods else None raise Failed(f"Metadata Error: template sub-attribute name is required")
new_attributes = self.apply_template(name, mapping_name, meta, meta[methods["template"]], new_variables) elif not original_variables["name"]:
for attr in new_attributes: raise Failed(f"Metadata Error: template sub-attribute name cannot be blank")
if attr.lower() not in methods: named_templates.append(original_variables["name"])
meta[attr] = new_attributes[attr] logger.debug(f"Templates Called: {', '.join(named_templates)}")
methods[attr.lower()] = attr logger.debug("")
new_variables = {}
if "title" in methods: if "variables" in methods:
if meta[methods["title"]] is None: logger.debug("")
logger.error("Metadata Error: title attribute is blank") logger.debug("Validating Method: variables")
else: if not isinstance(meta[methods["variables"]], dict):
title = meta[methods["title"]] raise Failed(f"Metadata Error: variables must be a dictionary (key: value pairs)")
logger.trace(meta[methods["variables"]])
edition_titles = None new_variables = meta[methods["variables"]]
if "edition_filter" in methods and self.library.is_movie: name = meta[methods["name"]] if "name" in methods else None
edition_titles = util.get_list(meta[methods["edition_filter"]]) new_attributes = self.apply_template(name, mapping_name, meta, meta[methods["template"]], new_variables)
if not edition_titles: for attr in new_attributes:
edition_titles = [""] if attr.lower() not in methods:
meta[attr] = new_attributes[attr]
edition_contains = None methods[attr.lower()] = attr
if "edition_contains" in methods and self.library.is_movie:
edition_contains = util.get_list(meta[methods["edition_contains"]]) if "run_definition" in methods:
if not edition_contains: logger.debug("")
edition_contains = [] logger.debug("Validating Method: run_definition")
if meta[methods["run_definition"]] is None:
if not item: raise NotScheduled("Skipped because run_definition has no value")
year = None logger.debug(f"Value: {meta[methods['run_definition']]}")
if "year" in methods and not self.library.is_music: valid_options = ["true", "false"] + plex.library_types
if meta[methods["year"]] is None: for library_type in util.get_list(meta[methods["run_definition"]], lower=True):
raise Failed("Metadata Error: year attribute is blank") if library_type not in valid_options:
try: raise Failed(f"Metadata Error: {library_type} is invalid. Options: true, false, {', '.join(plex.library_types)}")
year_value = int(str(meta[methods["year"]])) elif library_type == "false":
if 1800 <= year_value <= next_year: raise NotScheduled(f"Skipped because run_definition is false")
year = year_value elif library_type != "true" and self.library and library_type != self.library.Plex.type:
except ValueError: raise NotScheduled(f"Skipped because run_definition library_type: {library_type} doesn't match")
pass
if year is None: if "title" in methods:
raise Failed(f"Metadata Error: year attribute must be an integer between 1800 and {next_year}") if meta[methods["title"]] is None:
edition_title = edition_titles[0] if len(edition_titles) == 1 else None logger.error("Metadata Error: title attribute is blank")
item = self.library.search_item(title, year=year, edition=edition_title)
if not item and "alt_title" in methods:
if meta[methods["alt_title"]] is None:
logger.error("Metadata Error: alt_title attribute is blank")
else: else:
alt_title = meta[methods["alt_title"]] title = meta[methods["title"]]
item = self.library.search_item(alt_title, year=year, edition=edition_title)
if not item: edition_titles = None
item = self.library.search_item(alt_title, edition=edition_title) if "edition_filter" in methods and self.library.is_movie:
edition_titles = util.get_list(meta[methods["edition_filter"]])
if not edition_titles:
edition_titles = [""]
edition_contains = None
if "edition_contains" in methods and self.library.is_movie:
edition_contains = util.get_list(meta[methods["edition_contains"]])
if not edition_contains:
edition_contains = []
if not item: if not item:
logger.error(f"Skipping {mapping_name}: Item {title} not found") year = None
continue if "year" in methods and not self.library.is_music:
if not isinstance(item, list): if meta[methods["year"]] is None:
item = [item] raise Failed("Metadata Error: year attribute is blank")
if edition_titles or edition_contains: try:
item = [i for i in item if (edition_titles and i.editionTitle in edition_titles) or (edition_contains and any([r in i.editionTitle for r in edition_contains]))] year_value = int(str(meta[methods["year"]]))
if 1800 <= year_value <= next_year:
for i in item: year = year_value
self.update_metadata_item(i, title, mapping_name, meta, methods) except ValueError:
pass
if year is None:
raise Failed(f"Metadata Error: year attribute must be an integer between 1800 and {next_year}")
edition_title = edition_titles[0] if len(edition_titles) == 1 else None
item = self.library.search_item(title, year=year, edition=edition_title)
if not item and "alt_title" in methods:
if meta[methods["alt_title"]] is None:
logger.error("Metadata Error: alt_title attribute is blank")
else:
alt_title = meta[methods["alt_title"]]
item = self.library.search_item(alt_title, year=year, edition=edition_title)
if not item:
item = self.library.search_item(alt_title, edition=edition_title)
if not item:
logger.error(f"Skipping {mapping_name}: Item {title} not found")
continue
if not isinstance(item, list):
item = [item]
if edition_titles or edition_contains:
item = [i for i in item if (edition_titles and i.editionTitle in edition_titles) or (edition_contains and any([r in i.editionTitle for r in edition_contains]))]
for i in item:
try:
logger.separator(f"Updating {i.title}", space=False, border=False)
self.update_metadata_item(i, title, mapping_name, meta, methods)
except Failed as e:
logger.error(e)
except NotScheduled as e:
logger.info(e)
except Failed as e:
logger.error(e)
def update_metadata_item(self, item, title, mapping_name, meta, methods): def update_metadata_item(self, item, title, mapping_name, meta, methods):
@ -1359,7 +1384,33 @@ class MetadataFile(DataFile):
updated = True updated = True
logger.info(f"{self.library.type}: {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") logger.info(f"{self.library.type}: {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}")
if "seasons" in methods and self.library.is_show: update_seasons = True
if "update_seasons" in methods and self.library.is_show:
logger.debug("")
logger.debug("Validating Method: update_seasons")
if meta[methods["update_seasons"]] is None:
logger.warning("Metadata Warning: update_seasons has no value and season updates will be performed")
logger.debug(f"Value: {meta[methods['update_seasons']]}")
for library_type in util.get_list(meta[methods["run_definition"]], lower=True):
if library_type not in ["true", "false"]:
raise Failed(f"Metadata Error: {library_type} is invalid. Options: true or false")
elif library_type == "false":
update_seasons = False
update_episodes = True
if "update_episodes" in methods and self.library.is_show:
logger.debug("")
logger.debug("Validating Method: update_episodes")
if meta[methods["update_episodes"]] is None:
logger.warning("Metadata Warning: update_episodes has no value and episode updates will be performed")
logger.debug(f"Value: {meta[methods['update_episodes']]}")
for library_type in util.get_list(meta[methods["run_definition"]], lower=True):
if library_type not in ["true", "false"]:
raise Failed(f"Metadata Error: {library_type} is invalid. Options: true or false")
elif library_type == "false":
update_episodes = False
if "seasons" in methods and self.library.is_show and (update_seasons or update_episodes):
if not meta[methods["seasons"]]: if not meta[methods["seasons"]]:
logger.error("Metadata Error: seasons attribute is blank") logger.error("Metadata Error: seasons attribute is blank")
elif not isinstance(meta[methods["seasons"]], dict): elif not isinstance(meta[methods["seasons"]], dict):
@ -1379,21 +1430,22 @@ class MetadataFile(DataFile):
logger.error(f"Metadata Error: Season: {season_id} not found") logger.error(f"Metadata Error: Season: {season_id} not found")
continue continue
season_methods = {sm.lower(): sm for sm in season_dict} season_methods = {sm.lower(): sm for sm in season_dict}
#season.batchEdits() if update_seasons:
add_edit("title", season, season_dict, season_methods) #season.batchEdits()
add_edit("summary", season, season_dict, season_methods) add_edit("title", season, season_dict, season_methods)
add_edit("user_rating", season, season_dict, season_methods, key="userRating", var_type="float") add_edit("summary", season, season_dict, season_methods)
if self.edit_tags("label", season, season_dict, season_methods): add_edit("user_rating", season, season_dict, season_methods, key="userRating", var_type="float")
updated = True if self.edit_tags("label", season, season_dict, season_methods):
finish_edit(season, f"Season: {season_id}") updated = True
_, _, ups = self.library.item_images(season, season_dict, season_methods, asset_location=asset_location, finish_edit(season, f"Season: {season_id}")
title=f"{item.title} Season {season.seasonNumber}", _, _, ups = self.library.item_images(season, season_dict, season_methods, asset_location=asset_location,
image_name=f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}", folder_name=folder_name) title=f"{item.title} Season {season.seasonNumber}",
if ups: image_name=f"Season{'0' if season.seasonNumber < 10 else ''}{season.seasonNumber}", folder_name=folder_name)
updated = True if ups:
logger.info(f"Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") updated = True
logger.info(f"Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}")
if "episodes" in season_methods and self.library.is_show: if "episodes" in season_methods and update_episodes and self.library.is_show:
if not season_dict[season_methods["episodes"]]: if not season_dict[season_methods["episodes"]]:
logger.error("Metadata Error: episodes attribute is blank") logger.error("Metadata Error: episodes attribute is blank")
elif not isinstance(season_dict[season_methods["episodes"]], dict): elif not isinstance(season_dict[season_methods["episodes"]], dict):
@ -1433,7 +1485,7 @@ class MetadataFile(DataFile):
updated = True updated = True
logger.info(f"Episode {episode_str} in Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}") logger.info(f"Episode {episode_str} in Season {season_id} of {mapping_name} Details Update {'Complete' if updated else 'Not Needed'}")
if "episodes" in methods and self.library.is_show: if "episodes" in methods and update_episodes and self.library.is_show:
if not meta[methods["episodes"]]: if not meta[methods["episodes"]]:
logger.error("Metadata Error: episodes attribute is blank") logger.error("Metadata Error: episodes attribute is blank")
elif not isinstance(meta[methods["episodes"]], dict): elif not isinstance(meta[methods["episodes"]], dict):

Loading…
Cancel
Save