Skip to content

Commit

Permalink
[add] trakt_next_episode - 'aired' context (Flexget#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking authored Jan 6, 2019
1 parent b17567c commit 21f6032
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions flexget/plugins/input/next_trakt_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class NextTraktEpisodes(object):
'username': {'type': 'string'},
'account': {'type': 'string'},
'position': {'type': 'string', 'enum': ['last', 'next'], 'default': 'next'},
'context': {'type': 'string', 'enum': ['watched', 'collected'], 'default': 'watched'},
'context': {'type': 'string', 'enum': ['watched', 'collected', 'aired'], 'default': 'watched'},
'list': {'type': 'string'},
'strip_dates': {'type': 'boolean', 'default': False}
},
Expand Down Expand Up @@ -70,7 +70,7 @@ def on_task_input(self, task, config):
if item.get('show'):
if not item['show']['title']:
# Seems we can get entries with a blank show title sometimes
log.warning('Found trakt list show with no series name.')
log.warning('Found trakt list show without series name.')
continue
ids = item['show']['ids']
trakt_id = ids['trakt']
Expand All @@ -87,12 +87,22 @@ def on_task_input(self, task, config):
context = 'collection' if config['context'] == 'collected' else config['context']
entries = []
for trakt_id, fields in listed_series.items():
url = get_api_url('shows', trakt_id, 'progress', context)
if context == 'aired':
url = get_api_url('shows', trakt_id, '{}_episode'.format(config['position']))
else:
url = get_api_url('shows', trakt_id, 'progress', context)
try:
data = session.get(url).json()
response = session.get(url)
if response.status_code == 204:
log.debug('No %s episode for %s', config['position'], fields['series_name'])
continue
data = response.json()
except RequestException as e:
raise plugin.PluginError('An error has occurred looking up: Trakt_id: %s Error: %s' % (trakt_id, e))
if config['position'] == 'next' and data.get('next_episode'):
if context == 'aired':
eps = data['season']
epn = data['number']
elif config['position'] == 'next' and data.get('next_episode'):
# If the next episode is already in the trakt database, we'll get it here
season_number = data['next_episode']['season']
episode_number = data['next_episode']['number']
Expand Down

0 comments on commit 21f6032

Please sign in to comment.