2015-03-14 08:24:59 +11:00
|
|
|
import xbmcaddon
|
|
|
|
import xbmcplugin
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import os
|
|
|
|
import threading
|
|
|
|
import json
|
2015-03-21 07:00:17 +11:00
|
|
|
import inspect
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
import KodiMonitor
|
|
|
|
import Utils as utils
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
from DownloadUtils import DownloadUtils
|
2015-04-19 03:10:06 +10:00
|
|
|
from WebSocketClient import WebSocketThread
|
2015-03-14 08:24:59 +11:00
|
|
|
from PlayUtils import PlayUtils
|
|
|
|
from ClientInformation import ClientInformation
|
|
|
|
from LibrarySync import LibrarySync
|
2015-03-28 12:34:09 +11:00
|
|
|
from PlaybackUtils import PlaybackUtils
|
2015-04-08 00:21:54 +10:00
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
|
|
|
from API import API
|
2015-06-05 20:12:09 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
librarySync = LibrarySync()
|
|
|
|
|
|
|
|
# service class for playback monitoring
|
|
|
|
class Player( xbmc.Player ):
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
# Borg - multiple instances, shared state
|
|
|
|
_shared_state = {}
|
|
|
|
|
|
|
|
xbmcplayer = xbmc.Player()
|
|
|
|
doUtils = DownloadUtils()
|
|
|
|
clientInfo = ClientInformation()
|
|
|
|
ws = WebSocketThread()
|
|
|
|
|
|
|
|
addonName = clientInfo.getAddonName()
|
|
|
|
|
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
logLevel = 0
|
|
|
|
played_information = {}
|
|
|
|
settings = None
|
|
|
|
playStats = {}
|
2015-06-08 13:48:28 +10:00
|
|
|
|
2015-06-11 18:17:48 +10:00
|
|
|
audioPref = "default"
|
|
|
|
subsPref = "default"
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def __init__( self, *args ):
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
self.__dict__ = self._shared_state
|
|
|
|
self.logMsg("Starting playback monitor service", 1)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
def logMsg(self, msg, lvl=1):
|
|
|
|
|
|
|
|
self.className = self.__class__.__name__
|
2015-06-11 18:17:48 +10:00
|
|
|
utils.logMsg("%s %s" % (self.addonName, self.className), msg, int(lvl))
|
|
|
|
|
|
|
|
def setAudioSubsPref(self, audio, subs):
|
|
|
|
self.audioPref = audio
|
|
|
|
self.subsPref = subs
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def hasData(self, data):
|
|
|
|
if(data == None or len(data) == 0 or data == "None"):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def stopAll(self):
|
|
|
|
|
2015-08-06 18:09:45 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
if(len(self.played_information) == 0):
|
|
|
|
return
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("emby Service -> played_information : " + str(self.played_information))
|
2015-05-16 16:31:08 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
for item_url in self.played_information:
|
|
|
|
data = self.played_information.get(item_url)
|
2015-04-29 08:23:26 +10:00
|
|
|
if (data is not None):
|
|
|
|
self.logMsg("emby Service -> item_url : " + item_url)
|
|
|
|
self.logMsg("emby Service -> item_data : " + str(data))
|
2015-05-16 16:31:08 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
runtime = data.get("runtime")
|
|
|
|
currentPosition = data.get("currentPosition")
|
|
|
|
item_id = data.get("item_id")
|
|
|
|
refresh_id = data.get("refresh_id")
|
|
|
|
currentFile = data.get("currentfile")
|
2015-03-20 04:40:29 +11:00
|
|
|
type = data.get("Type")
|
2015-08-06 18:09:45 +10:00
|
|
|
playMethod = data.get('playmethod')
|
2015-03-23 16:24:52 +11:00
|
|
|
|
2015-05-16 16:31:08 +10:00
|
|
|
# Prevent websocket feedback
|
|
|
|
self.WINDOW.setProperty("played_itemId", item_id)
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
if(currentPosition != None and self.hasData(runtime)):
|
|
|
|
runtimeTicks = int(runtime)
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("emby Service -> runtimeticks:" + str(runtimeTicks))
|
2015-03-14 08:24:59 +11:00
|
|
|
percentComplete = (currentPosition * 10000000) / runtimeTicks
|
|
|
|
markPlayedAt = float(90) / 100
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("emby Service -> Percent Complete:" + str(percentComplete) + " Mark Played At:" + str(markPlayedAt))
|
2015-05-16 16:31:08 +10:00
|
|
|
if percentComplete < markPlayedAt:
|
|
|
|
# Do not mark as watched
|
|
|
|
self.WINDOW.setProperty('played_skipWatched', 'true')
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
self.stopPlayback(data)
|
|
|
|
|
2015-07-05 01:04:04 +10:00
|
|
|
offerDelete=False
|
2015-08-14 19:03:12 +10:00
|
|
|
if data.get("Type") == "Episode" and utils.settings("offerDeleteTV")=="true":
|
2015-07-05 01:04:04 +10:00
|
|
|
offerDelete = True
|
2015-08-14 19:03:12 +10:00
|
|
|
elif data.get("Type") == "Movie" and utils.settings("offerDeleteMovies")=="true":
|
2015-07-05 01:04:04 +10:00
|
|
|
offerDelete = True
|
|
|
|
|
|
|
|
if percentComplete > .80 and offerDelete == True:
|
2015-05-09 03:40:36 +10:00
|
|
|
return_value = xbmcgui.Dialog().yesno("Offer Delete", "Delete\n" + data.get("currentfile").split("/")[-1] + "\non Emby Server? ")
|
|
|
|
if return_value:
|
2015-06-28 22:08:06 +10:00
|
|
|
# Delete Kodi entry before Emby
|
|
|
|
listItem = [item_id]
|
|
|
|
LibrarySync().removefromDB(listItem, True)
|
2015-04-08 00:21:54 +10:00
|
|
|
|
2015-08-06 18:09:45 +10:00
|
|
|
# Stop transcoding
|
|
|
|
if playMethod == "Transcode":
|
|
|
|
self.logMsg("Transcoding for %s terminated." % item_id)
|
|
|
|
deviceId = self.clientInfo.getMachineId()
|
|
|
|
url = "{server}/mediabrowser/Videos/ActiveEncodings?DeviceId=%s" % deviceId
|
|
|
|
self.doUtils.downloadUrl(url, type="DELETE")
|
2015-04-08 00:21:54 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
self.played_information.clear()
|
|
|
|
|
|
|
|
def stopPlayback(self, data):
|
2015-04-29 08:23:26 +10:00
|
|
|
|
|
|
|
self.logMsg("stopPlayback called", 2)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
item_id = data.get("item_id")
|
|
|
|
currentPosition = data.get("currentPosition")
|
2015-04-29 08:23:26 +10:00
|
|
|
positionTicks = int(currentPosition * 10000000)
|
|
|
|
|
|
|
|
url = "{server}/mediabrowser/Sessions/Playing/Stopped"
|
2015-04-14 04:56:36 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
postdata = {
|
|
|
|
'ItemId': item_id,
|
|
|
|
'MediaSourceId': item_id,
|
|
|
|
'PositionTicks': positionTicks
|
2015-05-16 16:31:08 +10:00
|
|
|
}
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
self.doUtils.downloadUrl(url, postBody=postdata, type="POST")
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def reportPlayback(self):
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("reportPlayback Called", 2)
|
|
|
|
xbmcplayer = self.xbmcplayer
|
2015-05-04 02:26:04 +10:00
|
|
|
|
|
|
|
if not xbmcplayer.isPlaying():
|
|
|
|
self.logMsg("reportPlayback: Not playing anything so returning", 0)
|
|
|
|
return
|
2015-04-29 08:23:26 +10:00
|
|
|
|
|
|
|
currentFile = xbmcplayer.getPlayingFile()
|
2015-03-14 08:24:59 +11:00
|
|
|
data = self.played_information.get(currentFile)
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-03-26 04:37:21 +11:00
|
|
|
# only report playback if emby has initiated the playback (item_id has value)
|
2015-05-16 16:31:08 +10:00
|
|
|
if data is not None and data.get("item_id") is not None:
|
2015-04-29 08:23:26 +10:00
|
|
|
|
|
|
|
# Get playback information
|
2015-03-14 08:24:59 +11:00
|
|
|
item_id = data.get("item_id")
|
|
|
|
audioindex = data.get("AudioStreamIndex")
|
|
|
|
subtitleindex = data.get("SubtitleStreamIndex")
|
2015-04-29 08:23:26 +10:00
|
|
|
playTime = data.get("currentPosition")
|
2015-03-14 08:24:59 +11:00
|
|
|
playMethod = data.get("playmethod")
|
|
|
|
paused = data.get("paused")
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
if paused is None:
|
|
|
|
paused = False
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-05-16 16:31:08 +10:00
|
|
|
# Get playback volume
|
|
|
|
volume_query = '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume","muted"]}, "id": 1}'
|
|
|
|
result = xbmc.executeJSONRPC(volume_query)
|
|
|
|
result = json.loads(result)
|
|
|
|
volume = result.get(u'result').get(u'volume')
|
|
|
|
muted = result.get(u'result').get(u'muted')
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
postdata = {
|
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
|
|
|
'ItemId': item_id,
|
|
|
|
'MediaSourceId': item_id,
|
2015-05-16 16:31:08 +10:00
|
|
|
'PlayMethod': playMethod,
|
2015-04-29 08:23:26 +10:00
|
|
|
'IsPaused': paused,
|
2015-05-16 16:31:08 +10:00
|
|
|
'VolumeLevel': volume,
|
|
|
|
'IsMuted': muted
|
2015-04-29 08:23:26 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
if playTime:
|
|
|
|
postdata['PositionTicks'] = int(playTime * 10000000)
|
|
|
|
|
2015-08-06 18:09:45 +10:00
|
|
|
if playMethod != "Transcode":
|
|
|
|
# Get current audio and subtitles track
|
|
|
|
track_query = '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": {"playerid":1,"properties": ["currentsubtitle","currentaudiostream","subtitleenabled"]} , "id": 1}'
|
|
|
|
result = xbmc.executeJSONRPC(track_query)
|
|
|
|
result = json.loads(result)
|
2015-08-20 22:27:29 +10:00
|
|
|
# Audio tracks
|
|
|
|
indexAudio = result.get('result', 0)
|
|
|
|
if indexAudio:
|
|
|
|
indexAudio = indexAudio.get('currentaudiostream', {}).get('index', 0)
|
|
|
|
# Subtitles tracks
|
|
|
|
indexSubs = result.get('result', 0)
|
|
|
|
if indexSubs:
|
|
|
|
indexSubs = indexSubs.get('currentsubtitle', {}).get('index', 0)
|
|
|
|
# If subtitles are enabled
|
|
|
|
subsEnabled = result.get('result', "")
|
|
|
|
if subsEnabled:
|
|
|
|
subsEnabled = subsEnabled.get('subtitleenabled', "")
|
2015-08-06 18:09:45 +10:00
|
|
|
|
|
|
|
# Convert back into an Emby index
|
|
|
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
|
|
|
indexAudio = indexAudio + 1
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-08-20 22:27:29 +10:00
|
|
|
if subsEnabled and len(xbmc.Player().getAvailableSubtitleStreams()) > 0:
|
2015-08-24 20:55:37 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
mapping = WINDOW.getProperty("%sIndexMapping" % currentFile)
|
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
if externalIndex:
|
|
|
|
# If there's external subtitles added via PlaybackUtils
|
|
|
|
if externalIndex.get(str(indexSubs)):
|
|
|
|
# If the current subtitle is in the mapping
|
|
|
|
indexSubs = externalIndex[str(indexSubs)]
|
|
|
|
else:
|
|
|
|
# Internal subtitle currently selected
|
|
|
|
external = len(externalIndex)
|
|
|
|
indexSubs = indexSubs - external + audioTracks + 1
|
|
|
|
else:
|
|
|
|
# No external subtitles added via PlayUtils
|
|
|
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
|
|
|
indexSubs = indexSubs + audioTracks + 1
|
2015-08-06 18:09:45 +10:00
|
|
|
else:
|
|
|
|
indexSubs = ""
|
|
|
|
|
|
|
|
if audioindex == indexAudio:
|
|
|
|
postdata['AudioStreamIndex'] = audioindex
|
|
|
|
else:
|
|
|
|
postdata['AudioStreamIndex'] = indexAudio
|
|
|
|
data['AudioStreamIndex'] = indexAudio
|
|
|
|
|
|
|
|
if subtitleindex == indexSubs:
|
|
|
|
postdata['SubtitleStreamIndex'] = subtitleindex
|
|
|
|
else:
|
|
|
|
postdata['SubtitleStreamIndex'] = indexSubs
|
|
|
|
data['SubtitleStreamIndex'] = indexSubs
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-08-06 14:30:33 +10:00
|
|
|
else:
|
2015-08-06 18:09:45 +10:00
|
|
|
data['AudioStreamIndex'] = audioindex
|
|
|
|
data['SubtitleStreamIndex'] = subtitleindex
|
2015-04-29 08:23:26 +10:00
|
|
|
|
|
|
|
postdata = json.dumps(postdata)
|
2015-05-03 16:06:44 +10:00
|
|
|
self.logMsg("Report: %s" % postdata, 2)
|
2015-04-29 08:23:26 +10:00
|
|
|
self.ws.sendProgressUpdate(postdata)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def onPlayBackPaused( self ):
|
|
|
|
currentFile = xbmc.Player().getPlayingFile()
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("PLAYBACK_PAUSED : " + currentFile,2)
|
2015-03-14 08:24:59 +11:00
|
|
|
if(self.played_information.get(currentFile) != None):
|
|
|
|
self.played_information[currentFile]["paused"] = "true"
|
|
|
|
self.reportPlayback()
|
|
|
|
|
|
|
|
def onPlayBackResumed( self ):
|
|
|
|
currentFile = xbmc.Player().getPlayingFile()
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("PLAYBACK_RESUMED : " + currentFile,2)
|
2015-03-14 08:24:59 +11:00
|
|
|
if(self.played_information.get(currentFile) != None):
|
|
|
|
self.played_information[currentFile]["paused"] = "false"
|
|
|
|
self.reportPlayback()
|
|
|
|
|
|
|
|
def onPlayBackSeek( self, time, seekOffset ):
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("PLAYBACK_SEEK",2)
|
2015-05-16 18:52:30 +10:00
|
|
|
# Make position when seeking a bit more accurate
|
|
|
|
try:
|
|
|
|
playTime = xbmc.Player().getTime()
|
|
|
|
currentFile = xbmc.Player().getPlayingFile()
|
|
|
|
if(self.played_information.get(currentFile) != None):
|
|
|
|
self.played_information[currentFile]["currentPosition"] = playTime
|
|
|
|
except: pass
|
2015-05-16 18:47:06 +10:00
|
|
|
self.reportPlayback()
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def onPlayBackStarted( self ):
|
|
|
|
# Will be called when xbmc starts playing a file
|
2015-08-06 18:09:45 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
2015-04-29 08:23:26 +10:00
|
|
|
xbmcplayer = self.xbmcplayer
|
2015-03-14 08:24:59 +11:00
|
|
|
self.stopAll()
|
|
|
|
|
2015-03-23 00:02:38 +11:00
|
|
|
if xbmcplayer.isPlaying():
|
2015-05-03 02:36:06 +10:00
|
|
|
|
|
|
|
currentFile = ""
|
|
|
|
try:
|
|
|
|
currentFile = xbmcplayer.getPlayingFile()
|
|
|
|
except: pass
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("onPlayBackStarted: %s" % currentFile, 0)
|
2015-03-30 21:01:26 +11:00
|
|
|
|
|
|
|
# we may need to wait until the info is available
|
|
|
|
item_id = WINDOW.getProperty(currentFile + "item_id")
|
|
|
|
tryCount = 0
|
|
|
|
while(item_id == None or item_id == ""):
|
|
|
|
xbmc.sleep(500)
|
|
|
|
item_id = WINDOW.getProperty(currentFile + "item_id")
|
|
|
|
tryCount += 1
|
|
|
|
if(tryCount == 20): # try 20 times or about 10 seconds
|
|
|
|
return
|
|
|
|
xbmc.sleep(500)
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
# grab all the info about this item from the stored windows props
|
|
|
|
# only ever use the win props here, use the data map in all other places
|
|
|
|
runtime = WINDOW.getProperty(currentFile + "runtimeticks")
|
|
|
|
refresh_id = WINDOW.getProperty(currentFile + "refresh_id")
|
|
|
|
playMethod = WINDOW.getProperty(currentFile + "playmethod")
|
|
|
|
itemType = WINDOW.getProperty(currentFile + "type")
|
2015-08-24 20:55:37 +10:00
|
|
|
mapping = WINDOW.getProperty("%sIndexMapping" % currentFile)
|
|
|
|
|
|
|
|
self.logMsg("Mapping for index: %s" % mapping)
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-05-25 13:59:57 +10:00
|
|
|
# Get playback volume
|
2015-05-16 16:31:08 +10:00
|
|
|
volume_query = '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume","muted"]}, "id": 1}'
|
|
|
|
result = xbmc.executeJSONRPC(volume_query)
|
|
|
|
result = json.loads(result)
|
|
|
|
volume = result.get(u'result').get(u'volume')
|
2015-05-25 13:59:57 +10:00
|
|
|
muted = result.get(u'result').get(u'muted')
|
2015-07-20 11:35:14 +10:00
|
|
|
|
|
|
|
seekTime = xbmc.Player().getTime()
|
2015-04-14 04:56:36 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
url = "{server}/mediabrowser/Sessions/Playing"
|
|
|
|
postdata = {
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
|
|
|
'ItemId': item_id,
|
|
|
|
'MediaSourceId': item_id,
|
2015-05-16 16:31:08 +10:00
|
|
|
'PlayMethod': playMethod,
|
2015-05-25 13:59:57 +10:00
|
|
|
'VolumeLevel': volume,
|
2015-07-20 14:36:15 +10:00
|
|
|
'PositionTicks': int(seekTime * 10000000),
|
2015-05-25 13:59:57 +10:00
|
|
|
'IsMuted': muted
|
2015-04-29 08:23:26 +10:00
|
|
|
}
|
2015-04-14 04:56:36 +10:00
|
|
|
|
2015-08-06 18:09:45 +10:00
|
|
|
# Get the current audio track and subtitles
|
|
|
|
if playMethod == "Transcode":
|
|
|
|
audioindex = WINDOW.getProperty(currentFile + "AudioStreamIndex")
|
|
|
|
subtitleindex = WINDOW.getProperty(currentFile + "SubtitleStreamIndex")
|
2015-04-29 08:23:26 +10:00
|
|
|
postdata['AudioStreamIndex'] = audioindex
|
|
|
|
postdata['SubtitleStreamIndex'] = subtitleindex
|
2015-08-06 18:09:45 +10:00
|
|
|
|
2015-08-06 14:30:33 +10:00
|
|
|
else:
|
2015-08-06 18:09:45 +10:00
|
|
|
track_query = '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": {"playerid": 1,"properties": ["currentsubtitle","currentaudiostream","subtitleenabled"]} , "id": 1}'
|
|
|
|
result = xbmc.executeJSONRPC(track_query)
|
|
|
|
result = json.loads(result)
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-08-20 22:27:29 +10:00
|
|
|
# Audio tracks
|
|
|
|
indexAudio = result.get('result', 0)
|
|
|
|
if indexAudio:
|
|
|
|
indexAudio = indexAudio.get('currentaudiostream', {}).get('index', 0)
|
|
|
|
# Subtitles tracks
|
|
|
|
indexSubs = result.get('result', 0)
|
|
|
|
if indexSubs:
|
|
|
|
indexSubs = indexSubs.get('currentsubtitle', {}).get('index', 0)
|
|
|
|
# If subtitles are enabled
|
|
|
|
subsEnabled = result.get('result', "")
|
2015-08-06 14:56:47 +10:00
|
|
|
if subsEnabled:
|
2015-08-20 22:27:29 +10:00
|
|
|
subsEnabled = subsEnabled.get('subtitleenabled', "")
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-08-20 22:27:29 +10:00
|
|
|
# Postdata for the audio and subs tracks
|
2015-08-24 20:55:37 +10:00
|
|
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
2015-08-20 22:27:29 +10:00
|
|
|
postdata['AudioStreamIndex'] = indexAudio + 1
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-08-20 22:27:29 +10:00
|
|
|
if subsEnabled and len(xbmc.Player().getAvailableSubtitleStreams()) > 0:
|
2015-08-24 20:55:37 +10:00
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
if externalIndex:
|
|
|
|
# If there's external subtitles added via PlaybackUtils
|
|
|
|
if externalIndex.get(str(indexSubs)):
|
|
|
|
# If the current subtitle is in the mapping
|
|
|
|
postdata['SubtitleStreamIndex'] = externalIndex[str(indexSubs)]
|
|
|
|
else:
|
|
|
|
# Internal subtitle currently selected
|
|
|
|
external = len(externalIndex)
|
|
|
|
postdata['SubtitleStreamIndex'] = indexSubs - external + audioTracks + 1
|
|
|
|
else:
|
|
|
|
# No external subtitles added via PlayUtils
|
|
|
|
postdata['SubtitleStreamIndex'] = indexSubs + audioTracks + 1
|
2015-08-06 14:56:47 +10:00
|
|
|
else:
|
|
|
|
postdata['SubtitleStreamIndex'] = ""
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-05-16 16:31:08 +10:00
|
|
|
# Post playback to server
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("Sending POST play started.", 1)
|
2015-05-16 16:31:08 +10:00
|
|
|
self.doUtils.downloadUrl(url, postBody=postdata, type="POST")
|
2015-03-22 14:19:26 +11:00
|
|
|
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
# save data map for updates and position calls
|
2015-05-16 16:31:08 +10:00
|
|
|
data = {
|
|
|
|
'runtime': runtime,
|
|
|
|
'item_id': item_id,
|
|
|
|
'refresh_id': refresh_id,
|
|
|
|
'currentfile': currentFile,
|
2015-08-06 14:30:33 +10:00
|
|
|
'AudioStreamIndex': postdata['AudioStreamIndex'],
|
|
|
|
'SubtitleStreamIndex': postdata['SubtitleStreamIndex'],
|
2015-05-16 16:31:08 +10:00
|
|
|
'playmethod': playMethod,
|
2015-05-17 05:57:44 +10:00
|
|
|
'Type': itemType,
|
2015-05-17 15:37:53 +10:00
|
|
|
'currentPosition': int(seekTime)
|
2015-05-16 16:31:08 +10:00
|
|
|
}
|
2015-03-23 16:24:52 +11:00
|
|
|
self.played_information[currentFile] = data
|
2015-05-16 16:31:08 +10:00
|
|
|
self.logMsg("ADDING_FILE: %s" % self.played_information, 1)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
# log some playback stats
|
|
|
|
if(itemType != None):
|
|
|
|
if(self.playStats.get(itemType) != None):
|
|
|
|
count = self.playStats.get(itemType) + 1
|
|
|
|
self.playStats[itemType] = count
|
|
|
|
else:
|
|
|
|
self.playStats[itemType] = 1
|
|
|
|
|
|
|
|
if(playMethod != None):
|
|
|
|
if(self.playStats.get(playMethod) != None):
|
|
|
|
count = self.playStats.get(playMethod) + 1
|
|
|
|
self.playStats[playMethod] = count
|
|
|
|
else:
|
|
|
|
self.playStats[playMethod] = 1
|
|
|
|
|
|
|
|
# reset in progress position
|
2015-05-16 16:31:08 +10:00
|
|
|
#self.reportPlayback()
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def GetPlayStats(self):
|
|
|
|
return self.playStats
|
|
|
|
|
|
|
|
def onPlayBackEnded( self ):
|
|
|
|
# Will be called when xbmc stops playing a file
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("onPlayBackEnded", 0)
|
2015-03-22 14:19:26 +11:00
|
|
|
|
|
|
|
#workaround when strm files are launched through the addon - mark watched when finished playing
|
|
|
|
#TODO --> mark watched when 95% is played of the file
|
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
|
|
|
if WINDOW.getProperty("virtualstrm") != "":
|
|
|
|
try:
|
|
|
|
id = WINDOW.getProperty("virtualstrm")
|
|
|
|
type = WINDOW.getProperty("virtualstrmtype")
|
2015-04-29 08:23:26 +10:00
|
|
|
watchedurl = "{server}/mediabrowser/Users/{UserId}/PlayedItems/%s" % id
|
|
|
|
self.doUtils.downloadUrl(watchedurl, postBody="", type="POST")
|
2015-04-18 12:28:39 +10:00
|
|
|
librarySync.updatePlayCount(id)
|
2015-03-22 14:19:26 +11:00
|
|
|
except: pass
|
|
|
|
WINDOW.clearProperty("virtualstrm")
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
self.stopAll()
|
|
|
|
|
|
|
|
def onPlayBackStopped( self ):
|
|
|
|
# Will be called when user stops xbmc playing a file
|
2015-04-29 08:23:26 +10:00
|
|
|
self.logMsg("onPlayBackStopped", 0)
|
2015-08-06 18:09:45 +10:00
|
|
|
self.stopAll()
|