2015-10-01 23:08:34 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import json as json
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
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 ClientInformation import ClientInformation
|
|
|
|
from LibrarySync import LibrarySync
|
2015-10-01 23:08:34 +10:00
|
|
|
import Utils as utils
|
2015-06-05 20:12:09 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
#################################################################################################
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
class Player( xbmc.Player ):
|
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
# Borg - multiple instances, shared state
|
|
|
|
_shared_state = {}
|
2015-10-01 23:08:34 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
xbmcplayer = xbmc.Player()
|
|
|
|
doUtils = DownloadUtils()
|
|
|
|
clientInfo = ClientInformation()
|
|
|
|
ws = WebSocketThread()
|
2015-10-01 23:08:34 +10:00
|
|
|
librarySync = LibrarySync()
|
2015-04-29 08:23:26 +10:00
|
|
|
|
|
|
|
addonName = clientInfo.getAddonName()
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
played_information = {}
|
|
|
|
playStats = {}
|
2015-10-01 23:08:34 +10:00
|
|
|
currentFile = None
|
|
|
|
stackFiles = None
|
|
|
|
stackElapsed = 0
|
|
|
|
|
|
|
|
def __init__(self, *args):
|
2015-06-08 13:48:28 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
self.__dict__ = self._shared_state
|
2015-10-01 23:08:34 +10:00
|
|
|
self.logMsg("Starting playback monitor.", 2)
|
|
|
|
|
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))
|
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
def GetPlayStats(self):
|
|
|
|
return self.playStats
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
def currentStackItem(self, stackItems):
|
|
|
|
# Only for stacked items - stack://
|
|
|
|
xbmcplayer = self.xbmcplayer
|
|
|
|
|
|
|
|
stack = stackItems.replace("stack://", "").split(" , ")
|
|
|
|
position = xbmcplayer.getTime()
|
|
|
|
totalRuntime = 0
|
|
|
|
|
|
|
|
for item in stack:
|
|
|
|
runtime = int(utils.window("%sruntimeticks" % item)) / 10000000
|
|
|
|
# Verify the position compared to the totalRuntime for stacked items processed in loop so far.
|
|
|
|
if position < (runtime + totalRuntime):
|
|
|
|
self.stackElapsed = totalRuntime
|
|
|
|
self.currentFile = item
|
|
|
|
return item
|
|
|
|
else:
|
|
|
|
totalRuntime += runtime
|
2015-08-06 18:09:45 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
def onPlayBackStarted( self ):
|
|
|
|
# Will be called when xbmc starts playing a file
|
|
|
|
xbmcplayer = self.xbmcplayer
|
|
|
|
self.stopAll()
|
|
|
|
|
|
|
|
# Get current file - if stack://, get currently playing item
|
|
|
|
currentFile = xbmcplayer.getPlayingFile()
|
|
|
|
if "stack://" in currentFile:
|
|
|
|
self.stackFiles = currentFile
|
|
|
|
currentFile = self.currentStackItem(currentFile)
|
|
|
|
else:
|
|
|
|
self.stackFiles = None
|
|
|
|
self.currentFile = currentFile
|
|
|
|
self.stackElapsed = 0
|
|
|
|
|
|
|
|
self.logMsg("ONPLAYBACK_STARTED: %s" % currentFile, 0)
|
|
|
|
|
|
|
|
# We may need to wait for info to be set in kodi monitor
|
|
|
|
itemId = utils.window("%sitem_id" % currentFile)
|
|
|
|
tryCount = 0
|
|
|
|
while not itemId:
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
xbmc.sleep(500)
|
|
|
|
itemId = utils.window("%sitem_id" % currentFile)
|
|
|
|
if tryCount == 20: # try 20 times or about 10 seconds
|
|
|
|
break
|
|
|
|
else: tryCount += 1
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Only proceed if an itemId was found.
|
|
|
|
runtime = utils.window("%sruntimeticks" % currentFile)
|
|
|
|
refresh_id = utils.window("%srefresh_id" % currentFile)
|
|
|
|
playMethod = utils.window("%splaymethod" % currentFile)
|
|
|
|
itemType = utils.window("%stype" % currentFile)
|
|
|
|
mapping = utils.window("%sIndexMapping" % currentFile)
|
|
|
|
seekTime = xbmc.Player().getTime()
|
2015-03-23 16:24:52 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
self.logMsg("Mapping for subtitles index: %s" % mapping, 2)
|
2015-05-16 16:31:08 +10:00
|
|
|
|
2015-10-01 23:08:34 +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('result').get('volume')
|
|
|
|
muted = result.get('result').get('muted')
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
url = "{server}/mediabrowser/Sessions/Playing"
|
|
|
|
postdata = {
|
2015-05-16 16:31:08 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
|
|
|
'PlayMethod': playMethod,
|
|
|
|
'VolumeLevel': volume,
|
|
|
|
'PositionTicks': int(seekTime * 10000000) - int(self.stackElapsed * 10000000),
|
|
|
|
'IsMuted': muted
|
|
|
|
}
|
2015-07-05 01:04:04 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
# Get the current audio track and subtitles
|
|
|
|
if playMethod == "Transcode":
|
|
|
|
# property set in PlayUtils.py
|
|
|
|
postdata['AudioStreamIndex'] = utils.window("%sAudioStreamIndex" % currentFile)
|
|
|
|
postdata['SubtitleStreamIndex'] = utils.window("%sSubtitleStreamIndex" % currentFile)
|
|
|
|
|
|
|
|
else:
|
|
|
|
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-04-08 00:21:54 +10:00
|
|
|
|
2015-10-01 23:08:34 +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', "")
|
|
|
|
|
|
|
|
# Postdata for the audio and subs tracks
|
|
|
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
|
|
|
postdata['AudioStreamIndex'] = indexAudio + 1
|
|
|
|
|
|
|
|
if subsEnabled and len(xbmc.Player().getAvailableSubtitleStreams()) > 0:
|
|
|
|
|
|
|
|
if mapping:
|
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
else: # Direct paths scenario
|
|
|
|
externalIndex = ""
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
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
|
|
|
|
else:
|
|
|
|
postdata['SubtitleStreamIndex'] = ""
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
# Post playback to server
|
|
|
|
self.logMsg("Sending POST play started.", 1)
|
|
|
|
self.doUtils.downloadUrl(url, postBody=postdata, type="POST")
|
|
|
|
|
|
|
|
# save data map for updates and position calls
|
|
|
|
data = {
|
|
|
|
|
|
|
|
'runtime': runtime,
|
|
|
|
'item_id': itemId,
|
|
|
|
'refresh_id': refresh_id,
|
|
|
|
'currentfile': currentFile,
|
|
|
|
'AudioStreamIndex': postdata['AudioStreamIndex'],
|
|
|
|
'SubtitleStreamIndex': postdata['SubtitleStreamIndex'],
|
|
|
|
'playmethod': playMethod,
|
|
|
|
'Type': itemType,
|
|
|
|
'currentPosition': int(seekTime) - int(self.stackElapsed)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.played_information[currentFile] = data
|
|
|
|
self.logMsg("ADDING_FILE: %s" % self.played_information, 1)
|
|
|
|
|
|
|
|
# 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'''
|
|
|
|
|
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-10-01 23:08:34 +10:00
|
|
|
# Get current file
|
|
|
|
currentFile = self.currentFile
|
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-10-01 23:08:34 +10:00
|
|
|
if data:
|
2015-04-29 08:23:26 +10:00
|
|
|
|
|
|
|
# Get playback information
|
2015-10-01 23:08:34 +10:00
|
|
|
itemId = data.get("item_id")
|
2015-03-14 08:24:59 +11:00
|
|
|
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)
|
2015-10-01 23:08:34 +10:00
|
|
|
volume = result.get('result').get('volume')
|
|
|
|
muted = result.get('result').get('muted')
|
2015-05-16 16:31:08 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
postdata = {
|
2015-10-01 23:08:34 +10:00
|
|
|
|
2015-04-29 08:23:26 +10:00
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
2015-10-01 23:08:34 +10:00
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
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:
|
2015-10-01 23:08:34 +10:00
|
|
|
postdata['PositionTicks'] = int(playTime * 10000000) - int(self.stackElapsed * 10000000)
|
|
|
|
|
|
|
|
if playMethod == "Transcode":
|
2015-04-29 08:23:26 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
data['AudioStreamIndex'] = audioindex
|
|
|
|
data['SubtitleStreamIndex'] = subtitleindex
|
|
|
|
|
|
|
|
else:
|
2015-08-06 18:09:45 +10:00
|
|
|
# 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)
|
2015-09-03 14:00:29 +10:00
|
|
|
|
|
|
|
if mapping:
|
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
else: # Direct paths scenario
|
|
|
|
externalIndex = ""
|
|
|
|
|
2015-08-24 20:55:37 +10:00
|
|
|
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
|
|
|
|
|
|
|
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-10-01 23:08:34 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
def onPlayBackPaused( self ):
|
2015-10-01 23:08:34 +10:00
|
|
|
|
|
|
|
currentFile = self.currentFile
|
|
|
|
self.logMsg("PLAYBACK_PAUSED: %s" % currentFile, 2)
|
|
|
|
|
|
|
|
if self.played_information.get(currentFile):
|
|
|
|
self.played_information[currentFile]['paused'] = "true"
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
self.reportPlayback()
|
2015-10-01 23:08:34 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
def onPlayBackResumed( self ):
|
2015-10-01 23:08:34 +10:00
|
|
|
|
|
|
|
currentFile = self.currentFile
|
|
|
|
self.logMsg("PLAYBACK_RESUMED: %s" % currentFile, 2)
|
|
|
|
|
|
|
|
if self.played_information.get(currentFile):
|
|
|
|
self.played_information[currentFile]['paused'] = "false"
|
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
self.reportPlayback()
|
2015-10-01 23:08:34 +10:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
def onPlayBackSeek( self, time, seekOffset ):
|
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
self.logMsg("PLAYBACK_SEEK", 2)
|
2015-04-29 08:23:26 +10:00
|
|
|
xbmcplayer = self.xbmcplayer
|
2015-10-01 23:08:34 +10:00
|
|
|
# Make position when seeking a bit more accurate
|
|
|
|
position = xbmcplayer.getTime()
|
|
|
|
currentFile = self.currentFile
|
2015-04-14 04:56:36 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
if self.played_information.get(currentFile):
|
|
|
|
self.played_information[currentFile]['currentPosition'] = position
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
self.reportPlayback()
|
|
|
|
|
|
|
|
def onPlayBackStopped( self ):
|
|
|
|
# Will be called when user stops xbmc playing a file
|
|
|
|
self.logMsg("ONPLAYBACK_STOPPED", 2)
|
|
|
|
self.stopAll()
|
2015-04-14 04:56:36 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
def onPlayBackEnded( self ):
|
|
|
|
# Will be called when xbmc stops playing a file
|
|
|
|
self.logMsg("ONPLAYBACK_ENDED", 2)
|
|
|
|
self.stopAll()
|
2015-08-06 18:09:45 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
def stopAll(self):
|
2015-09-03 14:00:29 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
if not self.played_information:
|
|
|
|
return
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
self.logMsg("Played_information: %s" % str(self.played_information), 1)
|
|
|
|
# Process each items
|
|
|
|
for item in self.played_information:
|
2015-03-22 14:19:26 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
data = self.played_information.get(item)
|
|
|
|
if data:
|
|
|
|
|
|
|
|
self.logMsg("Item path: %s" % item, 1)
|
|
|
|
self.logMsg("Item data: %s" % str(data), 1)
|
|
|
|
|
|
|
|
runtime = data.get('runtime')
|
|
|
|
currentPosition = data.get('currentPosition')
|
|
|
|
itemId = data.get('item_id')
|
|
|
|
refresh_id = data.get('refresh_id')
|
|
|
|
currentFile = data.get('currentfile')
|
|
|
|
type = data.get('Type')
|
|
|
|
playMethod = data.get('playmethod')
|
2015-08-24 20:55:37 +10:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
if currentPosition and runtime:
|
|
|
|
self.logMsg("RuntimeTicks: %s" % runtime, 1)
|
|
|
|
percentComplete = (currentPosition * 10000000) / int(runtime)
|
|
|
|
markPlayedAt = float(utils.settings('markPlayed')) / 100
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
self.logMsg("Percent complete: %s Mark played at: %s" % (percentComplete, markPlayedAt))
|
|
|
|
if percentComplete < markPlayedAt:
|
|
|
|
# Do not mark as watched for Kodi Monitor
|
|
|
|
utils.window('played_skipWatched', value="true")
|
|
|
|
|
|
|
|
self.stopPlayback(data)
|
|
|
|
offerDelete = False
|
|
|
|
|
|
|
|
if type == "Episode" and utils.settings('offerDeleteTV') == "true":
|
|
|
|
offerDelete = True
|
|
|
|
|
|
|
|
elif type == "Movie" and utils.settings('offerDeleteMovies') == "true":
|
|
|
|
offerDelete = True
|
|
|
|
|
|
|
|
if percentComplete >= markPlayedAt and offerDelete:
|
|
|
|
# Item could be stacked, so only offer to delete the main item.
|
|
|
|
if not self.stackFiles or itemId == utils.window('%sitem_id' % self.stackFiles):
|
|
|
|
return_value = xbmcgui.Dialog().yesno("Offer Delete", "Delete %s" % data.get('currentfile').split("/")[-1], "on Emby Server?")
|
|
|
|
if return_value:
|
|
|
|
# Delete Kodi entry before Emby
|
|
|
|
listItem = [itemId]
|
|
|
|
LibrarySync().removefromDB(listItem, True)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
# Stop transcoding
|
|
|
|
if playMethod == "Transcode":
|
|
|
|
self.logMsg("Transcoding for %s terminated." % itemId, 1)
|
|
|
|
deviceId = self.clientInfo.getMachineId()
|
|
|
|
url = "{server}/mediabrowser/Videos/ActiveEncodings?DeviceId=%s" % deviceId
|
|
|
|
self.doUtils.downloadUrl(url, type="DELETE")
|
|
|
|
|
|
|
|
self.played_information.clear()
|
|
|
|
|
|
|
|
def stopPlayback(self, data):
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
self.logMsg("stopPlayback called", 2)
|
2015-03-22 14:19:26 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
itemId = data.get('item_id')
|
|
|
|
currentPosition = data.get('currentPosition')
|
|
|
|
positionTicks = int(currentPosition * 10000000)
|
2015-03-14 08:24:59 +11:00
|
|
|
|
2015-10-01 23:08:34 +10:00
|
|
|
url = "{server}/mediabrowser/Sessions/Playing/Stopped"
|
|
|
|
postdata = {
|
|
|
|
|
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
|
|
|
'PositionTicks': positionTicks
|
|
|
|
}
|
|
|
|
|
|
|
|
self.doUtils.downloadUrl(url, postBody=postdata, type="POST")
|