Skip to content

Commit

Permalink
Merge pull request #70 from mza921/trakt_trending
Browse files Browse the repository at this point in the history
Add Trakt Trending List support
  • Loading branch information
mza921 authored Oct 28, 2020
2 parents 2388627 + 97f89f7 commit a6d4d62
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 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)
Expand All @@ -156,8 +157,12 @@ 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](#tautulli-list-list-type)

Note that each list type supports multiple lists.
Note that most list types supports multiple lists, with the following exceptions:
- Trakt Trending List
- Tautulli List

#### Plex Collection (List Type)

Expand Down Expand Up @@ -379,6 +384,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
Expand Down
6 changes: 5 additions & 1 deletion app/plex_auto_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))

Expand Down Expand Up @@ -616,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__))
Expand Down
6 changes: 5 additions & 1 deletion app/plex_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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":
Expand All @@ -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)

Expand Down
37 changes: 24 additions & 13 deletions app/trakt_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions config/config.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a6d4d62

Please sign in to comment.