split out get next episode into its own function

add notification event for next episode details
This commit is contained in:
Shaun
2018-01-03 14:42:27 +11:00
parent ea3932d569
commit c757b7ed5b
4 changed files with 99 additions and 48 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.4.17"
version="1.4.18"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.24.0"/>

View File

@@ -2,6 +2,7 @@
import sys
import os
import urllib
import json
import xbmc
import xbmcaddon
@@ -19,7 +20,7 @@ addon_instance = xbmcaddon.Addon(id='plugin.video.embycon')
addon_path = addon_instance.getAddonInfo('path')
PLUGINPATH = xbmc.translatePath(os.path.join(addon_path))
downloadUtils = DownloadUtils()
download_utils = DownloadUtils()
class ItemDetails():
@@ -194,7 +195,7 @@ def extract_item_info(item, gui_options):
person_id = person["Id"]
person_tag = person["PrimaryImageTag"]
if person_tag is not None:
person_thumbnail = downloadUtils.imageUrl(person_id, "Primary", 0, 400, 400, person_tag, server = gui_options["server"])
person_thumbnail = download_utils.imageUrl(person_id, "Primary", 0, 400, 400, person_tag, server = gui_options["server"])
else:
person_thumbnail = ""
person = {"name": person_name, "role": person_role, "thumbnail": person_thumbnail}
@@ -479,3 +480,50 @@ def add_context_menu(item_details, folder):
return commands
def get_next_episode(item):
if item.get("Type", "na") != "Episode":
log.debug("Not an episode, can not get next")
return None
parendId = item.get("ParentId", "na")
item_index = item.get("IndexNumber", -1)
if parendId == "na":
log.debug("No parent id, can not get next")
return None
if item_index == -1:
log.debug("No episode number, can not get next")
return None
url = ( '{server}/emby/Users/{userid}/Items?' +
'?Recursive=true' +
'&ParentId=' + parendId +
'&IsVirtualUnaired=false' +
'&IsMissing=False' +
'&IncludeItemTypes=Episode' +
'&ImageTypeLimit=1' +
'&format=json')
json_data = download_utils.downloadUrl(url)
items_result = json.loads(json_data)
log.debug("get_next_episode, sibling list: {0}", items_result)
if items_result is None:
log.debug("get_next_episode no results")
return None
item_list = items_result.get("Items", [])
for item in item_list:
index = item.get("IndexNumber", -1)
# find the very next episode in the season
if index == item_index + 1:
log.debug("get_next_episode, found next episode: {0}", item)
return item
return None

View File

@@ -1,5 +1,7 @@
# Gnu General Public License - see LICENSE.TXT
import binascii
import xbmc
import xbmcgui
import xbmcaddon
@@ -18,6 +20,7 @@ from kodi_utils import HomeWindow
from translation import i18n
from json_rpc import json_rpc
from datamanager import DataManager
from item_functions import get_next_episode
log = SimpleLogging(__name__)
downloadUtils = DownloadUtils()
@@ -187,6 +190,8 @@ def playFile(play_info):
playlist.add(playurl, list_item)
xbmc.Player().play(playlist)
send_next_episode_details(result)
if seekTime == 0:
return
@@ -208,6 +213,30 @@ def playFile(play_info):
xbmc.sleep(100)
# xbmc.Player().play()
def send_next_episode_details(item):
next_episode = get_next_episode(item)
if next_episode is None:
log.debug("No next episode")
next_info = {
"prev_id": item.get("Id"),
"id": next_episode.get("Id"),
"title": next_episode.get("Name")
}
next_data = json.dumps(next_info)
source_id = "embycon"
signal = "embycon_next_episode"
data = '\\"[\\"{0}\\"]\\"'.format(binascii.hexlify(next_data))
command = 'XBMC.NotifyAll({0}.SIGNAL,{1},{2})'.format(source_id, signal, data)
log.debug("Sending next episode details: {0}", command)
xbmc.executebuiltin(command)
def setListItemProps(id, listItem, result, server, extra_props, title):
# set up item and item info
thumbID = id

View File

@@ -16,6 +16,7 @@ from resources.lib.kodi_utils import HomeWindow
from resources.lib.translation import i18n
from resources.lib.widgets import checkForNewContent
from resources.lib.websocket_client import WebSocketClient
from resources.lib.item_functions import get_next_episode
# clear user and token when logging in
home_window = HomeWindow()
@@ -131,57 +132,30 @@ def promptForStopActions(item_id, current_possition):
if (prompt_next_percentage < 100 and
result.get("Type", "na") == "Episode" and
percenatge_complete > prompt_next_percentage):
parendId = result.get("ParentId", "na")
item_index = result.get("IndexNumber", -1)
if parendId == "na":
log.debug("No parent id, can not prompt for next episode")
return
next_episode = get_next_episode(result)
if item_index == -1:
log.debug("No episode number, can not prompt for next episode")
return
if next_episode is not None:
resp = True
index = next_episode.get("IndexNumber", -1)
if play_prompt:
next_epp_name = "%02d - %s" % (index, next_episode.get("Name", "n/a"))
resp = xbmcgui.Dialog().yesno(i18n("play_next_title"), i18n("play_next_question"), next_epp_name, autoclose=10000)
url = ( '{server}/emby/Users/{userid}/Items?' +
'?Recursive=true' +
'&ParentId=' + parendId +
# '&Filters=IsUnplayed,IsNotFolder' +
'&IsVirtualUnaired=false' +
'&IsMissing=False' +
'&IncludeItemTypes=Episode' +
'&ImageTypeLimit=1' +
'&format=json')
if resp:
next_item_id = next_episode.get("Id")
log.debug("Playing Next Episode: {0}", next_item_id)
jsonData = download_utils.downloadUrl(url)
play_info = {}
play_info["item_id"] = next_item_id
play_info["auto_resume"] = "-1"
play_info["force_transcode"] = False
play_data = json.dumps(play_info)
items_result = json.loads(jsonData)
log.debug("Prompt Next Item Details: {0}", items_result)
# find next episode
item_list = items_result.get("Items", [])
for item in item_list:
index = item.get("IndexNumber", -1)
if index == item_index + 1: # find the very next episode in the season
home_window = HomeWindow()
home_window.setProperty("item_id", next_item_id)
home_window.setProperty("play_item_message", play_data)
resp = True
if play_prompt:
next_epp_name = "%02d - %s" % (index, item.get("Name", "n/a"))
resp = xbmcgui.Dialog().yesno(i18n("play_next_title"), i18n("play_next_question"), next_epp_name, autoclose=10000)
if resp:
next_item_id = item.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
play_data = json.dumps(play_info)
home_window = HomeWindow()
home_window.setProperty("item_id", next_item_id)
home_window.setProperty("play_item_message", play_data)
break
@catch_except()
def stopAll(played_information):