Skip to content

Commit

Permalink
Merge pull request #14 from meisnate12/develop
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
meisnate12 authored Feb 11, 2021
2 parents a6dac05 + 015495d commit a7c420d
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Plex Meta Manager
#### Version 1.0.1

The original concept for Plex Meta Manager is [Plex Auto Collections](https:/mza921/Plex-Auto-Collections), but this is rewritten from the ground up to be able to include a scheduler, metadata edits, multiple libraries, and logging. Plex Meta Manager is a Python 3 script that can be continuously run using YAML configuration files to update on a schedule the metadata of the movies, shows, and collections in your libraries as well as automatically build collections based on various methods all detailed in the wiki. Some collection examples that the script can automatically build and update daily include Plex Based Searches like actor, genre, or studio collections or Collections based on TMDb, IMDb, Trakt, TVDb, AniDB, or MyAnimeList lists and various other services.

Expand Down
1 change: 1 addition & 0 deletions config/config.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plex: # Can be individually specified pe
token: ####################
sync_mode: append
asset_directory: config/assets
show_unmanaged_collections: true
radarr: # Can be individually specified per library as well
url: http://192.168.1.12:7878
token: ################################
Expand Down
40 changes: 28 additions & 12 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
self.general["plex"]["token"] = check_for_attribute(self.data, "token", parent="plex", default_is_none=True) if "plex" in self.data else None
self.general["plex"]["asset_directory"] = check_for_attribute(self.data, "asset_directory", parent="plex", var_type="path", default=os.path.join(default_dir, "assets")) if "plex" in self.data else os.path.join(default_dir, "assets")
self.general["plex"]["sync_mode"] = check_for_attribute(self.data, "sync_mode", parent="plex", default="append", test_list=["append", "sync"], options="| \tappend (Only Add Items to the Collection)\n| \tsync (Add & Remove Items from the Collection)") if "plex" in self.data else "append"
self.general["plex"]["show_unmanaged_collections"] = check_for_attribute(self.data, "show_unmanaged_collections", parent="plex", var_type="bool", default=True) if "plex" in self.data else True

self.general["radarr"] = {}
self.general["radarr"]["url"] = check_for_attribute(self.data, "url", parent="radarr", default_is_none=True) if "radarr" in self.data else None
Expand Down Expand Up @@ -239,6 +240,16 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, options=""
else:
logger.warning("Config Warning: sync_mode attribute is blank using general value: {}".format(self.general["plex"]["sync_mode"]))

params["show_unmanaged_collections"] = self.general["plex"]["show_unmanaged_collections"]
if "plex" in libs[lib] and "show_unmanaged_collections" in libs[lib]["plex"]:
if libs[lib]["plex"]["show_unmanaged_collections"]:
if isinstance(libs[lib]["plex"]["show_unmanaged_collections"], bool):
params["plex"]["show_unmanaged_collections"] = libs[lib]["plex"]["show_unmanaged_collections"]
else:
logger.warning("Config Warning: plex sub-attribute show_unmanaged_collections must be either true or false using general value: {}".format(self.general["plex"]["show_unmanaged_collections"]))
else:
logger.warning("Config Warning: radarr sub-attribute add is blank using general value: {}".format(self.general["radarr"]["add"]))

params["tmdb"] = self.TMDb
params["tvdb"] = self.TVDb

Expand Down Expand Up @@ -533,6 +544,8 @@ def update_libraries(self):
logger.info("Collection Error: {} skipped. MyAnimeList must be configured".format(m))
map = {}
elif collections[c][m] is not None:
logger.debug("Method: {}".format(m))
logger.debug("Value: {}".format(collections[c][m]))
if m in util.method_alias:
method_name = util.method_alias[m]
logger.warning("Collection Warning: {} attribute will run as {}".format(m, method_name))
Expand Down Expand Up @@ -843,8 +856,11 @@ def get_int(parent, method, data, default, min=1, max=None):
library.clear_collection_missing(collection_name)

for method, values in methods:
logger.debug("Method: {}".format(method))
logger.debug("Values: {}".format(values))
pretty = util.pretty_names[method] if method in util.pretty_names else method
for value in values:
logger.debug("Value: {}".format(value))
items = []
missing_movies = []
missing_shows = []
Expand Down Expand Up @@ -986,10 +1002,10 @@ def check_map(input_ids):
edits["summary.value"] = details["summary"]
edits["summary.locked"] = 1
if len(edits) > 0:
logger.debug(edits)
plex_collection.edit(**edits)
plex_collection.reload()
logger.info("Details: have been updated")
logger.debug(edits)
if "collection_mode" in details:
plex_collection.modeUpdate(mode=details["collection_mode"])
if "collection_order" in details:
Expand Down Expand Up @@ -1027,17 +1043,17 @@ def check_map(input_ids):
except Exception as e:
util.print_stacktrace()
logger.error("Unknown Error: {}".format(e))

logger.info("")
util.seperator("Unmanaged Collections in {} Library".format(library.name))
logger.info("")
unmanaged_count = 0
collections_in_plex = [str(pcol) for pcol in collections]
for col in library.get_all_collections():
if col.title not in collections_in_plex:
logger.info(col.title)
unmanaged_count += 1
logger.info("{} Unmanaged Collections".format(unmanaged_count))
if library.show_unmanaged_collections is True:
logger.info("")
util.seperator("Unmanaged Collections in {} Library".format(library.name))
logger.info("")
unmanaged_count = 0
collections_in_plex = [str(pcol) for pcol in collections]
for col in library.get_all_collections():
if col.title not in collections_in_plex:
logger.info(col.title)
unmanaged_count += 1
logger.info("{} Unmanaged Collections".format(unmanaged_count))
else:
logger.error("No collection to update")

Expand Down
6 changes: 5 additions & 1 deletion modules/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, params):
self.metadata_path = params["metadata_path"]
self.asset_directory = params["asset_directory"]
self.sync_mode = params["sync_mode"]
self.show_unmanaged_collections = params["show_unmanaged_collections"]
self.plex = params["plex"]
self.radarr = params["radarr"]
self.sonarr = params["sonarr"]
Expand Down Expand Up @@ -293,7 +294,10 @@ def add_edit(name, current, group, key=None, value=None):
add_edit("originally_available", str(item.originallyAvailableAt)[:-9], self.metadata[m], key="originallyAvailableAt", value=originally_available)
add_edit("rating", item.rating, self.metadata[m], value=rating)
add_edit("content_rating", item.contentRating, self.metadata[m], key="contentRating")
add_edit("original_title", item.originalTitle, self.metadata[m], key="originalTitle", value=original_title)
if self.is_movie:
add_edit("original_title", item.originalTitle, self.metadata[m], key="originalTitle", value=original_title)
elif "original_title" in self.metadata[m]:
logger.error("Metadata Error: original_title does not work with shows")
add_edit("studio", item.studio, self.metadata[m], value=studio)
add_edit("tagline", item.tagline, self.metadata[m], value=tagline)
add_edit("summary", item.summary, self.metadata[m], value=summary)
Expand Down
8 changes: 6 additions & 2 deletions modules/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def add_tmdb(self, tmdb_ids):
"title": movie.title,
"{}".format("qualityProfileId" if self.version == "v3" else "profileId"): self.quality_profile_id,
"year": int(year),
"tmdbid": str(tmdb_id),
"tmdbid": int(tmdb_id),
"titleslug": titleslug,
"monitored": True,
"rootFolderPath": self.root_folder_path,
Expand All @@ -79,7 +79,11 @@ def add_tmdb(self, tmdb_ids):
logger.info("Added to Radarr | {:<6} | {}".format(tmdb_id, movie.title))
add_count += 1
else:
logger.error("Radarr Error: ({}) {}: ({}) {}".format(tmdb_id, movie.title, response.status_code, response.json()[0]["errorMessage"]))
try:
logger.error("Radarr Error: ({}) {}: ({}) {}".format(tmdb_id, movie.title, response.status_code, response.json()[0]["errorMessage"]))
except KeyError as e:
logger.debug(url_json)
logger.error("Radarr Error: {}".format(response.json()))
logger.info("{} Movie{} added to Radarr".format(add_count, "s" if add_count > 1 else ""))

@retry(stop_max_attempt_number=6, wait_fixed=10000)
Expand Down
6 changes: 5 additions & 1 deletion modules/sonarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def add_tvdb(self, tvdb_ids):
logger.info("Added to Sonarr | {:<6} | {}".format(tvdb_id, show.title))
add_count += 1
else:
logger.error("Sonarr Error: ({}) {}: ({}) {}".format(tvdb_id, show.title, response.status_code, response.json()[0]["errorMessage"]))
try:
logger.error("Sonarr Error: ({}) {}: ({}) {}".format(tvdb_id, show.title, response.status_code, response.json()[0]["errorMessage"]))
except KeyError as e:
logger.debug(url_json)
logger.error("Sonarr Error: {}".format(response.json()))
logger.info("{} Show{} added to Sonarr".format(add_count, "s" if add_count > 1 else ""))

@retry(stop_max_attempt_number=6, wait_fixed=10000)
Expand Down
2 changes: 1 addition & 1 deletion modules/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging, re, signal, sys, time, traceback
import datetime, logging, re, signal, sys, time, traceback

try:
import msvcrt
Expand Down
2 changes: 1 addition & 1 deletion plex_meta_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def fmt_filter(record):
logger.info(util.get_centered_text("| __/| | __/> < | | | | __/ || (_| | | | | | (_| | | | | (_| | (_| | __/ | "))
logger.info(util.get_centered_text("|_| |_|\___/_/\_\ |_| |_|\___|\__\__,_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| "))
logger.info(util.get_centered_text(" |___/ "))
logger.info(util.get_centered_text(" Version: 1.0.0 "))
logger.info(util.get_centered_text(" Version: 1.0.1 "))
util.seperator()

if args.test:
Expand Down

0 comments on commit a7c420d

Please sign in to comment.