[103] fix more reloads

pull/1328/head
meisnate12 2 years ago
parent af93849e6d
commit f0f6c01d4e

@ -1 +1 @@
1.18.3-develop102 1.18.3-develop103

@ -1730,7 +1730,7 @@ class CollectionBuilder:
for pl_library in self.libraries: for pl_library in self.libraries:
if tvdb_id in pl_library.show_map: if tvdb_id in pl_library.show_map:
found = True found = True
show_item = pl_library.fetchItem(pl_library.show_map[tvdb_id][0]) show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0])
try: try:
items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) items.append(show_item.episode(season=int(season_num), episode=int(episode_num)))
except NotFound: except NotFound:
@ -1769,7 +1769,7 @@ class CollectionBuilder:
for pl_library in self.libraries: for pl_library in self.libraries:
if tvdb_id in pl_library.show_map: if tvdb_id in pl_library.show_map:
found = True found = True
show_item = pl_library.fetchItem(pl_library.show_map[tvdb_id][0]) show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0])
try: try:
season_obj = show_item.season(season=int(season_num)) season_obj = show_item.season(season=int(season_num))
if self.playlist: if self.playlist:
@ -1788,7 +1788,7 @@ class CollectionBuilder:
for pl_library in self.libraries: for pl_library in self.libraries:
if tvdb_id in pl_library.show_map: if tvdb_id in pl_library.show_map:
found = True found = True
show_item = pl_library.fetchItem(pl_library.show_map[tvdb_id][0]) show_item = pl_library.fetch_item(pl_library.show_map[tvdb_id][0])
try: try:
items.append(show_item.episode(season=int(season_num), episode=int(episode_num))) items.append(show_item.episode(season=int(season_num), episode=int(episode_num)))
except NotFound: except NotFound:
@ -1825,7 +1825,7 @@ class CollectionBuilder:
rating_keys = [] rating_keys = []
for rk in found_keys: for rk in found_keys:
try: try:
item = self.fetch_item(rk) item = self.library.fetch_item(rk)
if self.builder_level == "episode" and isinstance(item, Show): if self.builder_level == "episode" and isinstance(item, Show):
if tvdb_season is not None: if tvdb_season is not None:
item = item.season(season=tvdb_season) item = item.season(season=tvdb_season)
@ -1843,7 +1843,7 @@ class CollectionBuilder:
rating_keys = [rating_keys] rating_keys = [rating_keys]
for rk in rating_keys: for rk in rating_keys:
try: try:
item = self.fetch_item(rk) item = self.library.fetch_item(rk)
if self.playlist and isinstance(item, (Show, Season)): if self.playlist and isinstance(item, (Show, Season)):
items.extend(item.episodes()) items.extend(item.episodes())
elif self.builder_level == "movie" and not isinstance(item, Movie): elif self.builder_level == "movie" and not isinstance(item, Movie):
@ -2264,24 +2264,6 @@ class CollectionBuilder:
else: else:
raise Failed(f"{self.Type} Error: {final} attribute not supported") raise Failed(f"{self.Type} Error: {final} attribute not supported")
def fetch_item(self, item):
if isinstance(item, (Movie, Show, Season, Episode, Artist, Album, Track)):
if item.ratingKey not in self.library.cached_items:
self.library.cached_items[item.ratingKey] = (item, False)
return item
key = int(item)
if key in self.library.cached_items:
cached_item, full_obj = self.library.cached_items[key]
return cached_item
try:
current = self.library.fetchItem(key)
if not isinstance(current, (Movie, Show, Season, Episode, Artist, Album, Track)):
raise NotFound
self.library.cached_items[key] = (current, True)
return current
except (BadRequest, NotFound):
raise Failed(f"Plex Error: Item {item} not found")
def add_to_collection(self): def add_to_collection(self):
logger.info("") logger.info("")
logger.separator(f"Adding to {self.name} {self.Type}", space=False, border=False) logger.separator(f"Adding to {self.name} {self.Type}", space=False, border=False)
@ -3008,9 +2990,9 @@ class CollectionBuilder:
if len(rating_keys) > 0: if len(rating_keys) > 0:
for rating_key in rating_keys: for rating_key in rating_keys:
try: try:
current = self.library.fetchItem(int(rating_key)) current = self.library.fetch_item(int(rating_key))
except (BadRequest, NotFound): except Failed as e:
logger.error(f"Plex Error: Item {rating_key} not found") logger.error(e)
continue continue
if current in collection_items: if current in collection_items:
logger.info(f"{name} {self.Type} | = | {util.item_title(current)}") logger.info(f"{name} {self.Type} | = | {util.item_title(current)}")

@ -1171,13 +1171,13 @@ class MetadataFile(DataFile):
logger.info(f"{id_type} ID Mapping: {mapping_id}") logger.info(f"{id_type} ID Mapping: {mapping_id}")
if self.library.is_movie and mapping_id in self.library.movie_map: if self.library.is_movie and mapping_id in self.library.movie_map:
for item_id in self.library.movie_map[mapping_id]: for item_id in self.library.movie_map[mapping_id]:
item.append(self.library.fetchItem(item_id)) item.append(self.library.fetch_item(item_id))
elif self.library.is_show and mapping_id in self.library.show_map: elif self.library.is_show and mapping_id in self.library.show_map:
for item_id in self.library.show_map[mapping_id]: for item_id in self.library.show_map[mapping_id]:
item.append(self.library.fetchItem(item_id)) item.append(self.library.fetch_item(item_id))
elif mapping_id in self.library.imdb_map: elif mapping_id in self.library.imdb_map:
for item_id in self.library.imdb_map[mapping_id]: for item_id in self.library.imdb_map[mapping_id]:
item.append(self.library.fetchItem(item_id)) item.append(self.library.fetch_item(item_id))
else: else:
logger.error(f"Metadata Error: {id_type} ID not mapped") logger.error(f"Metadata Error: {id_type} ID not mapped")
continue continue

@ -506,6 +506,20 @@ class Plex(Library):
terms["year"] = year terms["year"] = year
return self.Plex.search(libtype=libtype, **terms) return self.Plex.search(libtype=libtype, **terms)
def fetch_item(self, item):
if isinstance(item, (Movie, Show, Season, Episode, Artist, Album, Track)):
return self.reload(item)
key = int(item)
if key in self.cached_items:
return self.reload(self.cached_items[key][0])
try:
current = self.fetchItem(key)
if isinstance(current, (Movie, Show, Season, Episode, Artist, Album, Track)):
return self.reload(current)
except (BadRequest, NotFound) as e:
logger.trace(e)
raise Failed(f"Plex Error: Item {item} not found")
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex)
def fetchItem(self, data): def fetchItem(self, data):
return self.PlexServer.fetchItem(data) return self.PlexServer.fetchItem(data)
@ -657,23 +671,22 @@ class Plex(Library):
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex)
def reload(self, item, force=False): def reload(self, item, force=False):
is_full = False is_full = False
cached_item = item if not force and item.ratingKey in self.cached_items:
if not force and cached_item.ratingKey in self.cached_items: item, is_full = self.cached_items[item.ratingKey]
cached_item, is_full = self.cached_items[cached_item.ratingKey]
try: try:
if not is_full or force: if not is_full or force:
cached_item.reload(checkFiles=False, includeAllConcerts=False, includeBandwidths=False, item.reload(checkFiles=False, includeAllConcerts=False, includeBandwidths=False,
includeChapters=False, includeChildren=False, includeConcerts=False, includeChapters=False, includeChildren=False, includeConcerts=False,
includeExternalMedia=False, includeExtras=False, includeFields=False, includeExternalMedia=False, includeExtras=False, includeFields=False,
includeGeolocation=False, includeLoudnessRamps=False, includeMarkers=False, includeGeolocation=False, includeLoudnessRamps=False, includeMarkers=False,
includeOnDeck=False, includePopularLeaves=False, includeRelated=False, includeOnDeck=False, includePopularLeaves=False, includeRelated=False,
includeRelatedCount=0, includeReviews=False, includeStations=False) includeRelatedCount=0, includeReviews=False, includeStations=False)
cached_item._autoReload = False item._autoReload = False
self.cached_items[cached_item.ratingKey] = (cached_item, True) self.cached_items[item.ratingKey] = (item, True)
return cached_item
except (BadRequest, NotFound) as e: except (BadRequest, NotFound) as e:
logger.stacktrace() logger.stacktrace()
raise Failed(f"Item Failed to Load: {e}") raise Failed(f"Item Failed to Load: {e}")
return item
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_plex)
def edit_query(self, item, edits, advanced=False): def edit_query(self, item, edits, advanced=False):

@ -45,16 +45,16 @@ class Tautulli:
if int(item[stat_type]) < params['list_minimum']: if int(item[stat_type]) < params['list_minimum']:
continue continue
try: try:
plex_item = self.library.fetchItem(int(item["rating_key"])) plex_item = self.library.fetch_item(int(item["rating_key"]))
if not isinstance(plex_item, (Movie, Show)): if not isinstance(plex_item, (Movie, Show)):
raise BadRequest raise BadRequest
rating_keys.append((item["rating_key"], "ratingKey")) rating_keys.append((item["rating_key"], "ratingKey"))
except (BadRequest, NotFound): except Failed as e:
new_item = self.library.exact_search(item["title"], year=item["year"]) new_item = self.library.exact_search(item["title"], year=item["year"])
if new_item: if new_item:
rating_keys.append((new_item[0].ratingKey, "ratingKey")) rating_keys.append((new_item[0].ratingKey, "ratingKey"))
else: else:
logger.error(f"Plex Error: Item not found {item}") logger.error(e)
return rating_keys return rating_keys
def _request(self, url): def _request(self, url):

Loading…
Cancel
Save