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_url_invalid = ["filters", "run_again", "sync_mode", "show_filtered", "show_missing", "save_missing", "smart_label"] + radarr_details + sonarr_details
custom_sort_builders = [
"tmdb_collection", "tmdb_list", "tmdb_popular", "tmdb_now_playing", "tmdb_top_rated",
"tmdb_trending_daily", "tmdb_trending_weekly", "tmdb_discover",
"tvdb_list", "imdb_list",
"trakt_list", "trakt_trending", "trakt_popular", "trakt_recommended", "trakt_watched", "trakt_collected",
"tautulli_popular", "tautulli_watched", "letterboxd_list", "icheckmovies_list",
"anidb_popular",
"anilist_top_rated", "anilist_popular", "anilist_season", "anilist_studio", "anilist_genre", "anilist_tag",
"mal_all", "mal_airing", "mal_upcoming", "mal_tv", "mal_movie", "mal_ova", "mal_special",
"mal_popular", "mal_favorite", "mal_suggested", "mal_userlist", "mal_season"
#"tmdb_collection", "tmdb_list", "tmdb_popular", "tmdb_now_playing", "tmdb_top_rated",
#"tmdb_trending_daily", "tmdb_trending_weekly", "tmdb_discover",
#"tvdb_list",
"imdb_list"
#"trakt_list", "trakt_trending", "trakt_popular", "trakt_recommended", "trakt_watched", "trakt_collected",
#"tautulli_popular", "tautulli_watched", "letterboxd_list", "icheckmovies_list",
#"anidb_popular",
#"anilist_top_rated", "anilist_popular", "anilist_season", "anilist_studio", "anilist_genre", "anilist_tag",
#"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:
@ -385,7 +386,7 @@ class CollectionBuilder:
logger.debug(f"Value: {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:
logger.info("")
logger.info("Validating Method: collection_order")
@ -393,8 +394,8 @@ class CollectionBuilder:
raise Failed(f"Collection Warning: collection_order attribute is blank")
elif self.data[methods["collection_order"]].lower() in plex.collection_order_options:
self.details["collection_order"] = self.data[methods["collection_order"]].lower()
if self.data[methods["collection_order"]].lower() == "custom":
self.sort_collection = True
if self.data[methods["collection_order"]].lower() == "custom" and self.build_collection:
self.custom_sort = True
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)")
@ -511,10 +512,10 @@ class CollectionBuilder:
elif method_name == "filters": self._filters(method_name, method_data)
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")
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]}")
if self.add_to_radarr is None:
@ -1791,6 +1792,20 @@ class CollectionBuilder:
if poster or 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):
self.obj = self.library.get_collection(self.name)
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/"
}
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()",
"search": "//div[@class='desc']/span/text()",
"keyword": "//div[@class='desc']/text()"
@ -91,6 +91,7 @@ class IMDb:
time.sleep(2)
util.print_end()
if len(imdb_ids) > 0:
logger.debug(f"{len(imdb_ids)} IMDb IDs Found: {imdb_ids}")
return imdb_ids
raise ValueError(f"IMDb Error: No IMDb IDs Found at {imdb_url}")

@ -489,6 +489,12 @@ class Plex:
else: method = None
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):
labels = self.get_labels()
if title not in labels:

@ -463,6 +463,12 @@ def run_collection(config, library, metadata, requested_collections):
logger.info("")
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("")
util.separator(f"Updating Details of the Items in {mapping_name} Collection", space=False, border=False)
logger.info("")

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

Loading…
Cancel
Save