add play next episode prompt when approaching the end of the current episode

This commit is contained in:
faush01 2020-07-01 14:34:27 +10:00
parent 6b9f709092
commit 3e28f5aa7c
6 changed files with 230 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.9.97"
version="1.9.98"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.25.0"/>

View File

@ -167,7 +167,7 @@ msgid "Show load progress"
msgstr ""
msgctxt "#30121"
msgid "On Resume"
msgid "On resume"
msgstr ""
msgctxt "#30125"
@ -1065,3 +1065,11 @@ msgstr ""
msgctxt "#30438"
msgid "Play cinema intros"
msgstr ""
msgctxt "#30439"
msgid "Show play next episode at time left"
msgstr ""
msgctxt "#30440"
msgid "Play next"
msgstr ""

138
resources/lib/playnext.py Normal file
View File

@ -0,0 +1,138 @@
import os
import threading
import xbmc
import xbmcgui
import xbmcaddon
from .simple_logging import SimpleLogging
from .play_utils import get_playing_data, send_event_notification
log = SimpleLogging(__name__)
class PlayNextService(threading.Thread):
stop_thread = False
monitor = None
def __init__(self, play_monitor):
super(PlayNextService, self).__init__()
self.monitor = play_monitor
def run(self):
settings = xbmcaddon.Addon()
play_next_trigger_time = int(settings.getSetting('play_next_trigger_time'))
plugin_path = settings.getAddonInfo('path')
plugin_path_real = xbmc.translatePath(os.path.join(plugin_path))
play_next_dialog = None
play_next_triggered = False
is_playing = False
while not xbmc.Monitor().abortRequested() and not self.stop_thread:
player = xbmc.Player()
if player.isPlaying():
if not is_playing:
play_next_trigger_time = int(settings.getSetting('play_next_trigger_time'))
duration = player.getTotalTime()
position = player.getTime()
trigger_time = play_next_trigger_time # 300
time_to_end = (duration - position)
if not play_next_triggered and (trigger_time > time_to_end) and play_next_dialog is None:
play_next_triggered = True
log.debug("play_next_triggered hit at {0} seconds from end", time_to_end)
play_data = get_playing_data(self.monitor.played_information)
log.debug("play_next_triggered play_data : {0}", play_data)
next_episode = play_data.get("next_episode")
item_type = play_data.get("item_type")
if next_episode is not None and item_type == "Episode":
play_next_dialog = PlayNextDialog("PlayNextDialog.xml", plugin_path_real, "default", "720p")
play_next_dialog.set_episode_info(next_episode)
if play_next_dialog is not None:
play_next_dialog.show()
is_playing = True
else:
play_next_triggered = False
if play_next_dialog is not None:
play_next_dialog.close()
del play_next_dialog
play_next_dialog = None
is_playing = False
if xbmc.Monitor().waitForAbort(1):
break
def stop_servcie(self):
log.debug("PlayNextService Stop Called")
self.stop_thread = True
class PlayNextDialog(xbmcgui.WindowXMLDialog):
action_exitkeys_id = None
episode_info = None
def __init__(self, *args, **kwargs):
log.debug("PlayNextDialog: __init__")
xbmcgui.WindowXML.__init__(self, *args, **kwargs)
def onInit(self):
log.debug("PlayNextDialog: onInit")
self.action_exitkeys_id = [10, 13]
index = self.episode_info.get("IndexNumber", -1)
series_name = self.episode_info.get("SeriesName")
next_epp_name = "Episode %02d - (%s)" % (index, self.episode_info.get("Name", "n/a"))
series_label = self.getControl(3011)
series_label.setLabel(series_name)
series_label = self.getControl(3012)
series_label.setLabel(next_epp_name)
def onFocus(self, control_id):
pass
def doAction(self, action_id):
pass
def onMessage(self, message):
log.debug("PlayNextDialog: onMessage: {0}", message)
def onAction(self, action):
if action.getId() == 10: # ACTION_PREVIOUS_MENU
self.close()
elif action.getId() == 92: # ACTION_NAV_BACK
self.close()
else:
log.debug("PlayNextDialog: onAction: {0}", action.getId())
def onClick(self, control_id):
if control_id == 3013:
log.debug("PlayNextDialog: Play Next Episode")
self.close()
next_item_id = self.episode_info.get("Id")
log.debug("Playing Next Episode: {0}", next_item_id)
play_info = {}
play_info["item_id"] = next_item_id
play_info["auto_resume"] = "-1"
play_info["force_transcode"] = False
send_event_notification("embycon_play_action", play_info)
elif control_id == 3014:
self.close()
def set_episode_info(self, info):
self.episode_info = info

View File

@ -55,6 +55,10 @@
</category>
<category label="30214">
<setting label="30440" type="lsep"/>
<setting type="sep" />
<setting id="play_next_trigger_time" type="slider" label="30439" default="0" range="0,1,180" option="int" visible="true"/>
<setting label="30215" type="lsep"/>
<setting type="sep" />
<setting id="promptPlayNextEpisodePercentage" type="slider" label="30218" default="90" range="5,1,100" option="int" visible="true"/>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<window id="3301" type="dialog">
<defaultcontrol always="true">3013</defaultcontrol>
<zorder>2</zorder>
<coordinates>
<system>1</system>
<left>0</left>
<top>0</top>
</coordinates>
<controls>
<control type="image" id="3010">
<left>0</left>
<top>0</top>
<width>1280</width>
<height>52</height>
<texture border="0" colordiffuse="90FFFFFF">bg.png</texture>
</control>
<control type="label" id="3011">
<left>20</left>
<top>0</top>
<width>390</width>
<height>45</height>
<label></label>
<font>font45_title</font>
<align>left</align>
</control>
<control type="label" id="3012">
<left>390</left>
<top>5</top>
<width>500</width>
<height>35</height>
<label></label>
<font>font14</font>
<align>center</align>
</control>
<control type="button" id="3013">
<left>1020</left>
<top>-8</top>
<width>150</width>
<height>65</height>
<visible>true</visible>
<label>Play Next</label>
<align>center</align>
<texture border="1" colordiffuse="ff161616">white.png</texture>
<font>font12</font>
<onright>3014</onright>
</control>
<control type="button" id="3014">
<left>1140</left>
<top>-8</top>
<width>150</width>
<height>65</height>
<visible>true</visible>
<label>Close</label>
<align>center</align>
<texture border="1" colordiffuse="ff161616">white.png</texture>
<font>font12</font>
<onleft>3013</onleft>
</control>
</controls>
</window>

View File

@ -21,6 +21,7 @@ from resources.lib.library_change_monitor import LibraryChangeMonitor
from resources.lib.datamanager import clear_old_cache_data
from resources.lib.tracking import set_timing_enabled
from resources.lib.image_server import HttpImageServerThread
from resources.lib.playnext import PlayNextService
settings = xbmcaddon.Addon()
@ -86,6 +87,12 @@ websocket_client = WebSocketClient(library_change_monitor)
if remote_control:
websocket_client.start()
play_next_service = None
play_next_trigger_time = int(settings.getSetting('play_next_trigger_time'))
if play_next_trigger_time > 0:
play_next_service = PlayNextService(monitor)
play_next_service.start()
# Start the context menu monitor
context_monitor = None
context_menu = settings.getSetting('override_contextmenu') == "true"
@ -184,6 +191,10 @@ image_server.stop()
# call stop on the library update monitor
library_change_monitor.stop()
# stop the play next episdoe service
if play_next_service:
play_next_service.stop_servcie()
# call stop on the context menu monitor
if context_monitor:
context_monitor.stop_monitor()