From a52491ac928897e94a530b670e484a02406ef0e0 Mon Sep 17 00:00:00 2001 From: mza921 Date: Tue, 27 Oct 2020 18:01:57 -0700 Subject: [PATCH 1/5] Add Trakt Trending List support --- README.md | 22 ++++++++++++++++++--- app/plex_auto_collections.py | 4 ++++ app/plex_tools.py | 6 +++++- app/trakt_tools.py | 37 +++++++++++++++++++++++------------- config/config.yml.template | 3 +++ 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 9626455..8f616db 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Plex Auto Collections -##### Version 2.1.1 +##### Version 2.2.0 Plex Auto Collections is a Python 3 script that works off a configuration file to create/update Plex collections. Collection management with this tool can be automated in a varying degree of customizability. Supports IMDB, TMDb, and Trakt lists as well as built in Plex filters such as actors, genres, year, studio and more. ![https://i.imgur.com/iHAYFIZ.png](https://i.imgur.com/iHAYFIZ.png) @@ -20,6 +20,7 @@ Plex Auto Collections is a Python 3 script that works off a configuration file t - [TVDb Show (List Type)](#tvdb-show-list-type) - [IMDb List or Search (List Type)](#imdb-list-or-search-list-type) - [Trakt List (List Type)](#trakt-list-list-type) + - [Trakt Trending List (List Type)](#trakt-trending-list-list-type) - [Tautulli List (List Type)](#tautulli-list-list-type) - [Subfilters (Collection Attribute)](#subfilters-collection-attribute) - [Sync Mode (Collection Attribute)](#sync-mode-collection-attribute) @@ -146,7 +147,7 @@ Each collection is defined by the mapping name which becomes the name of the Ple ### List Type (Collection Attribute) -The only required attribute for each collection is the list type. There are eight different list types to choose from: +The only required attribute for the following collections is the list type. There are eight different list types to choose from: - [Plex Collection](#plex-collection-list-type) - [TMDb Collection](#tmdb-collection-list-type) - [TMDb Actor](#tmdb-actor-list-type) @@ -156,8 +157,10 @@ The only required attribute for each collection is the list type. There are eigh - [TVDb Show](#tvdb-show-list-type) - [IMDb List or Search](#imdb-list-or-search-list-type) - [Trakt List](#trakt-list-list-type) +- [Trakt Trending List](#trakt-trending-list-list-type) +- [Tautulli List (List Type)](#tautulli-list-list-type) -Note that each list type supports multiple lists. +Note that each list type supports multiple lists, with the `Trakt Trending List` as the only exception. #### Plex Collection (List Type) @@ -379,6 +382,19 @@ collections: trakt_list: https://trakt.tv/users/jay-greene/lists/reddit-top-250-2019-edition ``` +#### Trakt Trending List (List Type) + +###### Works with Movie and TV Show Libraries + +This script can pull a number of items from the Trakt Trending List for [Movies](https://trakt.tv/movies/trending) or [Shows](https://trakt.tv/shows/trending). The `trakt_trending` attribute only supports a single integer value. The `sync_mode: sync` option is recommended since the list is continuously updated. + +```yaml +collections: + Trending: + trakt_trending: 30 + sync_mode: sync +``` + #### Tautulli List (List Type) ###### Works with Movie and TV Show Libraries diff --git a/app/plex_auto_collections.py b/app/plex_auto_collections.py index 949853a..7d1219c 100644 --- a/app/plex_auto_collections.py +++ b/app/plex_auto_collections.py @@ -123,6 +123,8 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag print("| {} missing movie{} from {} List: {}".format(len(missing), "s" if len(missing) > 1 else "", method_name, v)) elif m == "tmdb_collection": print("| {} missing movie{} from {} Collection: {}".format(len(missing), "s" if len(missing) > 1 else "", method_name, v)) + elif m == "trakt_trending": + print("| {} missing movie{} from {} List: Trending (top {})".format(len(missing), "s" if len(missing) > 1 else "", method_name, v)) else: print("| {} ID: {} missing".format(method_name, v)) if Radarr.valid: @@ -136,6 +138,8 @@ def update_from_config(config_path, plex, headless=False, no_meta=False, no_imag method_name = "Trakt" if "trakt" in m else "TVDb" if "tvdb" in m else "TMDb" if m == "trakt_list" or m == "tmdb_list": print("| {} missing show{} from {} List: {}".format(len(missing), "s" if len(missing) > 1 else "", method_name, v)) + elif m == "trakt_trending": + print("| {} missing show{} from {} List: Trending (top {})".format(len(missing), "s" if len(missing) > 1 else "", method_name, v)) else: print("| {} ID: {} missing".format(method_name, v)) diff --git a/app/plex_tools.py b/app/plex_tools.py index 16faf57..e7304e2 100644 --- a/app/plex_tools.py +++ b/app/plex_tools.py @@ -118,7 +118,7 @@ def add_to_collection(config_path, plex, method, value, c, map, subfilters=None) shows = [] items = [] missing = [] - if (method == "trakt_list" or ("tmdb" in method and plex.library_type == "show")) and not TraktClient.valid: + if ("trakt" in method or ("tmdb" in method and plex.library_type == "show")) and not TraktClient.valid: raise KeyError("| trakt connection required for {}",format(method)) if ("imdb" in method or "tmdb" in method) and not TMDB.valid: raise KeyError("| tmdb connection required for {}",format(method)) @@ -141,6 +141,8 @@ def add_to_collection(config_path, plex, method, value, c, map, subfilters=None) movies, missing = imdb_tools.tmdb_get_movies(config_path, plex, value) elif method == "trakt_list" and TraktClient.valid: movies, missing = trakt_tools.trakt_get_movies(config_path, plex, value) + elif method == "trakt_trending" and TraktClient.valid: + movies, missing = trakt_tools.trakt_get_movies(config_path, plex, value, is_userlist=False) elif method == "tautulli" and Tautulli.valid: movies, missing = imdb_tools.get_tautulli(config_path, plex, value) elif plex.library_type == "show": @@ -161,6 +163,8 @@ def add_to_collection(config_path, plex, method, value, c, map, subfilters=None) shows, missing = imdb_tools.tvdb_get_shows(config_path, plex, value) elif method == "trakt_list" and TraktClient.valid: shows, missing = trakt_tools.trakt_get_shows(config_path, plex, value) + elif method == "trakt_trending" and TraktClient.valid: + shows, missing = trakt_tools.trakt_get_shows(config_path, plex, value, is_userlist=False) elif method == "tautulli" and Tautulli.valid: shows, missing = imdb_tools.get_tautulli(config_path, plex, value) diff --git a/app/trakt_tools.py b/app/trakt_tools.py index f8a6e8a..dc71534 100644 --- a/app/trakt_tools.py +++ b/app/trakt_tools.py @@ -3,16 +3,21 @@ import plex_tools import trakt -def trakt_get_movies(config_path, plex, data): +def trakt_get_movies(config_path, plex, data, is_userlist=True): config_tools.TraktClient(config_path) - trakt_url = data - if trakt_url[-1:] == " ": - trakt_url = trakt_url[:-1] - imdb_map = {} - trakt_list_path = urlparse(trakt_url).path - trakt_list_items = trakt.Trakt[trakt_list_path].items() + if is_userlist: + trakt_url = data + if trakt_url[-1:] == " ": + trakt_url = trakt_url[:-1] + trakt_list_path = urlparse(trakt_url).path + trakt_list_items = trakt.Trakt[trakt_list_path].items() + else: + # Trending list + max_items = int(data) + trakt_list_items = trakt.Trakt['movies'].trending(per_page=max_items) title_ids = [m.pk[1] for m in trakt_list_items if isinstance(m, trakt.objects.movie.Movie)] + imdb_map = {} if title_ids: for item in plex.Library.all(): guid = urlparse(item.guid) @@ -52,14 +57,20 @@ def trakt_get_movies(config_path, plex, data): # No movies return None, None -def trakt_get_shows(config_path, plex, data): +def trakt_get_shows(config_path, plex, data, is_userlist=True): config_tools.TraktClient(config_path) - trakt_url = data - if trakt_url[-1:] == " ": - trakt_url = trakt_url[:-1] + if is_userlist: + trakt_url = data + if trakt_url[-1:] == " ": + trakt_url = trakt_url[:-1] + trakt_list_path = urlparse(trakt_url).path + trakt_list_items = trakt.Trakt[trakt_list_path].items() + else: + # Trending list + max_items = int(data) + trakt_list_items = trakt.Trakt['shows'].trending(per_page=max_items) + tvdb_map = {} - trakt_list_path = urlparse(trakt_url).path - trakt_list_items = trakt.Trakt[trakt_list_path].items() title_ids = [] for m in trakt_list_items: if isinstance(m, trakt.objects.show.Show): diff --git a/config/config.yml.template b/config/config.yml.template index a6c03f9..59ce228 100644 --- a/config/config.yml.template +++ b/config/config.yml.template @@ -24,6 +24,9 @@ collections: Marvel: trakt_list: https://trakt.tv/users/movistapp/lists/marvel collection_mode: show_items + Trakt Trending: + trakt_trending: 30 + sync_mode: sync Pixar: studio: Pixar summary: A collection of Pixar movies From a7900d643b50f37b812675aa67c8608e1ac4bebc Mon Sep 17 00:00:00 2001 From: mza921 Date: Tue, 27 Oct 2020 18:16:06 -0700 Subject: [PATCH 2/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f616db..951bfd2 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Each collection is defined by the mapping name which becomes the name of the Ple ### List Type (Collection Attribute) -The only required attribute for the following collections is the list type. There are eight different list types to choose from: +The only required attribute for each collection is the list type. There are eight different list types to choose from: - [Plex Collection](#plex-collection-list-type) - [TMDb Collection](#tmdb-collection-list-type) - [TMDb Actor](#tmdb-actor-list-type) From ebdc2ae3d8bf1347a333633eab02dc860d775805 Mon Sep 17 00:00:00 2001 From: mza921 Date: Tue, 27 Oct 2020 18:25:00 -0700 Subject: [PATCH 3/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 951bfd2..2352c1a 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Each collection is defined by the mapping name which becomes the name of the Ple ### List Type (Collection Attribute) -The only required attribute for each collection is the list type. There are eight different list types to choose from: +The only required attribute for each collection is the list type. There are eleven different list types to choose from: - [Plex Collection](#plex-collection-list-type) - [TMDb Collection](#tmdb-collection-list-type) - [TMDb Actor](#tmdb-actor-list-type) From 35155753b56f8eaa00134e24bf65f12f2ea0563f Mon Sep 17 00:00:00 2001 From: mza921 Date: Tue, 27 Oct 2020 19:56:33 -0700 Subject: [PATCH 4/5] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2352c1a..4b3d932 100644 --- a/README.md +++ b/README.md @@ -158,9 +158,11 @@ The only required attribute for each collection is the list type. There are elev - [IMDb List or Search](#imdb-list-or-search-list-type) - [Trakt List](#trakt-list-list-type) - [Trakt Trending List](#trakt-trending-list-list-type) -- [Tautulli List (List Type)](#tautulli-list-list-type) +- [Tautulli List](#tautulli-list-list-type) -Note that each list type supports multiple lists, with the `Trakt Trending List` as the only exception. +Note that most list types supports multiple lists, with the following exceptions: +- Trakt Trending List +- Tautulli List #### Plex Collection (List Type) From 97f89f7983f9f6c986e900ddd44fcceb0ea011a0 Mon Sep 17 00:00:00 2001 From: mza921 Date: Tue, 27 Oct 2020 20:11:42 -0700 Subject: [PATCH 5/5] Update version number --- app/plex_auto_collections.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/plex_auto_collections.py b/app/plex_auto_collections.py index 7d1219c..b23a30d 100644 --- a/app/plex_auto_collections.py +++ b/app/plex_auto_collections.py @@ -620,7 +620,7 @@ def append_collection(config_path, config_update=None): print("| |_| |_|\___|/_\_\ /_/ \_\\\\_,_| \__|\___/ \___|\___/|_||_|\___|\__| \__||_|\___/|_||_|/__/ |") print("| |") print("|===================================================================================================|") -print("| Version 2.1.1") +print("| Version 2.2.0") print("| Locating config...") config_path = None app_dir = os.path.dirname(os.path.abspath(__file__))