2015-10-01 13:08:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import json as json
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
2015-04-28 22:23:26 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
from DownloadUtils import DownloadUtils
|
2015-04-18 17:10:06 +00:00
|
|
|
from WebSocketClient import WebSocketThread
|
2015-03-13 21:24:59 +00:00
|
|
|
from ClientInformation import ClientInformation
|
|
|
|
from LibrarySync import LibrarySync
|
2015-10-01 13:08:34 +00:00
|
|
|
import Utils as utils
|
2015-06-05 10:12:09 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
#################################################################################################
|
2015-03-13 21:24:59 +00:00
|
|
|
|
|
|
|
class Player( xbmc.Player ):
|
|
|
|
|
2015-04-28 22:23:26 +00:00
|
|
|
# Borg - multiple instances, shared state
|
|
|
|
_shared_state = {}
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-04-28 22:23:26 +00:00
|
|
|
xbmcplayer = xbmc.Player()
|
|
|
|
doUtils = DownloadUtils()
|
|
|
|
clientInfo = ClientInformation()
|
|
|
|
ws = WebSocketThread()
|
2015-10-01 13:08:34 +00:00
|
|
|
librarySync = LibrarySync()
|
2015-04-28 22:23:26 +00:00
|
|
|
|
|
|
|
addonName = clientInfo.getAddonName()
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
played_information = {}
|
|
|
|
playStats = {}
|
2015-10-01 13:08:34 +00:00
|
|
|
currentFile = None
|
|
|
|
|
|
|
|
def __init__(self, *args):
|
2015-06-08 03:48:28 +00:00
|
|
|
|
2015-04-28 22:23:26 +00:00
|
|
|
self.__dict__ = self._shared_state
|
2015-10-01 13:08:34 +00:00
|
|
|
self.logMsg("Starting playback monitor.", 2)
|
|
|
|
|
2015-04-28 22:23:26 +00:00
|
|
|
def logMsg(self, msg, lvl=1):
|
|
|
|
|
|
|
|
self.className = self.__class__.__name__
|
2015-06-11 08:17:48 +00:00
|
|
|
utils.logMsg("%s %s" % (self.addonName, self.className), msg, int(lvl))
|
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
def GetPlayStats(self):
|
|
|
|
return self.playStats
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
def onPlayBackStarted( self ):
|
|
|
|
# Will be called when xbmc starts playing a file
|
|
|
|
xbmcplayer = self.xbmcplayer
|
|
|
|
self.stopAll()
|
2015-10-13 08:00:32 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
# Get current file
|
|
|
|
try:
|
|
|
|
currentFile = xbmcplayer.getPlayingFile()
|
2015-10-13 08:00:32 +00:00
|
|
|
xbmc.sleep(300)
|
2015-10-11 14:25:10 +00:00
|
|
|
except:
|
|
|
|
currentFile = ""
|
|
|
|
count = 0
|
|
|
|
while not currentFile:
|
|
|
|
xbmc.sleep(100)
|
|
|
|
try:
|
|
|
|
currentFile = xbmcplayer.getPlayingFile()
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
if count == 5: # try 5 times
|
|
|
|
self.logMsg("Cancelling playback report...", 1)
|
|
|
|
break
|
|
|
|
else: count += 1
|
|
|
|
|
|
|
|
|
|
|
|
if currentFile:
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-10-13 08:00:32 +00:00
|
|
|
self.currentFile = currentFile
|
2015-10-11 14:25:10 +00:00
|
|
|
|
|
|
|
# We may need to wait for info to be set in kodi monitor
|
|
|
|
itemId = utils.window("%sitem_id" % currentFile)
|
|
|
|
tryCount = 0
|
|
|
|
while not itemId:
|
|
|
|
|
|
|
|
xbmc.sleep(200)
|
|
|
|
itemId = utils.window("%sitem_id" % currentFile)
|
|
|
|
if tryCount == 20: # try 20 times or about 10 seconds
|
|
|
|
self.logMsg("Could not find itemId, cancelling playback report...", 1)
|
|
|
|
break
|
|
|
|
else: tryCount += 1
|
|
|
|
|
|
|
|
else:
|
2015-10-13 08:00:32 +00:00
|
|
|
self.logMsg("ONPLAYBACK_STARTED: %s ITEMID: %s" % (currentFile, itemId), 0)
|
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
# 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)
|
|
|
|
seekTime = xbmcplayer.getTime()
|
2015-07-04 15:04:04 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
# Get playback volume
|
|
|
|
volume_query = '{"jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["volume","muted"]}, "id": 1}'
|
|
|
|
result = xbmc.executeJSONRPC(volume_query)
|
2015-10-01 13:08:34 +00:00
|
|
|
result = json.loads(result)
|
2015-10-11 14:25:10 +00:00
|
|
|
result = result.get('result')
|
|
|
|
|
|
|
|
volume = result.get('volume')
|
|
|
|
muted = result.get('muted')
|
|
|
|
|
|
|
|
# Postdata structure to send to Emby server
|
|
|
|
url = "{server}/mediabrowser/Sessions/Playing"
|
|
|
|
postdata = {
|
|
|
|
|
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
|
|
|
'PlayMethod': playMethod,
|
|
|
|
'VolumeLevel': volume,
|
2015-10-13 08:00:32 +00:00
|
|
|
'PositionTicks': int(seekTime * 10000000),
|
2015-10-11 14:25:10 +00:00
|
|
|
'IsMuted': muted
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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)
|
2015-04-28 22:23:26 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
else:
|
2015-10-11 14:25:10 +00:00
|
|
|
# Get the current kodi audio and subtitles and convert to Emby equivalent
|
|
|
|
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)
|
|
|
|
result = result.get('result')
|
|
|
|
|
|
|
|
try: # Audio tracks
|
|
|
|
indexAudio = result['currentaudiostream']['index']
|
|
|
|
except KeyError:
|
|
|
|
indexAudio = 0
|
|
|
|
|
|
|
|
try: # Subtitles tracks
|
|
|
|
indexSubs = result['currentsubtitle']['index']
|
|
|
|
except KeyError:
|
|
|
|
indexSubs = 0
|
|
|
|
|
|
|
|
try: # If subtitles are enabled
|
|
|
|
subsEnabled = result['subtitleenabled']
|
|
|
|
except KeyError:
|
|
|
|
subsEnabled = ""
|
|
|
|
|
|
|
|
# Postdata for the audio
|
|
|
|
postdata['AudioStreamIndex'] = indexAudio + 1
|
|
|
|
|
|
|
|
# Postdata for the subtitles
|
|
|
|
if subsEnabled and len(xbmc.Player().getAvailableSubtitleStreams()) > 0:
|
|
|
|
|
|
|
|
# Number of audiotracks to help get Emby Index
|
|
|
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
|
|
|
mapping = utils.window("%sIndexMapping" % currentFile)
|
|
|
|
|
|
|
|
if mapping: # Set in PlaybackUtils.py
|
|
|
|
|
|
|
|
self.logMsg("Mapping for external subtitles index: %s" % mapping, 2)
|
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
|
|
|
|
if externalIndex.get(str(indexSubs)):
|
|
|
|
# If the current subtitle is in the mapping
|
|
|
|
postdata['SubtitleStreamIndex'] = externalIndex[str(indexSubs)]
|
|
|
|
else:
|
|
|
|
# Internal subtitle currently selected
|
|
|
|
postdata['SubtitleStreamIndex'] = indexSubs - len(externalIndex) + audioTracks + 1
|
|
|
|
|
|
|
|
else: # Direct paths enabled scenario or no external subtitles set
|
|
|
|
postdata['SubtitleStreamIndex'] = indexSubs + audioTracks + 1
|
|
|
|
else:
|
|
|
|
postdata['SubtitleStreamIndex'] = ""
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
|
|
|
|
# Post playback to server
|
|
|
|
self.logMsg("Sending POST play started: %s." % postdata, 2)
|
|
|
|
self.doUtils.downloadUrl(url, postBody=postdata, type="POST")
|
|
|
|
|
|
|
|
# Ensure we do have a runtime
|
2015-10-12 16:19:44 +00:00
|
|
|
try:
|
|
|
|
runtime = int(runtime)
|
|
|
|
except ValueError:
|
2015-10-11 14:25:10 +00:00
|
|
|
runtime = xbmcplayer.getTotalTime()
|
|
|
|
self.logMsg("Runtime is missing, grabbing runtime from Kodi player: %s" % runtime, 1)
|
|
|
|
|
|
|
|
# Save data map for updates and position calls
|
|
|
|
data = {
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
'runtime': runtime,
|
|
|
|
'item_id': itemId,
|
|
|
|
'refresh_id': refresh_id,
|
|
|
|
'currentfile': currentFile,
|
|
|
|
'AudioStreamIndex': postdata['AudioStreamIndex'],
|
|
|
|
'SubtitleStreamIndex': postdata['SubtitleStreamIndex'],
|
|
|
|
'playmethod': playMethod,
|
|
|
|
'Type': itemType,
|
2015-10-13 08:00:32 +00:00
|
|
|
'currentPosition': int(seekTime)
|
2015-10-11 14:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-01 13:08:34 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def reportPlayback(self):
|
|
|
|
|
2015-04-28 22:23:26 +00:00
|
|
|
self.logMsg("reportPlayback Called", 2)
|
|
|
|
xbmcplayer = self.xbmcplayer
|
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
# Get current file
|
|
|
|
currentFile = self.currentFile
|
2015-03-13 21:24:59 +00:00
|
|
|
data = self.played_information.get(currentFile)
|
2015-04-28 22:23:26 +00:00
|
|
|
|
2015-03-25 17:37:21 +00:00
|
|
|
# only report playback if emby has initiated the playback (item_id has value)
|
2015-10-01 13:08:34 +00:00
|
|
|
if data:
|
2015-04-28 22:23:26 +00:00
|
|
|
# Get playback information
|
2015-10-11 14:25:10 +00:00
|
|
|
itemId = data['item_id']
|
|
|
|
audioindex = data['AudioStreamIndex']
|
|
|
|
subtitleindex = data['SubtitleStreamIndex']
|
|
|
|
playTime = data['currentPosition']
|
|
|
|
playMethod = data['playmethod']
|
|
|
|
paused = data.get('paused', False)
|
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-05-16 06:31:08 +00: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-11 14:25:10 +00:00
|
|
|
result = result.get('result')
|
|
|
|
|
|
|
|
volume = result.get('volume')
|
|
|
|
muted = result.get('muted')
|
2015-05-16 06:31:08 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
|
|
|
|
# Postdata for the websocketclient report
|
2015-04-28 22:23:26 +00:00
|
|
|
postdata = {
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-04-28 22:23:26 +00:00
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
2015-10-01 13:08:34 +00:00
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
2015-05-16 06:31:08 +00:00
|
|
|
'PlayMethod': playMethod,
|
2015-10-13 08:00:32 +00:00
|
|
|
'PositionTicks': int(playTime * 10000000),
|
2015-04-28 22:23:26 +00:00
|
|
|
'IsPaused': paused,
|
2015-05-16 06:31:08 +00:00
|
|
|
'VolumeLevel': volume,
|
|
|
|
'IsMuted': muted
|
2015-04-28 22:23:26 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
if playMethod == "Transcode":
|
2015-10-11 14:25:10 +00:00
|
|
|
# Track can't be changed, keep reporting the same index
|
|
|
|
postdata['AudioStreamIndex'] = audioindex
|
|
|
|
postdata['AudioStreamIndex'] = subtitleindex
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
else:
|
2015-08-06 08:09:45 +00: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-10-11 14:25:10 +00:00
|
|
|
result = result.get('result')
|
2015-08-24 10:55:37 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
try: # Audio tracks
|
|
|
|
indexAudio = result['currentaudiostream']['index']
|
|
|
|
except KeyError:
|
|
|
|
indexAudio = 0
|
|
|
|
|
|
|
|
try: # Subtitles tracks
|
|
|
|
indexSubs = result['currentsubtitle']['index']
|
|
|
|
except KeyError:
|
|
|
|
indexSubs = 0
|
|
|
|
|
|
|
|
try: # If subtitles are enabled
|
|
|
|
subsEnabled = result['subtitleenabled']
|
|
|
|
except KeyError:
|
|
|
|
subsEnabled = ""
|
|
|
|
|
|
|
|
# Postdata for the audio
|
|
|
|
data['AudioStreamIndex'], postdata['AudioStreamIndex'] = [indexAudio + 1] * 2
|
|
|
|
|
|
|
|
# Postdata for the subtitles
|
2015-08-20 12:27:29 +00:00
|
|
|
if subsEnabled and len(xbmc.Player().getAvailableSubtitleStreams()) > 0:
|
2015-09-03 04:00:29 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
# Number of audiotracks to help get Emby Index
|
|
|
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
|
|
|
mapping = utils.window("%sIndexMapping" % currentFile)
|
|
|
|
|
|
|
|
if mapping: # Set in PlaybackUtils.py
|
|
|
|
|
|
|
|
self.logMsg("Mapping for external subtitles index: %s" % mapping, 2)
|
2015-09-03 04:00:29 +00:00
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
|
2015-08-24 10:55:37 +00:00
|
|
|
if externalIndex.get(str(indexSubs)):
|
|
|
|
# If the current subtitle is in the mapping
|
2015-10-11 14:25:10 +00:00
|
|
|
data['SubtitleStreamIndex'], postdata['SubtitleStreamIndex'] = [externalIndex[str(indexSubs)]] * 2
|
2015-08-24 10:55:37 +00:00
|
|
|
else:
|
|
|
|
# Internal subtitle currently selected
|
2015-10-11 14:25:10 +00:00
|
|
|
data['SubtitleStreamIndex'], postdata['SubtitleStreamIndex'] = [indexSubs - len(externalIndex) + audioTracks + 1] * 2
|
|
|
|
|
|
|
|
else: # Direct paths enabled scenario or no external subtitles set
|
|
|
|
data['SubtitleStreamIndex'], postdata['SubtitleStreamIndex'] = [indexSubs + audioTracks + 1] * 2
|
2015-08-06 08:09:45 +00:00
|
|
|
else:
|
2015-10-11 14:25:10 +00:00
|
|
|
data['SubtitleStreamIndex'], postdata['SubtitleStreamIndex'] = [""] * 2
|
2015-04-28 22:23:26 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
# Report progress via websocketclient
|
2015-04-28 22:23:26 +00:00
|
|
|
postdata = json.dumps(postdata)
|
2015-05-03 06:06:44 +00:00
|
|
|
self.logMsg("Report: %s" % postdata, 2)
|
2015-04-28 22:23:26 +00:00
|
|
|
self.ws.sendProgressUpdate(postdata)
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def onPlayBackPaused( self ):
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
currentFile = self.currentFile
|
|
|
|
self.logMsg("PLAYBACK_PAUSED: %s" % currentFile, 2)
|
|
|
|
|
|
|
|
if self.played_information.get(currentFile):
|
2015-10-11 14:25:10 +00:00
|
|
|
self.played_information[currentFile]['paused'] = True
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
self.reportPlayback()
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def onPlayBackResumed( self ):
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
currentFile = self.currentFile
|
|
|
|
self.logMsg("PLAYBACK_RESUMED: %s" % currentFile, 2)
|
|
|
|
|
|
|
|
if self.played_information.get(currentFile):
|
2015-10-11 14:25:10 +00:00
|
|
|
self.played_information[currentFile]['paused'] = False
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
self.reportPlayback()
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-03-13 21:24:59 +00:00
|
|
|
def onPlayBackSeek( self, time, seekOffset ):
|
2015-10-01 13:08:34 +00:00
|
|
|
# Make position when seeking a bit more accurate
|
|
|
|
currentFile = self.currentFile
|
2015-10-11 14:25:10 +00:00
|
|
|
self.logMsg("PLAYBACK_SEEK: %s" % currentFile, 2)
|
2015-04-13 18:56:36 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
if self.played_information.get(currentFile):
|
2015-10-11 14:25:10 +00:00
|
|
|
position = self.xbmcplayer.getTime()
|
2015-10-01 13:08:34 +00:00
|
|
|
self.played_information[currentFile]['currentPosition'] = position
|
2015-08-24 10:55:37 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
self.reportPlayback()
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
def onPlayBackStopped( self ):
|
|
|
|
# Will be called when user stops xbmc playing a file
|
|
|
|
self.logMsg("ONPLAYBACK_STOPPED", 2)
|
|
|
|
self.stopAll()
|
2015-04-13 18:56:36 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
def onPlayBackEnded( self ):
|
|
|
|
# Will be called when xbmc stops playing a file
|
|
|
|
self.logMsg("ONPLAYBACK_ENDED", 2)
|
|
|
|
self.stopAll()
|
2015-08-06 08:09:45 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
def stopAll(self):
|
2015-09-03 04:00:29 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
if not self.played_information:
|
|
|
|
return
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
self.logMsg("Played_information: %s" % self.played_information, 1)
|
2015-10-01 13:08:34 +00:00
|
|
|
# Process each items
|
|
|
|
for item in self.played_information:
|
2015-03-22 03:19:26 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
data = self.played_information.get(item)
|
|
|
|
if data:
|
|
|
|
|
2015-10-04 11:05:31 +00:00
|
|
|
self.logMsg("Item path: %s" % item, 2)
|
2015-10-11 14:25:10 +00:00
|
|
|
self.logMsg("Item data: %s" % data, 2)
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-11 14:25:10 +00:00
|
|
|
runtime = data['runtime']
|
|
|
|
currentPosition = data['currentPosition']
|
|
|
|
itemId = data['item_id']
|
|
|
|
refresh_id = data['refresh_id']
|
|
|
|
currentFile = data['currentfile']
|
|
|
|
type = data['Type']
|
|
|
|
playMethod = data['playmethod']
|
2015-08-24 10:55:37 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
if currentPosition and runtime:
|
|
|
|
percentComplete = (currentPosition * 10000000) / int(runtime)
|
|
|
|
markPlayedAt = float(utils.settings('markPlayed')) / 100
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-10-04 11:05:31 +00:00
|
|
|
self.logMsg("Percent complete: %s Mark played at: %s" % (percentComplete, markPlayedAt), 1)
|
|
|
|
# Prevent manually mark as watched in Kodi monitor > WriteKodiVideoDB().UpdatePlaycountFromKodi()
|
|
|
|
utils.window('SkipWatched%s' % itemId, "true")
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
self.stopPlayback(data)
|
2015-10-13 10:41:28 +00:00
|
|
|
offerDelete = utils.settings('offerDelete') == "true"
|
|
|
|
offerTypeDelete = False
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
if type == "Episode" and utils.settings('offerDeleteTV') == "true":
|
2015-10-13 10:41:28 +00:00
|
|
|
offerTypeDelete = True
|
2015-10-01 13:08:34 +00:00
|
|
|
|
|
|
|
elif type == "Movie" and utils.settings('offerDeleteMovies') == "true":
|
2015-10-13 10:41:28 +00:00
|
|
|
offerTypeDelete = True
|
2015-10-01 13:08:34 +00:00
|
|
|
|
2015-10-13 10:41:28 +00:00
|
|
|
if percentComplete >= markPlayedAt and offerDelete and offerTypeDelete:
|
|
|
|
# Make the bigger setting be able to disable option easily.
|
2015-10-13 08:00:32 +00:00
|
|
|
self.logMsg("Offering deletion for: %s." % itemId, 1)
|
|
|
|
return_value = xbmcgui.Dialog().yesno("Offer Delete", "Delete %s" % currentFile.split("/")[-1], "on Emby Server?")
|
|
|
|
if return_value:
|
|
|
|
# Delete Kodi entry before Emby
|
|
|
|
listItem = [itemId]
|
|
|
|
LibrarySync().removefromDB(listItem, True)
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-10-01 13:08:34 +00: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-13 21:24:59 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
self.logMsg("stopPlayback called", 2)
|
2015-03-22 03:19:26 +00:00
|
|
|
|
2015-10-04 11:05:31 +00:00
|
|
|
itemId = data['item_id']
|
|
|
|
currentPosition = data['currentPosition']
|
2015-10-01 13:08:34 +00:00
|
|
|
positionTicks = int(currentPosition * 10000000)
|
2015-03-13 21:24:59 +00:00
|
|
|
|
2015-10-01 13:08:34 +00:00
|
|
|
url = "{server}/mediabrowser/Sessions/Playing/Stopped"
|
|
|
|
postdata = {
|
|
|
|
|
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
|
|
|
'PositionTicks': positionTicks
|
|
|
|
}
|
|
|
|
|
|
|
|
self.doUtils.downloadUrl(url, postBody=postdata, type="POST")
|