Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Trakt Trending List support #70

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in plex_auto_collections.py right after the big title it prints out there's another version number

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also update this.

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,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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tautulli also doesn't support multiple lists

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll update


#### Plex Collection (List Type)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions 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
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