Merge pull request #28 from l3uddz/feat/genre-tag-changes

Feat/genre tag changes
pull/29/head
James 7 years ago committed by GitHub
commit a9bbbfe420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -749,11 +749,7 @@ Options:
--help Show this message and exit. --help Show this message and exit.
``` ```
<<<<<<< HEAD
_Note: This command only works with `-id` or `--show_id` specified (i.e. not with lists), and support both Trakt IDs and IMDB IDs._
=======
_Note: This command only works with `-id` or `--show_id` specified (i.e. not with lists), and supports both Trakt IDs and IMDB IDs._ _Note: This command only works with `-id` or `--show_id` specified (i.e. not with lists), and supports both Trakt IDs and IMDB IDs._
>>>>>>> Readme: minor fixes
### Movies (Multiple Movies) ### Movies (Multiple Movies)
@ -804,11 +800,7 @@ Options:
--help Show this message and exit. --help Show this message and exit.
``` ```
<<<<<<< HEAD
_Note: This command only works with `-id` or `--show_id` specified (i.e. not with lists), and support both Trakt IDs and IMDB IDs._
=======
_Note: This command only works with `-id` or `--show_id` specified (i.e. not with lists), and supports both Trakt IDs and IMDB IDs._ _Note: This command only works with `-id` or `--show_id` specified (i.e. not with lists), and supports both Trakt IDs and IMDB IDs._
>>>>>>> Readme: minor fixes
### Shows (Multiple Shows) ### Shows (Multiple Shows)

@ -44,3 +44,22 @@ def dict_merge(dct, merge_dct):
dct[k] = merge_dct[k] dct[k] = merge_dct[k]
return dct return dct
def unblacklist_genres(genre, blacklisted_genres):
genres = genre.split(',')
for allow_genre in genres:
if allow_genre in blacklisted_genres:
blacklisted_genres.remove(allow_genre)
return
def allowed_genres(genre, object_type, trakt_object):
allowed_object = False
genres = genre.split(',')
for item in genres:
if item.lower() in trakt_object[object_type]['genres']:
allowed_object = True
break
return allowed_object

@ -57,11 +57,14 @@ class Trakt:
@backoff.on_predicate(backoff.expo, lambda x: x is None, max_tries=4, on_backoff=backoff_handler) @backoff.on_predicate(backoff.expo, lambda x: x is None, max_tries=4, on_backoff=backoff_handler)
def _make_items_request(self, url, limit, languages, type_name, object_name, authenticate_user=None, payload={}, def _make_items_request(self, url, limit, languages, type_name, object_name, authenticate_user=None, payload={},
sleep_between=5): sleep_between=5, genres=None):
if languages is None: if not languages:
languages = ['en'] languages = ['en']
payload = dict_merge(payload, {'extended': 'full', 'limit': limit, 'page': 1, 'languages': ','.join(languages)}) payload = dict_merge(payload, {'extended': 'full', 'limit': limit, 'page': 1, 'languages': ','.join(languages)})
if genres:
payload['genres'] = genres
processed = [] processed = []
type_name = type_name.replace('{authenticate_user}', self._user_used_for_authentication(authenticate_user)) type_name = type_name.replace('{authenticate_user}', self._user_used_for_authentication(authenticate_user))
@ -81,7 +84,10 @@ class Trakt:
for item in resp_json: for item in resp_json:
if item not in processed: if item not in processed:
processed.append(item) if object_name.rstrip('s') not in item and 'title' in item:
processed.append({object_name.rstrip('s'): item})
else:
processed.append(item)
# check if we have fetched the last page, break if so # check if we have fetched the last page, break if so
if total_pages == 0: if total_pages == 0:
@ -306,31 +312,34 @@ class Trakt:
object_name='show', object_name='show',
) )
def get_trending_shows(self, limit=1000, languages=None): def get_trending_shows(self, limit=1000, languages=None, genres=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/shows/trending', url='https://api.trakt.tv/shows/trending',
limit=limit, limit=limit,
languages=languages, languages=languages,
object_name='shows', object_name='shows',
type_name='trending', type_name='trending',
genres=genres
) )
def get_popular_shows(self, limit=1000, languages=None): def get_popular_shows(self, limit=1000, languages=None, genres=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/shows/popular', url='https://api.trakt.tv/shows/popular',
limit=limit, limit=limit,
languages=languages, languages=languages,
object_name='shows', object_name='shows',
type_name='popular', type_name='popular',
genres=genres
) )
def get_anticipated_shows(self, limit=1000, languages=None): def get_anticipated_shows(self, limit=1000, languages=None, genres=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/shows/anticipated', url='https://api.trakt.tv/shows/anticipated',
limit=limit, limit=limit,
languages=languages, languages=languages,
object_name='shows', object_name='shows',
type_name='anticipated', type_name='anticipated',
genres=genres
) )
def get_watchlist_shows(self, authenticate_user=None, limit=1000, languages=None): def get_watchlist_shows(self, authenticate_user=None, limit=1000, languages=None):
@ -367,31 +376,34 @@ class Trakt:
object_name='movie', object_name='movie',
) )
def get_trending_movies(self, limit=1000, languages=None): def get_trending_movies(self, limit=1000, languages=None, genres=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/movies/trending', url='https://api.trakt.tv/movies/trending',
limit=limit, limit=limit,
languages=languages, languages=languages,
object_name='movies', object_name='movies',
type_name='trending', type_name='trending',
genres=genres
) )
def get_popular_movies(self, limit=1000, languages=None): def get_popular_movies(self, limit=1000, languages=None, genres=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/movies/popular', url='https://api.trakt.tv/movies/popular',
limit=limit, limit=limit,
languages=languages, languages=languages,
object_name='movies', object_name='movies',
type_name='popular', type_name='popular',
genres=genres
) )
def get_anticipated_movies(self, limit=1000, languages=None): def get_anticipated_movies(self, limit=1000, languages=None, genres=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/movies/anticipated', url='https://api.trakt.tv/movies/anticipated',
limit=limit, limit=limit,
languages=languages, languages=languages,
object_name='movies', object_name='movies',
type_name='anticipated', type_name='anticipated',
genres=genres
) )
def get_boxoffice_movies(self, limit=1000, languages=None): def get_boxoffice_movies(self, limit=1000, languages=None):

@ -60,6 +60,7 @@ class Config(object, metaclass=Singleton):
'blacklisted_genres': [], 'blacklisted_genres': [],
'blacklisted_networks': [], 'blacklisted_networks': [],
'allowed_countries': [], 'allowed_countries': [],
'allowed_languages': [],
'blacklisted_min_runtime': 15, 'blacklisted_min_runtime': 15,
'blacklisted_min_year': 2000, 'blacklisted_min_year': 2000,
'blacklisted_max_year': 2019, 'blacklisted_max_year': 2019,
@ -72,7 +73,8 @@ class Config(object, metaclass=Singleton):
'blacklisted_max_year': 2019, 'blacklisted_max_year': 2019,
'blacklist_title_keywords': [], 'blacklist_title_keywords': [],
'blacklisted_tmdb_ids': [], 'blacklisted_tmdb_ids': [],
'allowed_countries': [] 'allowed_countries': [],
'allowed_languages': []
} }
}, },
'automatic': { 'automatic': {
@ -154,11 +156,6 @@ class Config(object, metaclass=Singleton):
sub_upgraded = False sub_upgraded = False
merged = settings2.copy() merged = settings2.copy()
# print(settings1)
# print(settings2)
# print(overwrite)
# print("_______________")
if isinstance(settings1, dict): if isinstance(settings1, dict):
for k, v in settings1.items(): for k, v in settings1.items():
# missing k # missing k

@ -185,14 +185,15 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
authenticate_user=None): authenticate_user=None):
from media.sonarr import Sonarr from media.sonarr import Sonarr
from media.trakt import Trakt from media.trakt import Trakt
from helpers import misc as misc_helper
from helpers import sonarr as sonarr_helper from helpers import sonarr as sonarr_helper
from helpers import trakt as trakt_helper from helpers import trakt as trakt_helper
added_shows = 0 added_shows = 0
# remove genre from shows blacklisted_genres if supplied # remove genre from shows blacklisted_genres if supplied
if genre and genre in cfg.filters.shows.blacklisted_genres: if genre:
cfg['filters']['shows']['blacklisted_genres'].remove(genre) misc_helper.unblacklist_genres(genre, cfg['filters']['shows']['blacklisted_genres'])
# replace sonarr root_folder if folder is supplied # replace sonarr root_folder if folder is supplied
if folder: if folder:
@ -212,11 +213,11 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
# get trakt series list # get trakt series list
if list_type.lower() == 'anticipated': if list_type.lower() == 'anticipated':
trakt_objects_list = trakt.get_anticipated_shows() trakt_objects_list = trakt.get_anticipated_shows(genres=genre, languages=cfg.filters.shows.allowed_languages)
elif list_type.lower() == 'trending': elif list_type.lower() == 'trending':
trakt_objects_list = trakt.get_trending_shows() trakt_objects_list = trakt.get_trending_shows(genres=genre, languages=cfg.filters.shows.allowed_languages)
elif list_type.lower() == 'popular': elif list_type.lower() == 'popular':
trakt_objects_list = trakt.get_popular_shows() trakt_objects_list = trakt.get_popular_shows(genres=genre, languages=cfg.filters.shows.allowed_languages)
elif list_type.lower() == 'watchlist': elif list_type.lower() == 'watchlist':
trakt_objects_list = trakt.get_watchlist_shows(authenticate_user) trakt_objects_list = trakt.get_watchlist_shows(authenticate_user)
else: else:
@ -254,8 +255,8 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
for series in sorted_series_list: for series in sorted_series_list:
try: try:
# check if genre matches genre supplied via argument # check if genre matches genre supplied via argument
if genre and genre.lower() not in series['show']['genres']: if genre and not misc_helper.allowed_genres(genre, 'show', series):
log.debug("Skipping: %s because it was not from %s genre", series['show']['title'], genre.lower()) log.debug("Skipping: %s because it was not from %s genre(s)", series['show']['title'], genre.lower())
continue continue
# check if series passes out blacklist criteria inspection # check if series passes out blacklist criteria inspection
@ -361,14 +362,15 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se
authenticate_user=None): authenticate_user=None):
from media.radarr import Radarr from media.radarr import Radarr
from media.trakt import Trakt from media.trakt import Trakt
from helpers import misc as misc_helper
from helpers import radarr as radarr_helper from helpers import radarr as radarr_helper
from helpers import trakt as trakt_helper from helpers import trakt as trakt_helper
added_movies = 0 added_movies = 0
# remove genre from movies blacklisted_genres if supplied # remove genre from movies blacklisted_genres if supplied
if genre and genre in cfg.filters.movies.blacklisted_genres: if genre:
cfg['filters']['movies']['blacklisted_genres'].remove(genre) misc_helper.unblacklist_genres(genre, cfg['filters']['movies']['blacklisted_genres'])
# replace radarr root_folder if folder is supplied # replace radarr root_folder if folder is supplied
if folder: if folder:
@ -387,11 +389,11 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se
# get trakt movies list # get trakt movies list
if list_type.lower() == 'anticipated': if list_type.lower() == 'anticipated':
trakt_objects_list = trakt.get_anticipated_movies() trakt_objects_list = trakt.get_anticipated_movies(genres=genre, languages=cfg.filters.movies.allowed_languages)
elif list_type.lower() == 'trending': elif list_type.lower() == 'trending':
trakt_objects_list = trakt.get_trending_movies() trakt_objects_list = trakt.get_trending_movies(genres=genre, languages=cfg.filters.movies.allowed_languages)
elif list_type.lower() == 'popular': elif list_type.lower() == 'popular':
trakt_objects_list = trakt.get_popular_movies() trakt_objects_list = trakt.get_popular_movies(genres=genre, languages=cfg.filters.movies.allowed_languages)
elif list_type.lower() == 'boxoffice': elif list_type.lower() == 'boxoffice':
trakt_objects_list = trakt.get_boxoffice_movies() trakt_objects_list = trakt.get_boxoffice_movies()
elif list_type.lower() == 'watchlist': elif list_type.lower() == 'watchlist':
@ -431,8 +433,8 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se
for movie in sorted_movies_list: for movie in sorted_movies_list:
try: try:
# check if genre matches genre supplied via argument # check if genre matches genre supplied via argument
if genre and genre.lower() not in movie['movie']['genres']: if genre and not misc_helper.allowed_genres(genre, 'movie', movie):
log.debug("Skipping: %s because it was not from %s genre", movie['movie']['title'], genre.lower()) log.debug("Skipping: %s because it was not from %s genre(s)", movie['movie']['title'], genre.lower())
continue continue
# check if movie passes out blacklist criteria inspection # check if movie passes out blacklist criteria inspection

Loading…
Cancel
Save