Skip to content

Commit

Permalink
Fix watchlater (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister authored Jan 21, 2022
1 parent eb4299b commit d9ec71f
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 171 deletions.
12 changes: 6 additions & 6 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ def unfollow(program, title):
Favorites().unfollow(program=program, title=to_unicode(unquote_plus(from_unicode(title))), move_down=move_down)


@plugin.route('/watchlater/<path:url>/<asset_id>/<title>')
def watchlater(asset_id, title, url):
@plugin.route('/watchlater/<episode_id>/<title>')
def watchlater(episode_id, title):
"""The API interface to watch an episode used by the context menu"""
from resumepoints import ResumePoints
ResumePoints().watchlater(asset_id=asset_id, title=to_unicode(unquote_plus(from_unicode(title))), url=url)
ResumePoints().watchlater(episode_id=episode_id, title=to_unicode(unquote_plus(from_unicode(title))))


@plugin.route('/unwatchlater/<path:url>/<asset_id>/<title>')
def unwatchlater(asset_id, title, url):
@plugin.route('/unwatchlater/<episode_id>/<title>')
def unwatchlater(episode_id, title):
"""The API interface to unwatch an episode used by the context menu"""
from resumepoints import ResumePoints
ResumePoints().unwatchlater(asset_id=asset_id, title=to_unicode(unquote_plus(from_unicode(title))), url=url)
ResumePoints().unwatchlater(episode_id=episode_id, title=to_unicode(unquote_plus(from_unicode(title))))


@plugin.route('/favorites')
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ def get_episodes(self, program=None, season=None, episodes=None, category=None,

if variety == 'watchlater':
self._resumepoints.refresh_watchlater(ttl=ttl('direct'))
episode_urls = self._resumepoints.watchlater_urls()
params['facets[url]'] = '[%s]' % (','.join(episode_urls))
episode_ids = self._resumepoints.watchlater_ids()
params['facets[episodeId]'] = '[%s]' % (','.join(episode_ids))

if variety == 'continue':
self._resumepoints.refresh_resumepoints(ttl=ttl('direct'))
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ def get_cached_url_json(url, cache, headers=None, ttl=None, fail=None): # pylin

def refresh_caches(cache_file=None):
"""Invalidate the needed caches and refresh container"""
files = ['favorites.json', 'oneoff.json', 'resume_points.json', 'resume_points_ddt.json']
files = ['favorites.json', 'oneoff.json', 'resume_points.json', 'watchlater.json']
if cache_file and cache_file not in files:
files.append(cache_file)
invalidate_caches(*files)
Expand Down
38 changes: 9 additions & 29 deletions resources/lib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from data import CHANNELS, SECONDS_MARGIN
from kodiutils import colour, get_setting_bool, localize, localize_datelong, log, url_for
from utils import (add_https_proto, assetpath_to_id, capitalize, find_entry, from_unicode,
from utils import (add_https_proto, capitalize, find_entry, from_unicode,
html_to_kodi, reformat_url, reformat_image_url, shorten_link, to_unicode, unescape,
url_to_episode)

Expand Down Expand Up @@ -61,36 +61,36 @@ def get_context_menu(self, api_data, program, cache_file):

# WATCH LATER
if self._resumepoints.is_activated():
asset_id = self.get_asset_id(api_data)
episode_id = api_data.get('episodeId')

# VRT NU Search API
if api_data.get('type') == 'episode':
program_title = api_data.get('program')
title = api_data.get('title')

# VRT NU Schedule API (some are missing vrt.whatson-id)
elif api_data.get('vrt.whatson-id') or api_data.get('startTime'):
program_title = api_data.get('title')
title = api_data.get('title')

if asset_id is not None:
if episode_id is not None:
# We need to ensure forward slashes are quoted
program_title = to_unicode(quote_plus(from_unicode(program_title)))
title = to_unicode(quote_plus(from_unicode(title)))
url = url_to_episode(api_data.get('url', ''))
if self._resumepoints.is_watchlater(asset_id):
if self._resumepoints.is_watchlater(episode_id):
extras = {}
# If we are in a watchlater menu, move cursor down before removing a favorite
if plugin.path.startswith('/resumepoints/watchlater'):
extras = dict(move_down=True)
# Unwatch context menu
context_menu.append((
capitalize(localize(30402)),
'RunPlugin(%s)' % url_for('unwatchlater', asset_id=asset_id, title=program_title, url=url, **extras)
'RunPlugin(%s)' % url_for('unwatchlater', episode_id=episode_id, title=title, url=url, **extras)
))
watchlater_marker = '[COLOR={highlighted}]ᶫ[/COLOR]'
else:
# Watch context menu
context_menu.append((
capitalize(localize(30401)),
'RunPlugin(%s)' % url_for('watchlater', asset_id=asset_id, title=program_title, url=url)
'RunPlugin(%s)' % url_for('watchlater', episode_id=episode_id, title=title, url=url)
))

# FOLLOW PROGRAM
Expand Down Expand Up @@ -150,26 +150,6 @@ def get_context_menu(self, api_data, program, cache_file):

return context_menu, colour(favorite_marker), colour(watchlater_marker)

@staticmethod
def get_asset_id(api_data):
"""Get asset_id from single item json api data"""
asset_id = None

# VRT NU Search API
if api_data.get('type') == 'episode':
asset_id = assetpath_to_id(api_data.get('assetPath'))

# VRT NU Schedule API (some are missing vrt.whatson-id)
elif api_data.get('vrt.whatson-id') or api_data.get('startTime'):
asset_id = assetpath_to_id(api_data.get('assetPath'))

# Fallback to VRT NU website scraping
if not asset_id and api_data.get('url'):
from webscraper import get_asset_id
asset_id = get_asset_id(add_https_proto(api_data.get('url')))

return asset_id

@staticmethod
def get_asset_str(api_data):
"""Get asset_str from single item json api data"""
Expand Down
10 changes: 9 additions & 1 deletion resources/lib/playerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(self):
self.path = None
self.title = None
self.ep_id = None
self.episode_id = None
self.episode_title = None
self.video_id = None
from random import randint
self.thread_id = randint(1, 10001)
Expand All @@ -61,6 +63,8 @@ def onPlayBackStarted(self): # pylint: disable=invalid-name

# Reset episode data
self.video_id = None
self.episode_id = None
self.episode_title = None
self.asset_str = None
self.title = None

Expand All @@ -87,6 +91,8 @@ def onPlayBackStarted(self): # pylint: disable=invalid-name

from metadata import Metadata
self.video_id = episode.get('videoId') or None
self.episode_id = episode.get('episodeId') or None
self.episode_title = episode.get('title') or None
self.asset_str = Metadata(None, None).get_asset_str(episode)
self.title = episode.get('program')

Expand Down Expand Up @@ -282,5 +288,7 @@ def push_position(self, position, total):
title=self.title,
position=position,
total=total,
path=self.path
path=self.path,
episode_id=self.episode_id,
episode_title=self.episode_title
)
Loading

0 comments on commit d9ec71f

Please sign in to comment.