Add play session id

This commit is contained in:
Shaun Faulds
2017-11-14 19:11:25 +11:00
parent 7d1e0f39df
commit 7199726109
3 changed files with 24 additions and 8 deletions

View File

@@ -7,11 +7,12 @@ import xbmcaddon
from datetime import timedelta
import time
import json
import hashlib
from simple_logging import SimpleLogging
from downloadutils import DownloadUtils
from resume_dialog import ResumeDialog
from utils import PlayUtils, getArt
from utils import PlayUtils, getArt, id_generator
from kodi_utils import HomeWindow
from translation import i18n
from json_rpc import json_rpc
@@ -81,6 +82,8 @@ def playFile(play_info):
listitem_props = []
playurl = None
play_session_id = id_generator()
log.debug("play_session_id: %s" % play_session_id)
# check if strm file, path will contain contain strm contents
if result.get('MediaSources'):
@@ -89,7 +92,7 @@ def playFile(play_info):
playurl, listitem_props = PlayUtils().getStrmDetails(result)
if not playurl:
playurl, playback_type = PlayUtils().getPlayUrl(id, result, force_transcode)
playurl, playback_type = PlayUtils().getPlayUrl(id, result, force_transcode, play_session_id)
log.debug("Play URL: " + playurl + " ListItem Properties: " + str(listitem_props))
@@ -101,6 +104,7 @@ def playFile(play_info):
home_window = HomeWindow()
home_window.setProperty("PlaybackType_" + id, playback_type_string)
home_window.setProperty("PlaySessionId_" + id, play_session_id)
# add the playback type into the overview
if result.get("Overview", None) is not None:

View File

@@ -2,6 +2,8 @@
import xbmcaddon
import re
import encodings
import string
import random
from downloadutils import DownloadUtils
from simple_logging import SimpleLogging
@@ -14,7 +16,7 @@ log = SimpleLogging(__name__)
###########################################################################
class PlayUtils():
def getPlayUrl(self, id, result, force_transcode):
def getPlayUrl(self, id, result, force_transcode, play_session_id):
log.debug("getPlayUrl")
addonSettings = xbmcaddon.Addon(id='plugin.video.embycon')
playback_type = addonSettings.getSetting("playback_type")
@@ -23,6 +25,7 @@ class PlayUtils():
if force_transcode:
log.debug("playback_type: FORCED_TRANSCODE")
playurl = None
log.debug("play_session_id: " + play_session_id)
is_h265 = False
streams = result.get("MediaStreams", [])
@@ -58,8 +61,8 @@ class PlayUtils():
user_token = downloadUtils.authenticate()
playurl = (
"%s/emby/Videos/%s/master.m3u8?MediaSourceId=%s&VideoCodec=h264&AudioCodec=ac3&MaxAudioChannels=6&deviceId=%s&VideoBitrate=%s"
% (server, id, id, deviceId, bitrate))
"%s/emby/Videos/%s/master.m3u8?MediaSourceId=%s&PlaySessionId=%s&VideoCodec=h264&AudioCodec=ac3&MaxAudioChannels=6&deviceId=%s&VideoBitrate=%s&DeviceId=%s"
% (server, id, id, play_session_id, deviceId, bitrate))
playurl = playurl + "&maxWidth=" + playback_max_width
@@ -91,7 +94,7 @@ class PlayUtils():
# do direct http streaming playback
elif playback_type == "1":
playurl = "%s/emby/Videos/%s/stream?static=true" % (server, id)
playurl = "%s/emby/Videos/%s/stream?static=true&PlaySessionId=%s" % (server, id, play_session_id)
user_token = downloadUtils.authenticate()
playurl = playurl + "&api_key=" + user_token
@@ -220,3 +223,7 @@ def getArt(item, server, widget=False):
art['discart'] = downloadUtils.getArtwork(item, "Disc", server=server)
return art
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))

View File

@@ -57,6 +57,7 @@ def sendProgress():
ticks = int(play_time * 10000000)
paused = play_data.get("paused", False)
playback_type = play_data.get("playback_type")
play_session_id = play_data.get("play_session_id")
postdata = {
'QueueableMediaTypes': "Video",
@@ -66,7 +67,8 @@ def sendProgress():
'PositionTicks': ticks,
'IsPaused': paused,
'IsMuted': False,
'PlayMethod': playback_type
'PlayMethod': playback_type,
'PlaySessionId': play_session_id
}
log.debug("Sending POST progress started: %s." % postdata)
@@ -227,6 +229,7 @@ class Service(xbmc.Player):
home_window = HomeWindow()
emby_item_id = home_window.getProperty("item_id")
playback_type = home_window.getProperty("PlaybackType_" + emby_item_id)
play_session_id = home_window.getProperty("PlaySessionId_" + emby_item_id)
# if we could not find the ID of the current item then return
if emby_item_id is None or len(emby_item_id) == 0:
@@ -238,7 +241,8 @@ class Service(xbmc.Player):
'CanSeek': True,
'ItemId': emby_item_id,
'MediaSourceId': emby_item_id,
'PlayMethod': playback_type
'PlayMethod': playback_type,
'PlaySessionId': play_session_id
}
log.debug("Sending POST play started: %s." % postdata)
@@ -250,6 +254,7 @@ class Service(xbmc.Player):
data["item_id"] = emby_item_id
data["paused"] = False
data["playback_type"] = playback_type
data["play_session_id"] = play_session_id
self.played_information[current_playing_file] = data
log.debug("ADDING_FILE : " + current_playing_file)