Skip to content

Commit

Permalink
Add UpNext play_url support
Browse files Browse the repository at this point in the history
This adds UpNext `play_url` support and removes the old interface.

The aim is to move this functionality to Up Next so it is easier to
integrate with Up Next and offer the best experience in Up Next.
(Without work-arounds in VRT NU)
  • Loading branch information
dagwieers committed Oct 16, 2020
1 parent 877f570 commit d9d2863
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 40 deletions.
6 changes: 1 addition & 5 deletions resources/lib/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,10 @@ def get_upnext(self, info):
runtime=self._metadata.get_duration(next_ep),
)

play_info = dict(
video_id=next_ep.get('videoId'),
)

next_info = dict(
current_episode=current_episode,
next_episode=next_episode,
play_info=play_info,
play_url='plugin://plugin.video.vrt.nu/play/upnext/{video_id}'.format(video_id=next_ep.get('videoId')),
)
return next_info

Expand Down
17 changes: 1 addition & 16 deletions resources/lib/playerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from __future__ import absolute_import, division, unicode_literals
from threading import Event, Thread
from xbmc import getInfoLabel, Player, PlayList
from xbmc import getInfoLabel, Player

from apihelper import ApiHelper
from data import CHANNELS
Expand Down Expand Up @@ -185,21 +185,6 @@ def stream_position(self):
break
self.onPlayerExit()

def add_upnext(self, video_id):
"""Add Up Next url to Kodi Player"""
# Reset vrtnu_resumepoints property
set_property('vrtnu_resumepoints', None)

url = 'plugin://plugin.video.vrt.nu/play/upnext/{video_id}'.format(video_id=video_id)
self.update_position()
self.update_total()
if self.isPlaying() and self.total - self.last_pos < 1:
log(3, '[PlayerInfo {id}] Add {url} to Kodi Playlist', id=self.thread_id, url=url)
PlayList(1).add(url)
else:
log(3, '[PlayerInfo {id}] Add {url} to Kodi Player', id=self.thread_id, url=url)
self.play(url)

def push_upnext(self):
"""Push episode info to Up Next service add-on"""
if has_addon('service.upnext') and get_setting_bool('useupnext', default=True) and self.isPlaying():
Expand Down
19 changes: 0 additions & 19 deletions resources/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from playerinfo import PlayerInfo
from resumepoints import ResumePoints
from tokenresolver import TokenResolver
from utils import to_unicode


class VrtMonitor(Monitor, object): # pylint: disable=useless-object-inheritance
Expand Down Expand Up @@ -44,24 +43,6 @@ def init_watching_activity(self):
else:
self._playerinfo = None

def onNotification(self, sender, method, data): # pylint: disable=invalid-name
"""Handler for notifications"""
# log(2, '[Notification] sender={sender}, method={method}, data={data}', sender=sender, method=method, data=to_unicode(data))

# Handle play_action events from upnextprovider
if sender.startswith('upnextprovider') and method.endswith('plugin.video.vrt.nu_play_action'):
from json import loads
hexdata = loads(data)

if not hexdata:
return

# NOTE: With Python 3.5 and older json.loads() does not support bytes or bytearray, so we convert to unicode
from base64 import b64decode
data = loads(to_unicode(b64decode(hexdata[0])))
log(2, '[Up Next notification] sender={sender}, method={method}, data={data}', sender=sender, method=method, data=to_unicode(data))
self._playerinfo.add_upnext(data.get('video_id'))

def onSettingsChanged(self): # pylint: disable=invalid-name
"""Handler for changes to settings"""

Expand Down

0 comments on commit d9d2863

Please sign in to comment.