mirror of
https://github.com/meisnate12/Plex-Meta-Manager
synced 2024-11-22 20:43:07 +00:00
added trakt_collection
This commit is contained in:
parent
07f7caf610
commit
a6b7338544
3 changed files with 29 additions and 20 deletions
|
@ -248,7 +248,7 @@ class CollectionBuilder:
|
||||||
elif method_name == "tvdb_description":
|
elif method_name == "tvdb_description":
|
||||||
self.summaries[method_name] = config.TVDb.get_list_description(method_data, self.library.Plex.language)
|
self.summaries[method_name] = config.TVDb.get_list_description(method_data, self.library.Plex.language)
|
||||||
elif method_name == "trakt_description":
|
elif method_name == "trakt_description":
|
||||||
self.summaries[method_name] = config.Trakt.standard_list(config.Trakt.validate_trakt_list(util.get_list(method_data))[0]).description
|
self.summaries[method_name] = config.Trakt.standard_list(config.Trakt.validate_trakt(util.get_list(method_data))[0]).description
|
||||||
elif method_name == "letterboxd_description":
|
elif method_name == "letterboxd_description":
|
||||||
self.summaries[method_name] = config.Letterboxd.get_list_description(method_data, self.library.Plex.language)
|
self.summaries[method_name] = config.Letterboxd.get_list_description(method_data, self.library.Plex.language)
|
||||||
elif method_name == "collection_mode":
|
elif method_name == "collection_mode":
|
||||||
|
@ -355,15 +355,15 @@ class CollectionBuilder:
|
||||||
elif method_name in ["anilist_id", "anilist_relations", "anilist_studio"]:
|
elif method_name in ["anilist_id", "anilist_relations", "anilist_studio"]:
|
||||||
self.methods.append((method_name, config.AniList.validate_anilist_ids(util.get_int_list(method_data, "AniList ID"), studio=method_name == "anilist_studio")))
|
self.methods.append((method_name, config.AniList.validate_anilist_ids(util.get_int_list(method_data, "AniList ID"), studio=method_name == "anilist_studio")))
|
||||||
elif method_name == "trakt_list":
|
elif method_name == "trakt_list":
|
||||||
self.methods.append((method_name, config.Trakt.validate_trakt_list(util.get_list(method_data))))
|
self.methods.append((method_name, config.Trakt.validate_trakt(util.get_list(method_data))))
|
||||||
elif method_name == "trakt_list_details":
|
elif method_name == "trakt_list_details":
|
||||||
valid_list = config.Trakt.validate_trakt_list(util.get_list(method_data))
|
valid_list = config.Trakt.validate_trakt(util.get_list(method_data))
|
||||||
item = config.Trakt.standard_list(valid_list[0])
|
item = config.Trakt.standard_list(valid_list[0])
|
||||||
if hasattr(item, "description") and item.description:
|
if hasattr(item, "description") and item.description:
|
||||||
self.summaries[method_name] = item.description
|
self.summaries[method_name] = item.description
|
||||||
self.methods.append((method_name[:-8], valid_list))
|
self.methods.append((method_name[:-8], valid_list))
|
||||||
elif method_name == "trakt_watchlist":
|
elif method_name in ["trakt_watchlist", "trakt_collection"]:
|
||||||
self.methods.append((method_name, config.Trakt.validate_trakt_watchlist(util.get_list(method_data), self.library.is_movie)))
|
self.methods.append((method_name, config.Trakt.validate_trakt(method_name[6:], util.get_list(method_data), self.library.is_movie)))
|
||||||
elif method_name == "imdb_list":
|
elif method_name == "imdb_list":
|
||||||
new_list = []
|
new_list = []
|
||||||
for imdb_list in util.get_list(method_data, split=False):
|
for imdb_list in util.get_list(method_data, split=False):
|
||||||
|
|
|
@ -111,6 +111,11 @@ class TraktAPI:
|
||||||
def send_request(self, url):
|
def send_request(self, url):
|
||||||
return requests.get(url, headers={"Content-Type": "application/json", "trakt-api-version": "2", "trakt-api-key": self.client_id}).json()
|
return requests.get(url, headers={"Content-Type": "application/json", "trakt-api-version": "2", "trakt-api-key": self.client_id}).json()
|
||||||
|
|
||||||
|
def get_collection(self, username, is_movie):
|
||||||
|
items = self.send_request(f"{self.base_url}/users/{username}/collection/{'movies' if is_movie else 'shows'}")
|
||||||
|
if is_movie: return [item["movie"]["ids"]["tmdb"] for item in items], []
|
||||||
|
else: return [], [item["show"]["ids"]["tvdb"] for item in items]
|
||||||
|
|
||||||
def get_pagenation(self, pagenation, amount, is_movie):
|
def get_pagenation(self, pagenation, amount, is_movie):
|
||||||
items = self.send_request(f"{self.base_url}/{'movies' if is_movie else 'shows'}/{pagenation}?limit={amount}")
|
items = self.send_request(f"{self.base_url}/{'movies' if is_movie else 'shows'}/{pagenation}?limit={amount}")
|
||||||
if pagenation == "popular" and is_movie: return [item["ids"]["tmdb"] for item in items], []
|
if pagenation == "popular" and is_movie: return [item["ids"]["tmdb"] for item in items], []
|
||||||
|
@ -118,28 +123,26 @@ class TraktAPI:
|
||||||
elif is_movie: return [item["movie"]["ids"]["tmdb"] for item in items], []
|
elif is_movie: return [item["movie"]["ids"]["tmdb"] for item in items], []
|
||||||
else: return [], [item["show"]["ids"]["tvdb"] for item in items]
|
else: return [], [item["show"]["ids"]["tvdb"] for item in items]
|
||||||
|
|
||||||
def validate_trakt_list(self, values):
|
def validate_trakt(self, values, trakt_type=None, is_movie=None):
|
||||||
trakt_values = []
|
trakt_values = []
|
||||||
for value in values:
|
for value in values:
|
||||||
try:
|
try:
|
||||||
self.standard_list(value)
|
if trakt_type == "watchlist" and is_movie is not None:
|
||||||
|
self.watchlist(value, is_movie)
|
||||||
|
elif trakt_type == "collection" and is_movie is not None:
|
||||||
|
self.get_collection(value, is_movie)
|
||||||
|
else:
|
||||||
|
self.standard_list(value)
|
||||||
trakt_values.append(value)
|
trakt_values.append(value)
|
||||||
except Failed as e:
|
except Failed as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
if len(trakt_values) == 0:
|
if len(trakt_values) == 0:
|
||||||
raise Failed(f"Trakt Error: No valid Trakt Lists in {values}")
|
if trakt_type == "watchlist" and is_movie is not None:
|
||||||
return trakt_values
|
raise Failed(f"Trakt Error: No valid Trakt Watchlists in {values}")
|
||||||
|
elif trakt_type == "collection" and is_movie is not None:
|
||||||
def validate_trakt_watchlist(self, values, is_movie):
|
raise Failed(f"Trakt Error: No valid Trakt Collections in {values}")
|
||||||
trakt_values = []
|
else:
|
||||||
for value in values:
|
raise Failed(f"Trakt Error: No valid Trakt Lists in {values}")
|
||||||
try:
|
|
||||||
self.watchlist(value, is_movie)
|
|
||||||
trakt_values.append(value)
|
|
||||||
except Failed as e:
|
|
||||||
logger.error(e)
|
|
||||||
if len(trakt_values) == 0:
|
|
||||||
raise Failed(f"Trakt Error: No valid Trakt Watchlists in {values}")
|
|
||||||
return trakt_values
|
return trakt_values
|
||||||
|
|
||||||
def get_items(self, method, data, is_movie, status_message=True):
|
def get_items(self, method, data, is_movie, status_message=True):
|
||||||
|
@ -151,6 +154,10 @@ class TraktAPI:
|
||||||
movie_ids, show_ids = self.get_pagenation(method[6:], data, is_movie)
|
movie_ids, show_ids = self.get_pagenation(method[6:], data, is_movie)
|
||||||
if status_message:
|
if status_message:
|
||||||
logger.info(f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}")
|
logger.info(f"Processing {pretty}: {data} {media_type}{'' if data == 1 else 's'}")
|
||||||
|
elif method == "trakt_collection":
|
||||||
|
movie_ids, show_ids = self.get_collection(data, is_movie)
|
||||||
|
if status_message:
|
||||||
|
logger.info(f"Processing {pretty} {media_type}s for {data}")
|
||||||
else:
|
else:
|
||||||
show_ids = []
|
show_ids = []
|
||||||
movie_ids = []
|
movie_ids = []
|
||||||
|
|
|
@ -155,6 +155,7 @@ pretty_names = {
|
||||||
"tmdb_writer": "TMDb Writer",
|
"tmdb_writer": "TMDb Writer",
|
||||||
"tmdb_writer_details": "TMDb Writer",
|
"tmdb_writer_details": "TMDb Writer",
|
||||||
"trakt_collected": "Trakt Collected",
|
"trakt_collected": "Trakt Collected",
|
||||||
|
"trakt_collection": "Trakt Collection",
|
||||||
"trakt_list": "Trakt List",
|
"trakt_list": "Trakt List",
|
||||||
"trakt_list_details": "Trakt List",
|
"trakt_list_details": "Trakt List",
|
||||||
"trakt_popular": "Trakt Popular",
|
"trakt_popular": "Trakt Popular",
|
||||||
|
@ -296,6 +297,7 @@ all_lists = [
|
||||||
"tmdb_writer",
|
"tmdb_writer",
|
||||||
"tmdb_writer_details",
|
"tmdb_writer_details",
|
||||||
"trakt_collected",
|
"trakt_collected",
|
||||||
|
"trakt_collection",
|
||||||
"trakt_list",
|
"trakt_list",
|
||||||
"trakt_list_details",
|
"trakt_list_details",
|
||||||
"trakt_popular",
|
"trakt_popular",
|
||||||
|
|
Loading…
Reference in a new issue