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 Dec 12, 2019
1 parent d7c7fa9 commit a92659e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 37 deletions.
6 changes: 1 addition & 5 deletions resources/lib/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,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/%s' % next_ep.get('videoId'),
)
return next_info

Expand Down
14 changes: 1 addition & 13 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 SECONDS_MARGIN
Expand Down Expand Up @@ -153,18 +153,6 @@ def stream_position(self):
break
self.onThreadExit()

def add_upnext(self, video_id):
''' Add Up Next url to Kodi Player '''
url = 'plugin://plugin.video.vrt.nu/play/upnext/%s' % video_id
self.update_position()
self.update_total()
if self.isPlaying() and self.total - self.last_pos < 1:
log(3, '[PlayerInfo] %d Add %s to Kodi Playlist' % (self.thread_id, url))
PlayList(1).add(url)
else:
log(3, '[PlayerInfo] %d Add %s to Kodi Player' % (self.thread_id, 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('useupnext', 'true') == '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):
Expand Down Expand Up @@ -42,24 +41,6 @@ def init_watching_activity(self):
if not self._apihelper:
self._apihelper = ApiHelper(self._favorites, self._resumepoints)

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 a92659e

Please sign in to comment.