Merge pull request #36 from l3uddz/develop

Develop
pull/48/head
James 7 years ago committed by GitHub
commit 71460b8a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -193,6 +193,7 @@ You can repeat this process for as many users as you like.
}, },
"filters": { "filters": {
"movies": { "movies": {
"disabled_for": [],
"allowed_countries": [ "allowed_countries": [
"us", "us",
"gb", "gb",
@ -215,6 +216,7 @@ You can repeat this process for as many users as you like.
"blacklisted_tmdb_ids": [] "blacklisted_tmdb_ids": []
}, },
"shows": { "shows": {
"disabled_for": [],
"allowed_countries": [ "allowed_countries": [
"us", "us",
"gb", "gb",
@ -259,7 +261,8 @@ You can repeat this process for as many users as you like.
"pushover": { "pushover": {
"service": "pushover", "service": "pushover",
"app_token": "", "app_token": "",
"user_token": "" "user_token": "",
"priority": 0
}, },
"slack": { "slack": {
"service": "slack", "service": "slack",
@ -444,6 +447,7 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
```json ```json
"movies": { "movies": {
"disabled_for": [],
"allowed_countries": [ "allowed_countries": [
"us", "us",
"gb", "gb",
@ -466,6 +470,18 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
}, },
``` ```
`disabled_for` - specify for which lists the blacklist must be disabled when running in automatic mode
Example:
```
"disabled_for": [
"anticipated",
"watchlist:user1",
"list:http://url-to-list"
],
```
`allowed_countries` - only add movies from these countries. `allowed_countries` - only add movies from these countries.
`allowed_languages` - only add movies with these languages (default/blank=English). `allowed_languages` - only add movies with these languages (default/blank=English).
@ -530,6 +546,18 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi
} }
``` ```
`disabled_for` - specify for which lists the blacklist must be disabled when running in automatic mode
Example:
```
"disabled_for": [
"anticipated",
"watchlist:user1",
"list:http://url-to-list"
],
```
`allowed_countries` - only add shows from these countries. `allowed_countries` - only add shows from these countries.
`allowed_languages` - only add shows with these languages (default/blank=English). `allowed_languages` - only add shows with these languages (default/blank=English).
@ -564,7 +592,8 @@ Currently, only Pushover and Slack are supported. More will be added later.
"pushover": { "pushover": {
"service": "pushover", "service": "pushover",
"app_token": "", "app_token": "",
"user_token": "" "user_token": "",
"priority": 0
}, },
"slack": { "slack": {
"service": "slack", "service": "slack",
@ -582,6 +611,8 @@ Currently, only Pushover and Slack are supported. More will be added later.
`app_token` and `user_token` - retrieve from Pushover.net. `app_token` and `user_token` - retrieve from Pushover.net.
You can specify a priority for the messages send via Pushover using the `priority` key. It can be any Pushover priority value (https://pushover.net/api#priority).
_Note: The key name (i.e the name right under notifications) can be anything, but the `"service":` must be exactly `"pushover"`._ _Note: The key name (i.e the name right under notifications) can be anything, but the `"service":` must be exactly `"pushover"`._
@ -726,6 +757,7 @@ You can customize how the scheduled traktarr is ran by editing the `traktarr.ser
--no-search Disable search when adding to Sonarr / Radarr. --no-search Disable search when adding to Sonarr / Radarr.
--run-now Do a first run immediately without waiting. --run-now Do a first run immediately without waiting.
--no-notifications Disable notifications. --no-notifications Disable notifications.
--ignore-blacklist Ignores the blacklist when running the command.
--help Show this message and exit. --help Show this message and exit.
``` ```
@ -809,6 +841,7 @@ Options:
-f, --folder TEXT Add movies with this root folder to Radarr. -f, --folder TEXT Add movies with this root folder to Radarr.
--no-search Disable search when adding movies to Radarr. --no-search Disable search when adding movies to Radarr.
--notifications Send notifications. --notifications Send notifications.
--ignore-blacklist Ignores the blacklist when running the command.
--authenticate-user TEXT Specify which user to authenticate with to --authenticate-user TEXT Specify which user to authenticate with to
retrieve Trakt lists. Default: first user in the retrieve Trakt lists. Default: first user in the
config. config.
@ -861,6 +894,7 @@ Options:
-f, --folder TEXT Add shows with this root folder to Sonarr. -f, --folder TEXT Add shows with this root folder to Sonarr.
--no-search Disable search when adding shows to Sonarr. --no-search Disable search when adding shows to Sonarr.
--notifications Send notifications. --notifications Send notifications.
--ignore-blacklist Ignores the blacklist when running the command.
--authenticate-user TEXT Specify which user to authenticate with to --authenticate-user TEXT Specify which user to authenticate with to
retrieve Trakt lists. Default: first user in the retrieve Trakt lists. Default: first user in the
config config

@ -1,3 +1,5 @@
from copy import copy
from misc.log import logger from misc.log import logger
log = logger.get_logger(__name__) log = logger.get_logger(__name__)
@ -63,3 +65,20 @@ def allowed_genres(genre, object_type, trakt_object):
allowed_object = True allowed_object = True
break break
return allowed_object return allowed_object
def sorted_list(original_list, list_type, sort_key, reverse=True):
prepared_list = copy(original_list)
for item in prepared_list:
if not item[list_type][sort_key]:
if sort_key == 'released' or sort_key == 'first_aired':
item[list_type][sort_key] = ""
else:
item[list_type][sort_key] = 0
return sorted(prepared_list, key=lambda k: k[list_type][sort_key], reverse=reverse)
# reference: https://stackoverflow.com/a/16712886
def substring_after(s, delim):
return s.partition(delim)[2]

@ -106,7 +106,10 @@ def blacklisted_show_id(show, blacklisted_ids):
return blacklisted return blacklisted
def is_show_blacklisted(show, blacklist_settings): def is_show_blacklisted(show, blacklist_settings, ignore_blacklist):
if ignore_blacklist:
return False
blacklisted = False blacklisted = False
try: try:
if blacklisted_show_year(show, blacklist_settings.blacklisted_min_year, if blacklisted_show_year(show, blacklist_settings.blacklisted_min_year,
@ -228,7 +231,10 @@ def blacklisted_movie_id(movie, blacklisted_ids):
return blacklisted return blacklisted
def is_movie_blacklisted(movie, blacklist_settings): def is_movie_blacklisted(movie, blacklist_settings, ignore_blacklist):
if ignore_blacklist:
return False
blacklisted = False blacklisted = False
try: try:
if blacklisted_movie_title(movie, blacklist_settings.blacklist_title_keywords): if blacklisted_movie_title(movie, blacklist_settings.blacklist_title_keywords):

@ -11,7 +11,7 @@ log = logger.get_logger(__name__)
class Trakt: class Trakt:
non_user_lists = ['anticipated', 'trending', 'popular', 'boxoffice'] non_user_lists = ['anticipated', 'trending', 'popular', 'boxoffice', 'watched', 'played']
def __init__(self, cfg): def __init__(self, cfg):
self.cfg = cfg self.cfg = cfg
@ -343,6 +343,26 @@ class Trakt:
genres=genres genres=genres
) )
def get_most_played_shows(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/played/%s' % ('weekly' if not most_type else most_type),
limit=limit,
languages=languages,
object_name='shows',
type_name='played',
genres=genres
)
def get_most_watched_shows(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/shows/watched/%s' % ('weekly' if not most_type else most_type),
limit=limit,
languages=languages,
object_name='shows',
type_name='watched',
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):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/users/{authenticate_user}/watchlist/shows', url='https://api.trakt.tv/users/{authenticate_user}/watchlist/shows',
@ -407,6 +427,26 @@ class Trakt:
genres=genres genres=genres
) )
def get_most_played_movies(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/played/%s' % ('weekly' if not most_type else most_type),
limit=limit,
languages=languages,
object_name='movies',
type_name='played',
genres=genres
)
def get_most_watched_movies(self, limit=1000, languages=None, genres=None, most_type=None):
return self._make_items_request(
url='https://api.trakt.tv/movies/watched/%s' % ('weekly' if not most_type else most_type),
limit=limit,
languages=languages,
object_name='movies',
type_name='watched',
genres=genres
)
def get_boxoffice_movies(self, limit=1000, languages=None): def get_boxoffice_movies(self, limit=1000, languages=None):
return self._make_items_request( return self._make_items_request(
url='https://api.trakt.tv/movies/boxoffice', url='https://api.trakt.tv/movies/boxoffice',

@ -57,6 +57,7 @@ class Config(object, metaclass=Singleton):
}, },
'filters': { 'filters': {
'shows': { 'shows': {
'disabled_for': [],
'blacklisted_genres': [], 'blacklisted_genres': [],
'blacklisted_networks': [], 'blacklisted_networks': [],
'allowed_countries': [], 'allowed_countries': [],
@ -67,6 +68,7 @@ class Config(object, metaclass=Singleton):
'blacklisted_tvdb_ids': [], 'blacklisted_tvdb_ids': [],
}, },
'movies': { 'movies': {
'disabled_for': [],
'blacklisted_genres': [], 'blacklisted_genres': [],
'blacklisted_min_runtime': 60, 'blacklisted_min_runtime': 60,
'blacklisted_min_year': 2000, 'blacklisted_min_year': 2000,

@ -8,9 +8,10 @@ log = logger.get_logger(__name__)
class Pushover: class Pushover:
NAME = "Pushover" NAME = "Pushover"
def __init__(self, app_token, user_token): def __init__(self, app_token, user_token, priority=0):
self.app_token = app_token self.app_token = app_token
self.user_token = user_token self.user_token = user_token
self.priority = priority
log.debug("Initialized Pushover notification agent") log.debug("Initialized Pushover notification agent")
def send(self, **kwargs): def send(self, **kwargs):
@ -23,7 +24,8 @@ class Pushover:
payload = { payload = {
'token': self.app_token, 'token': self.app_token,
'user': self.user_token, 'user': self.user_token,
'message': kwargs['message'] 'message': kwargs['message'],
'priority': self.priority,
} }
resp = requests.post('https://api.pushover.net/1/messages.json', data=payload, timeout=30) resp = requests.post('https://api.pushover.net/1/messages.json', data=payload, timeout=30)
return True if resp.status_code == 200 else False return True if resp.status_code == 200 else False

@ -17,7 +17,7 @@ notify = None
# Click # Click
@click.group(help='Add new shows & movies to Sonarr/Radarr from Trakt.') @click.group(help='Add new shows & movies to Sonarr/Radarr from Trakt.')
@click.version_option('1.2.1', prog_name='traktarr') @click.version_option('1.2.2', prog_name='traktarr')
@click.option( @click.option(
'--config', '--config',
envvar='TRAKTARR_CONFIG', envvar='TRAKTARR_CONFIG',
@ -114,7 +114,8 @@ def get_objects(pvr, type, notifications):
if notifications: if notifications:
callback_notify({'event': 'error', 'reason': 'Failure to retrieve %s shows list' % type}) callback_notify({'event': 'error', 'reason': 'Failure to retrieve %s shows list' % type})
exit() exit()
log.info("Retrieved %s shows list, shows found: %d", type, len(objects_list)) objects_type = 'movies' if type.lower() == 'radarr' else 'shows'
log.info("Retrieved %s %s list, %s found: %d", type, objects_type, objects_type, len(objects_list))
return objects_list return objects_list
@ -171,18 +172,21 @@ def show(show_id, folder=None, no_search=False):
@app.command(help='Add multiple shows to Sonarr.') @app.command(help='Add multiple shows to Sonarr.')
@click.option('--list-type', '-t', @click.option('--list-type', '-t',
help='Trakt list to process. For example, anticipated, trending, popular, watchlist or any URL to a list', help='Trakt list to process. For example, anticipated, trending, popular, watched, played, watchlist '
required=True) 'or any URL to a list', required=True)
@click.option('--add-limit', '-l', default=0, help='Limit number of shows added to Sonarr.', show_default=True) @click.option('--add-limit', '-l', default=0, help='Limit number of shows added to Sonarr.', show_default=True)
@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr.', show_default=True) @click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr.', show_default=True)
@click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']),
help='Sort list to process.')
@click.option('--genre', '-g', default=None, help='Only add shows from this genre to Sonarr.') @click.option('--genre', '-g', default=None, help='Only add shows from this genre to Sonarr.')
@click.option('--folder', '-f', default=None, help='Add shows with this root folder to Sonarr.') @click.option('--folder', '-f', default=None, help='Add shows with this root folder to Sonarr.')
@click.option('--no-search', is_flag=True, help='Disable search when adding shows to Sonarr.') @click.option('--no-search', is_flag=True, help='Disable search when adding shows to Sonarr.')
@click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--notifications', is_flag=True, help='Send notifications.')
@click.option('--authenticate-user', @click.option('--authenticate-user',
help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config') help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config')
def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_search=False, notifications=False, @click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.')
authenticate_user=None): def shows(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False,
notifications=False, authenticate_user=None, ignore_blacklist=False):
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 misc as misc_helper
@ -218,6 +222,14 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
trakt_objects_list = trakt.get_trending_shows(genres=genre, languages=cfg.filters.shows.allowed_languages) 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(genres=genre, languages=cfg.filters.shows.allowed_languages) trakt_objects_list = trakt.get_popular_shows(genres=genre, languages=cfg.filters.shows.allowed_languages)
elif list_type.lower().startswith('played'):
most_type = misc_helper.substring_after(list_type.lower(), "_")
trakt_objects_list = trakt.get_most_played_shows(genres=genre, languages=cfg.filters.shows.allowed_languages,
most_type=most_type if most_type else None)
elif list_type.lower().startswith('watched'):
most_type = misc_helper.substring_after(list_type.lower(), "_")
trakt_objects_list = trakt.get_most_watched_shows(genres=genre, languages=cfg.filters.shows.allowed_languages,
most_type=most_type if most_type else None)
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:
@ -239,16 +251,23 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
log.error("Aborting due to failure to remove existing Sonarr shows from retrieved Trakt shows list") log.error("Aborting due to failure to remove existing Sonarr shows from retrieved Trakt shows list")
if notifications: if notifications:
callback_notify({'event': 'abort', 'type': 'shows', 'list_type': list_type, callback_notify({'event': 'abort', 'type': 'shows', 'list_type': list_type,
'reason': 'Failure to remove existing Sonarr shows from retrieved Trakt %s shows list' % list_type 'reason': 'Failure to remove existing Sonarr shows from retrieved Trakt %s shows list'
}) % list_type})
return None return None
else: else:
log.info("Removed existing Sonarr shows from Trakt shows list, shows left to process: %d", log.info("Removed existing Sonarr shows from Trakt shows list, shows left to process: %d",
len(processed_series_list)) len(processed_series_list))
# sort filtered series list by highest votes # sort filtered series list
sorted_series_list = sorted(processed_series_list, key=lambda k: k['show']['votes'], reverse=True) if sort == 'release':
log.info("Sorted shows list to process by highest votes") sorted_series_list = misc_helper.sorted_list(processed_series_list, 'show', 'first_aired')
log.info("Sorted shows list to process by release date")
elif sort == 'rating':
sorted_series_list = misc_helper.sorted_list(processed_series_list, 'show', 'rating')
log.info("Sorted shows list to process by highest rating")
else:
sorted_series_list = misc_helper.sorted_list(processed_series_list, 'show', 'votes')
log.info("Sorted shows list to process by highest votes")
# loop series_list # loop series_list
log.info("Processing list now...") log.info("Processing list now...")
@ -260,7 +279,7 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea
continue continue
# check if series passes out blacklist criteria inspection # check if series passes out blacklist criteria inspection
if not trakt_helper.is_show_blacklisted(series, cfg.filters.shows): if not trakt_helper.is_show_blacklisted(series, cfg.filters.shows, ignore_blacklist):
log.info("Adding: %s | Genres: %s | Network: %s | Country: %s", series['show']['title'], log.info("Adding: %s | Genres: %s | Network: %s | Country: %s", series['show']['title'],
', '.join(series['show']['genres']), series['show']['network'], ', '.join(series['show']['genres']), series['show']['network'],
series['show']['country'].upper()) series['show']['country'].upper())
@ -347,19 +366,22 @@ def movie(movie_id, folder=None, no_search=False):
@app.command(help='Add multiple movies to Radarr.') @app.command(help='Add multiple movies to Radarr.')
@click.option('--list-type', '-t', @click.option('--list-type', '-t',
help='Trakt list to process. For example, anticipated, trending, popular, boxoffice, watchlist ' help='Trakt list to process. For example, anticipated, trending, popular, boxoffice, watched, played, '
'or any URL to a list', 'watchlist or any URL to a list',
required=True) required=True)
@click.option('--add-limit', '-l', default=0, help='Limit number of movies added to Radarr.', show_default=True) @click.option('--add-limit', '-l', default=0, help='Limit number of movies added to Radarr.', show_default=True)
@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Radarr.', show_default=True) @click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Radarr.', show_default=True)
@click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']),
help='Sort list to process.')
@click.option('--genre', '-g', default=None, help='Only add movies from this genre to Radarr.') @click.option('--genre', '-g', default=None, help='Only add movies from this genre to Radarr.')
@click.option('--folder', '-f', default=None, help='Add movies with this root folder to Radarr.') @click.option('--folder', '-f', default=None, help='Add movies with this root folder to Radarr.')
@click.option('--no-search', is_flag=True, help='Disable search when adding movies to Radarr.') @click.option('--no-search', is_flag=True, help='Disable search when adding movies to Radarr.')
@click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--notifications', is_flag=True, help='Send notifications.')
@click.option('--authenticate-user', @click.option('--authenticate-user',
help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config.') help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config.')
def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_search=False, notifications=False, @click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.')
authenticate_user=None): def movies(list_type, add_limit=0, add_delay=2.5, sort='votes', genre=None, folder=None, no_search=False,
notifications=False, authenticate_user=None, ignore_blacklist=False):
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 misc as misc_helper
@ -396,6 +418,14 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se
trakt_objects_list = trakt.get_popular_movies(genres=genre, languages=cfg.filters.movies.allowed_languages) 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().startswith('played'):
most_type = misc_helper.substring_after(list_type.lower(), "_")
trakt_objects_list = trakt.get_most_played_movies(genres=genre, languages=cfg.filters.movies.allowed_languages,
most_type=most_type if most_type else None)
elif list_type.lower().startswith('watched'):
most_type = misc_helper.substring_after(list_type.lower(), "_")
trakt_objects_list = trakt.get_most_watched_movies(genres=genre, languages=cfg.filters.movies.allowed_languages,
most_type=most_type if most_type else None)
elif list_type.lower() == 'watchlist': elif list_type.lower() == 'watchlist':
trakt_objects_list = trakt.get_watchlist_movies(authenticate_user) trakt_objects_list = trakt.get_watchlist_movies(authenticate_user)
else: else:
@ -424,9 +454,16 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se
log.info("Removed existing Radarr movies from Trakt movies list, movies left to process: %d", log.info("Removed existing Radarr movies from Trakt movies list, movies left to process: %d",
len(processed_movies_list)) len(processed_movies_list))
# sort filtered movie list by highest votes # sort filtered movie list
sorted_movies_list = sorted(processed_movies_list, key=lambda k: k['movie']['votes'], reverse=True) if sort == 'release':
log.info("Sorted movie list to process by highest votes") sorted_movies_list = misc_helper.sorted_list(processed_movies_list, 'movie', 'released')
log.info("Sorted movies list to process by release date")
elif sort == 'rating':
sorted_movies_list = misc_helper.sorted_list(processed_movies_list, 'movie', 'rating')
log.info("Sorted movies list to process by highest rating")
else:
sorted_movies_list = misc_helper.sorted_list(processed_movies_list, 'movie', 'votes')
log.info("Sorted movies list to process by highest votes")
# loop movies # loop movies
log.info("Processing list now...") log.info("Processing list now...")
@ -438,7 +475,7 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se
continue continue
# check if movie passes out blacklist criteria inspection # check if movie passes out blacklist criteria inspection
if not trakt_helper.is_movie_blacklisted(movie, cfg.filters.movies): if not trakt_helper.is_movie_blacklisted(movie, cfg.filters.movies, ignore_blacklist):
log.info("Adding: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'], movie['movie']['year'], log.info("Adding: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'], movie['movie']['year'],
', '.join(movie['movie']['genres']), movie['movie']['country'].upper()) ', '.join(movie['movie']['genres']), movie['movie']['country'].upper())
# add movie to radarr # add movie to radarr
@ -499,7 +536,7 @@ def callback_notify(data):
return return
def automatic_shows(add_delay=2.5, no_search=False, notifications=False): def automatic_shows(add_delay=2.5, sort='votes', no_search=False, notifications=False, ignore_blacklist=False):
from media.trakt import Trakt from media.trakt import Trakt
total_shows_added = 0 total_shows_added = 0
@ -512,7 +549,8 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False):
if list_type.lower() == 'interval': if list_type.lower() == 'interval':
continue continue
if list_type.lower() in Trakt.non_user_lists: if list_type.lower() in Trakt.non_user_lists or (
'_' in list_type and list_type.lower().partition("_")[0] in Trakt.non_user_lists):
limit = value limit = value
if limit <= 0: if limit <= 0:
@ -521,10 +559,15 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False):
else: else:
log.info("Adding %d shows from Trakt's %s list", limit, list_type) log.info("Adding %d shows from Trakt's %s list", limit, list_type)
local_ignore_blacklist = ignore_blacklist
if list_type.lower() in cfg.filters.shows.disabled_for:
local_ignore_blacklist = True
# run shows # run shows
added_shows = shows.callback(list_type=list_type, add_limit=limit, added_shows = shows.callback(list_type=list_type, add_limit=limit,
add_delay=add_delay, no_search=no_search, add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications) notifications=notifications, ignore_blacklist=local_ignore_blacklist)
elif list_type.lower() == 'watchlist': elif list_type.lower() == 'watchlist':
for authenticate_user, limit in value.items(): for authenticate_user, limit in value.items():
if limit <= 0: if limit <= 0:
@ -533,10 +576,16 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False):
else: else:
log.info("Adding %d shows from the %s from %s", limit, list_type, authenticate_user) log.info("Adding %d shows from the %s from %s", limit, list_type, authenticate_user)
local_ignore_blacklist = ignore_blacklist
if "watchlist:%s".format(authenticate_user) in cfg.filters.shows.disabled_for:
local_ignore_blacklist = True
# run shows # run shows
added_shows = shows.callback(list_type=list_type, add_limit=limit, added_shows = shows.callback(list_type=list_type, add_limit=limit,
add_delay=add_delay, no_search=no_search, add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications, authenticate_user=authenticate_user) notifications=notifications, authenticate_user=authenticate_user,
ignore_blacklist=local_ignore_blacklist)
elif list_type.lower() == 'lists': elif list_type.lower() == 'lists':
for list, v in value.items(): for list, v in value.items():
if isinstance(v, dict): if isinstance(v, dict):
@ -546,10 +595,16 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False):
authenticate_user = None authenticate_user = None
limit = v limit = v
local_ignore_blacklist = ignore_blacklist
if "list:%s".format(list) in cfg.filters.shows.disabled_for:
local_ignore_blacklist = True
# run shows # run shows
added_shows = shows.callback(list_type=list, add_limit=limit, added_shows = shows.callback(list_type=list, add_limit=limit,
add_delay=add_delay, no_search=no_search, add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications, authenticate_user=authenticate_user) notifications=notifications, authenticate_user=authenticate_user,
ignore_blacklist=local_ignore_blacklist)
if added_shows is None: if added_shows is None:
log.error("Failed adding shows from Trakt's %s list", list_type) log.error("Failed adding shows from Trakt's %s list", list_type)
@ -570,7 +625,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False):
return return
def automatic_movies(add_delay=2.5, no_search=False, notifications=False): def automatic_movies(add_delay=2.5, sort='votes', no_search=False, notifications=False, ignore_blacklist=False):
from media.trakt import Trakt from media.trakt import Trakt
total_movies_added = 0 total_movies_added = 0
@ -583,7 +638,8 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False):
if list_type.lower() == 'interval': if list_type.lower() == 'interval':
continue continue
if list_type.lower() in Trakt.non_user_lists: if list_type.lower() in Trakt.non_user_lists or (
'_' in list_type and list_type.lower().partition("_")[0] in Trakt.non_user_lists):
limit = value limit = value
if limit <= 0: if limit <= 0:
@ -592,9 +648,14 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False):
else: else:
log.info("Adding %d movies from Trakt's %s list", limit, list_type) log.info("Adding %d movies from Trakt's %s list", limit, list_type)
local_ignore_blacklist = ignore_blacklist
if list_type.lower() in cfg.filters.movies.disabled_for:
local_ignore_blacklist = True
# run movies # run movies
added_movies = movies.callback(list_type=list_type, add_limit=limit, added_movies = movies.callback(list_type=list_type, add_limit=limit,
add_delay=add_delay, no_search=no_search, add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications) notifications=notifications)
elif list_type.lower() == 'watchlist': elif list_type.lower() == 'watchlist':
for authenticate_user, limit in value.items(): for authenticate_user, limit in value.items():
@ -604,10 +665,16 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False):
else: else:
log.info("Adding %d movies from the %s from %s", limit, list_type, authenticate_user) log.info("Adding %d movies from the %s from %s", limit, list_type, authenticate_user)
local_ignore_blacklist = ignore_blacklist
if "watchlist:%s".format(authenticate_user) in cfg.filters.movies.disabled_for:
local_ignore_blacklist = True
# run movies # run movies
added_movies = movies.callback(list_type=list_type, add_limit=limit, added_movies = movies.callback(list_type=list_type, add_limit=limit,
add_delay=add_delay, no_search=no_search, add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications, authenticate_user=authenticate_user) notifications=notifications, authenticate_user=authenticate_user,
ignore_blacklist=local_ignore_blacklist)
elif list_type.lower() == 'lists': elif list_type.lower() == 'lists':
for list, v in value.items(): for list, v in value.items():
if isinstance(v, dict): if isinstance(v, dict):
@ -617,10 +684,16 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False):
authenticate_user = None authenticate_user = None
limit = v limit = v
local_ignore_blacklist = ignore_blacklist
if "list:%s".format(list) in cfg.filters.movies.disabled_for:
local_ignore_blacklist = True
# run shows # run shows
added_movies = movies.callback(list_type=list, add_limit=limit, added_movies = movies.callback(list_type=list, add_limit=limit,
add_delay=add_delay, no_search=no_search, add_delay=add_delay, sort=sort, no_search=no_search,
notifications=notifications, authenticate_user=authenticate_user) notifications=notifications, authenticate_user=authenticate_user,
ignore_blacklist=local_ignore_blacklist)
if added_movies is None: if added_movies is None:
log.error("Failed adding movies from Trakt's %s list", list_type) log.error("Failed adding movies from Trakt's %s list", list_type)
@ -644,10 +717,13 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False):
@app.command(help='Run in automatic mode.') @app.command(help='Run in automatic mode.')
@click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr / Radarr.', @click.option('--add-delay', '-d', default=2.5, help='Seconds between each add request to Sonarr / Radarr.',
show_default=True) show_default=True)
@click.option('--sort', '-s', default='votes', type=click.Choice(['votes', 'rating', 'release']),
help='Sort list to process.')
@click.option('--no-search', is_flag=True, help='Disable search when adding to Sonarr / Radarr.') @click.option('--no-search', is_flag=True, help='Disable search when adding to Sonarr / Radarr.')
@click.option('--run-now', is_flag=True, help="Do a first run immediately without waiting.") @click.option('--run-now', is_flag=True, help="Do a first run immediately without waiting.")
@click.option('--no-notifications', is_flag=True, help="Disable notifications.") @click.option('--no-notifications', is_flag=True, help="Disable notifications.")
def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): @click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.')
def run(add_delay=2.5, sort='votes', no_search=False, run_now=False, no_notifications=False, ignore_blacklist=False):
log.info("Automatic mode is now running...") log.info("Automatic mode is now running...")
# Add tasks to schedule and do first run if enabled # Add tasks to schedule and do first run if enabled
@ -655,25 +731,32 @@ def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False):
movie_schedule = schedule.every(cfg.automatic.movies.interval).hours.do( movie_schedule = schedule.every(cfg.automatic.movies.interval).hours.do(
automatic_movies, automatic_movies,
add_delay, add_delay,
sort,
no_search, no_search,
not no_notifications not no_notifications,
ignore_blacklist
) )
if run_now: if run_now:
movie_schedule.run() movie_schedule.run()
# Sleep between tasks # Sleep between tasks
time.sleep(add_delay) time.sleep(add_delay)
if cfg.automatic.shows.interval: if cfg.automatic.shows.interval:
shows_schedule = schedule.every(cfg.automatic.shows.interval).hours.do( shows_schedule = schedule.every(cfg.automatic.shows.interval).hours.do(
automatic_shows, automatic_shows,
add_delay, add_delay,
sort,
no_search, no_search,
not no_notifications not no_notifications,
ignore_blacklist
) )
if run_now: if run_now:
shows_schedule.run() shows_schedule.run()
# Sleep between tasks
time.sleep(add_delay)
# Enter running schedule # Enter running schedule
while True: while True:
try: try:

Loading…
Cancel
Save