Skip to content

Commit

Permalink
Merge pull request #73 from mcarlton00/next-episodes
Browse files Browse the repository at this point in the history
Fix next episode dialog
  • Loading branch information
mcarlton00 authored May 30, 2021
2 parents 9adb23b + 2e7737c commit ca5918d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
35 changes: 18 additions & 17 deletions resources/lib/play_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ def play_file(play_info):
data["play_action_type"] = "play"
data["item_type"] = result.get("Type", None)
data["can_delete"] = result.get("CanDelete", False)

# Check for next episodes
if result.get('Type') == 'Episode':
next_episode = get_next_episode(result)
data["next_episode"] = next_episode

home_window.set_property('now_playing', json.dumps(data))

list_item.setPath(playurl)
Expand Down Expand Up @@ -494,10 +500,6 @@ def play_file(play_info):
else:
log.info("PlaybackResumrAction : Playback resumed")

next_episode = get_next_episode(result)
data["next_episode"] = next_episode
send_next_episode_details(result, next_episode)


def __build_label2_from(source):
videos = [item for item in source.get('MediaStreams', {}) if item.get('Type') == "Video"]
Expand Down Expand Up @@ -630,7 +632,7 @@ def send_next_episode_details(item, next_episode):
"force_transcode": False
}
}
send_event_notification("upnext_data", next_info)
send_event_notification("upnext_data", next_info, True)


def set_list_item_props(item_id, list_item, result, server, extra_props, title):
Expand Down Expand Up @@ -1048,6 +1050,10 @@ def stop_all_playback(played_information):


def get_playing_data():
home_window = HomeWindow()
play_data_string = home_window.get_property('now_playing')
play_data = json.loads(play_data_string)

settings = xbmcaddon.Addon()
server = settings.getSetting('server_address')
try:
Expand All @@ -1057,10 +1063,9 @@ def get_playing_data():
return None
log.debug("get_playing_data : getPlayingFile() : {0}".format(playing_file))
if server in playing_file:
url_data = urlparse(playing_file)
query = parse_qs(url_data.query)

return play_data_map.get(playing_file)
return play_data
else:
return {}


class Service(xbmc.Player):
Expand Down Expand Up @@ -1166,24 +1171,20 @@ def onNotification(self, sender, method, data):
home_window.set_property('exit', 'True')
return

if sender[-7:] != '.SIGNAL':
if sender != 'plugin.video.jellycon':
return

signal = method.split('.', 1)[-1]
if signal not in ("jellycon_play_action", "jellycon_play_youtube_trailer_action", "set_view"):
return

data_json = json.loads(data)
message_data = data_json[0]
log.debug("PlaybackService:onNotification:{0}".format(message_data))
decoded_data = base64.b64decode(message_data)
play_info = json.loads(decoded_data)
play_info = data_json[0]
log.debug("PlaybackService:onNotification:{0}".format(play_info))

if signal == "jellycon_play_action":
log.info("Received jellycon_play_action : {0}".format(play_info))
play_file(play_info, self.monitor)
play_file(play_info)
elif signal == "jellycon_play_youtube_trailer_action":
log.info("Received jellycon_play_trailer_action : {0}".format(play_info))
trailer_link = play_info["url"]
xbmc.executebuiltin(trailer_link)
elif signal == "set_view":
Expand Down
14 changes: 13 additions & 1 deletion resources/lib/playnext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import division, absolute_import, print_function, unicode_literals

import json
import os
import threading

Expand All @@ -9,6 +10,7 @@

from .loghandler import LazyLogger
from .play_utils import send_event_notification
from .kodi_utils import HomeWindow

log = LazyLogger(__name__)

Expand All @@ -32,6 +34,8 @@ def run(self):
play_next_triggered = False
is_playing = False

now_playing = None

while not xbmc.Monitor().abortRequested() and not self.stop_thread:

player = xbmc.Player()
Expand All @@ -42,6 +46,13 @@ def run(self):
play_next_trigger_time = int(settings.getSetting('play_next_trigger_time'))
log.debug("New play_next_trigger_time value: {0}".format(play_next_trigger_time))

now_playing_file = player.getPlayingFile()
if now_playing_file != now_playing:
# If the playing file has changed, reset the play next values
play_next_dialog = None
play_next_triggered = False
now_playing = now_playing_file

duration = player.getTotalTime()
position = player.getTime()
trigger_time = play_next_trigger_time # 300
Expand All @@ -51,7 +62,7 @@ def run(self):
play_next_triggered = True
log.debug("play_next_triggered hit at {0} seconds from end".format(time_to_end))

play_data = get_playing_data(self.monitor.played_information)
play_data = get_playing_data()
log.debug("play_next_triggered play_data : {0}".format(play_data))

next_episode = play_data.get("next_episode")
Expand All @@ -78,6 +89,7 @@ def run(self):
play_next_dialog = None

is_playing = False
now_playing = None

if xbmc.Monitor().waitForAbort(1):
break
Expand Down
23 changes: 15 additions & 8 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import xbmc
import xbmcvfs

import binascii
import string
import random
import json
Expand All @@ -14,6 +15,7 @@
from datetime import datetime
import calendar
import re
from six import ensure_text, ensure_binary
from six.moves.urllib.parse import urlencode

from .downloadutils import DownloadUtils
Expand Down Expand Up @@ -295,14 +297,19 @@ def single_urlencode(text):
return text.decode('utf-8') # return the result again as unicode


def send_event_notification(method, data):
message_data = json.dumps(data)
source_id = "jellycon"
base64_data = base64.b64encode(message_data.encode())
escaped_data = '\\"[\\"{0}\\"]\\"'.format(base64_data)
command = 'XBMC.NotifyAll({0}.SIGNAL,{1},{2})'.format(source_id, method, escaped_data)
log.debug("Sending notification event data: {0}".format(command))
xbmc.executebuiltin(command)
def send_event_notification(method, data=None, hexlify=False):
'''
Send events through Kodi's notification system
'''
data = data or {}

if hexlify:
# Used exclusively for the upnext plugin
data = ensure_text(binascii.hexlify(ensure_binary(json.dumps(data))))
sender = 'plugin.video.jellycon'
data = '"[%s]"' % json.dumps(data).replace('"', '\\"')

xbmc.executebuiltin('NotifyAll(%s, %s, %s)' % (sender, method, data))


def datetime_from_string(time_string):
Expand Down
1 change: 1 addition & 0 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
image_server.start()

# set up all the services
monitor = Service()
playback_service = PlaybackService(monitor)

home_window = HomeWindow()
Expand Down

0 comments on commit ca5918d

Please sign in to comment.