fix duplication error with imdb_list

pull/351/head
meisnate12 3 years ago
parent ba977e6a37
commit c55d93bbfb

@ -124,15 +124,16 @@ show_only_filters = ["network"]
smart_invalid = ["collection_order"] smart_invalid = ["collection_order"]
smart_url_invalid = ["filters", "run_again", "sync_mode", "show_filtered", "show_missing", "save_missing", "smart_label"] + radarr_details + sonarr_details smart_url_invalid = ["filters", "run_again", "sync_mode", "show_filtered", "show_missing", "save_missing", "smart_label"] + radarr_details + sonarr_details
custom_sort_builders = [ custom_sort_builders = [
"tmdb_collection", "tmdb_list", "tmdb_popular", "tmdb_now_playing", "tmdb_top_rated", #"tmdb_collection", "tmdb_list", "tmdb_popular", "tmdb_now_playing", "tmdb_top_rated",
"tmdb_trending_daily", "tmdb_trending_weekly", "tmdb_discover", #"tmdb_trending_daily", "tmdb_trending_weekly", "tmdb_discover",
"tvdb_list", "imdb_list", #"tvdb_list",
"trakt_list", "trakt_trending", "trakt_popular", "trakt_recommended", "trakt_watched", "trakt_collected", "imdb_list"
"tautulli_popular", "tautulli_watched", "letterboxd_list", "icheckmovies_list", #"trakt_list", "trakt_trending", "trakt_popular", "trakt_recommended", "trakt_watched", "trakt_collected",
"anidb_popular", #"tautulli_popular", "tautulli_watched", "letterboxd_list", "icheckmovies_list",
"anilist_top_rated", "anilist_popular", "anilist_season", "anilist_studio", "anilist_genre", "anilist_tag", #"anidb_popular",
"mal_all", "mal_airing", "mal_upcoming", "mal_tv", "mal_movie", "mal_ova", "mal_special", #"anilist_top_rated", "anilist_popular", "anilist_season", "anilist_studio", "anilist_genre", "anilist_tag",
"mal_popular", "mal_favorite", "mal_suggested", "mal_userlist", "mal_season" #"mal_all", "mal_airing", "mal_upcoming", "mal_tv", "mal_movie", "mal_ova", "mal_special",
#"mal_popular", "mal_favorite", "mal_suggested", "mal_userlist", "mal_season"
] ]
class CollectionBuilder: class CollectionBuilder:
@ -385,7 +386,7 @@ class CollectionBuilder:
logger.debug(f"Value: {self.data[methods['build_collection']]}") logger.debug(f"Value: {self.data[methods['build_collection']]}")
self.build_collection = util.parse_bool("build_collection", self.data[methods["build_collection"]]) self.build_collection = util.parse_bool("build_collection", self.data[methods["build_collection"]])
self.sort_collection = False self.custom_sort = False
if "collection_order" in methods: if "collection_order" in methods:
logger.info("") logger.info("")
logger.info("Validating Method: collection_order") logger.info("Validating Method: collection_order")
@ -393,8 +394,8 @@ class CollectionBuilder:
raise Failed(f"Collection Warning: collection_order attribute is blank") raise Failed(f"Collection Warning: collection_order attribute is blank")
elif self.data[methods["collection_order"]].lower() in plex.collection_order_options: elif self.data[methods["collection_order"]].lower() in plex.collection_order_options:
self.details["collection_order"] = self.data[methods["collection_order"]].lower() self.details["collection_order"] = self.data[methods["collection_order"]].lower()
if self.data[methods["collection_order"]].lower() == "custom": if self.data[methods["collection_order"]].lower() == "custom" and self.build_collection:
self.sort_collection = True self.custom_sort = True
else: else:
raise Failed(f"Collection Error: {self.data[methods['collection_order']]} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)") raise Failed(f"Collection Error: {self.data[methods['collection_order']]} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)")
@ -511,10 +512,10 @@ class CollectionBuilder:
elif method_name == "filters": self._filters(method_name, method_data) elif method_name == "filters": self._filters(method_name, method_data)
else: raise Failed(f"Collection Error: {method_final} attribute not supported") else: raise Failed(f"Collection Error: {method_final} attribute not supported")
if self.sort_collection and len(self.builders) > 1: if self.custom_sort and len(self.builders) > 1:
raise Failed("Collection Error: collection_order: custom can only be used with a single builder per collection") raise Failed("Collection Error: collection_order: custom can only be used with a single builder per collection")
if self.sort_collection and self.builders[0][0] not in custom_sort_builders: if self.custom_sort and self.builders[0][0] not in custom_sort_builders:
raise Failed(f"Collection Error: collection_order: custom cannot be used with {self.builders[0][0]}") raise Failed(f"Collection Error: collection_order: custom cannot be used with {self.builders[0][0]}")
if self.add_to_radarr is None: if self.add_to_radarr is None:
@ -1791,6 +1792,20 @@ class CollectionBuilder:
if poster or background: if poster or background:
self.library.upload_images(self.obj, poster=poster, background=background) self.library.upload_images(self.obj, poster=poster, background=background)
def sort_collection(self):
items = self.library.get_collection_items(self.obj, self.smart_label_collection)
keys = {item.ratingKey: item for item in items}
previous = None
for ki, key in enumerate(self.rating_keys):
if key != items[ki].ratingKey:
logger.info(f"Moving {keys[key].title} {'after {}'.format(keys[previous].title) if previous else 'to the beginning'}")
self.library.moveItem(self.obj, key, after=previous)
for ii, item in enumerate(items):
if key == item.ratingKey:
items.insert(ki, items.pop(ii))
break
previous = key
def run_collections_again(self): def run_collections_again(self):
self.obj = self.library.get_collection(self.name) self.obj = self.library.get_collection(self.name)
name, collection_items = self.library.get_collection_name_and_items(self.obj, self.smart_label_collection) name, collection_items = self.library.get_collection_name_and_items(self.obj, self.smart_label_collection)

@ -13,7 +13,7 @@ urls = {
"keyword": f"{base_url}/search/keyword/" "keyword": f"{base_url}/search/keyword/"
} }
xpath = { xpath = {
"imdb_id": "//div[contains(@class, 'lister-item-image')]//@data-tconst", "imdb_id": "//div[contains(@class, 'lister-item-image')]//a/img//@data-tconst",
"list": "//div[@class='desc lister-total-num-results']/text()", "list": "//div[@class='desc lister-total-num-results']/text()",
"search": "//div[@class='desc']/span/text()", "search": "//div[@class='desc']/span/text()",
"keyword": "//div[@class='desc']/text()" "keyword": "//div[@class='desc']/text()"
@ -91,6 +91,7 @@ class IMDb:
time.sleep(2) time.sleep(2)
util.print_end() util.print_end()
if len(imdb_ids) > 0: if len(imdb_ids) > 0:
logger.debug(f"{len(imdb_ids)} IMDb IDs Found: {imdb_ids}")
return imdb_ids return imdb_ids
raise ValueError(f"IMDb Error: No IMDb IDs Found at {imdb_url}") raise ValueError(f"IMDb Error: No IMDb IDs Found at {imdb_url}")

@ -489,6 +489,12 @@ class Plex:
else: method = None else: method = None
return self.Plex._server.query(key, method=method) return self.Plex._server.query(key, method=method)
def moveItem(self, collection, item, after=None):
key = f"{collection.key}/items/{item}/move"
if after:
key += f"?after={after}"
self._query(key, put=True)
def smart_label_url(self, title, sort): def smart_label_url(self, title, sort):
labels = self.get_labels() labels = self.get_labels()
if title not in labels: if title not in labels:

@ -463,6 +463,12 @@ def run_collection(config, library, metadata, requested_collections):
logger.info("") logger.info("")
builder.update_details() builder.update_details()
if builder.custom_sort:
logger.info("")
util.separator(f"Sorting {mapping_name} Collection", space=False, border=False)
logger.info("")
builder.sort_collection()
logger.info("") logger.info("")
util.separator(f"Updating Details of the Items in {mapping_name} Collection", space=False, border=False) util.separator(f"Updating Details of the Items in {mapping_name} Collection", space=False, border=False)
logger.info("") logger.info("")

@ -1,4 +1,4 @@
PlexAPI==4.6.1 PlexAPI==4.7.0
tmdbv3api==1.7.6 tmdbv3api==1.7.6
arrapi==1.1.1 arrapi==1.1.1
lxml lxml

Loading…
Cancel
Save