2015-12-25 07:07:00 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
###############################################################################
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
|
|
|
|
import utils
|
|
|
|
import clientinfo
|
|
|
|
import downloadutils
|
2016-05-17 02:19:05 +10:00
|
|
|
import embydb_functions as embydb
|
|
|
|
import kodidb_functions as kodidb
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-01-12 23:57:26 +11:00
|
|
|
from urllib import urlencode
|
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
###############################################################################
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
|
2016-01-27 03:20:13 +11:00
|
|
|
@utils.logging
|
2015-12-25 07:07:00 +11:00
|
|
|
class Player(xbmc.Player):
|
|
|
|
|
|
|
|
# Borg - multiple instances, shared state
|
|
|
|
_shared_state = {}
|
|
|
|
|
|
|
|
played_info = {}
|
|
|
|
playStats = {}
|
|
|
|
currentFile = None
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
self.__dict__ = self._shared_state
|
|
|
|
|
|
|
|
self.clientInfo = clientinfo.ClientInfo()
|
2016-02-17 19:13:37 +11:00
|
|
|
self.doUtils = downloadutils.DownloadUtils().downloadUrl
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-07-22 23:54:03 +10:00
|
|
|
xbmc.Player.__init__(self)
|
|
|
|
|
|
|
|
self.logMsg("Started playback monitor.", 2)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
def GetPlayStats(self):
|
|
|
|
return self.playStats
|
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
def onPlayBackStarted(self):
|
2016-03-17 03:02:22 +11:00
|
|
|
"""
|
|
|
|
Window values need to have been set in Kodimonitor.py
|
|
|
|
"""
|
2016-02-17 19:13:37 +11:00
|
|
|
window = utils.window
|
2015-12-25 07:07:00 +11:00
|
|
|
# Will be called when xbmc starts playing a file
|
|
|
|
self.stopAll()
|
|
|
|
|
2016-04-12 03:18:55 +10:00
|
|
|
# Get current file (in utf-8!)
|
2015-12-25 07:07:00 +11:00
|
|
|
try:
|
2016-07-24 02:16:44 +10:00
|
|
|
currentFile = self.getPlayingFile()
|
2015-12-25 07:07:00 +11:00
|
|
|
xbmc.sleep(300)
|
|
|
|
except:
|
|
|
|
currentFile = ""
|
|
|
|
count = 0
|
|
|
|
while not currentFile:
|
|
|
|
xbmc.sleep(100)
|
|
|
|
try:
|
2016-07-24 02:16:44 +10:00
|
|
|
currentFile = self.getPlayingFile()
|
2016-03-17 03:02:22 +11:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if count == 20:
|
2016-04-26 21:53:19 +10:00
|
|
|
self.logMsg("Cancelling playback report...", 1)
|
2015-12-25 07:07:00 +11:00
|
|
|
break
|
2016-03-17 03:02:22 +11:00
|
|
|
else:
|
|
|
|
count += 1
|
|
|
|
if not currentFile:
|
2016-04-27 01:15:05 +10:00
|
|
|
self.logMsg('Error getting a currently playing file; abort '
|
|
|
|
'reporting', -1)
|
2016-03-17 03:02:22 +11:00
|
|
|
return
|
|
|
|
|
|
|
|
# Save currentFile for cleanup later and for references
|
|
|
|
self.currentFile = currentFile
|
2016-05-07 21:15:02 +10:00
|
|
|
window('plex_lastPlayedFiled', value=utils.tryDecode(currentFile))
|
2016-03-17 03:02:22 +11:00
|
|
|
# We may need to wait for info to be set in kodi monitor
|
|
|
|
itemId = window("emby_%s.itemid" % currentFile)
|
|
|
|
count = 0
|
|
|
|
while not itemId:
|
|
|
|
xbmc.sleep(200)
|
2016-02-17 19:13:37 +11:00
|
|
|
itemId = window("emby_%s.itemid" % currentFile)
|
2016-07-22 23:33:27 +10:00
|
|
|
if count == 5:
|
2016-04-27 01:15:05 +10:00
|
|
|
self.logMsg("Could not find itemId, cancelling playback "
|
|
|
|
"report!", -1)
|
2016-03-17 03:02:22 +11:00
|
|
|
return
|
|
|
|
count += 1
|
|
|
|
|
2016-04-27 01:15:05 +10:00
|
|
|
self.logMsg("ONPLAYBACK_STARTED: %s itemid: %s"
|
2016-05-07 21:15:02 +10:00
|
|
|
% (utils.tryDecode(currentFile), itemId), 0)
|
2016-03-17 03:02:22 +11:00
|
|
|
|
|
|
|
embyitem = "emby_%s" % currentFile
|
|
|
|
runtime = window("%s.runtime" % embyitem)
|
|
|
|
refresh_id = window("%s.refreshid" % embyitem)
|
|
|
|
playMethod = window("%s.playmethod" % embyitem)
|
|
|
|
itemType = window("%s.type" % embyitem)
|
2016-05-17 02:19:05 +10:00
|
|
|
try:
|
|
|
|
playcount = int(window("%s.playcount" % embyitem))
|
|
|
|
except ValueError:
|
|
|
|
playcount = 0
|
2016-03-17 03:02:22 +11:00
|
|
|
window('emby_skipWatched%s' % itemId, value="true")
|
|
|
|
|
2016-04-27 01:15:05 +10:00
|
|
|
self.logMsg("Playing itemtype is: %s" % itemType, 1)
|
2016-03-17 03:02:22 +11:00
|
|
|
|
2016-05-31 16:06:42 +10:00
|
|
|
customseek = window('plex_customplaylist.seektime')
|
2016-06-20 02:30:21 +10:00
|
|
|
if customseek:
|
2016-03-17 03:02:22 +11:00
|
|
|
# Start at, when using custom playlist (play to Kodi from webclient)
|
2016-04-27 01:15:05 +10:00
|
|
|
self.logMsg("Seeking to: %s" % customseek, 1)
|
2016-06-01 03:13:29 +10:00
|
|
|
try:
|
2016-07-24 02:16:44 +10:00
|
|
|
self.seekTime(int(customseek))
|
2016-06-01 03:13:29 +10:00
|
|
|
except:
|
|
|
|
self.logMsg('Could not seek!', -1)
|
2016-05-31 16:06:42 +10:00
|
|
|
window('plex_customplaylist.seektime', clear=True)
|
2016-03-17 03:02:22 +11:00
|
|
|
|
2016-06-01 03:02:11 +10:00
|
|
|
try:
|
2016-07-24 02:16:44 +10:00
|
|
|
seekTime = self.getTime()
|
2016-06-01 03:02:11 +10:00
|
|
|
except RuntimeError:
|
2016-06-06 02:39:26 +10:00
|
|
|
self.logMsg('Could not get current seektime from xbmc player', -1)
|
2016-06-01 03:02:11 +10:00
|
|
|
seekTime = 0
|
2016-03-17 03:02:22 +11:00
|
|
|
|
|
|
|
# Get playback volume
|
|
|
|
volume_query = {
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
|
|
|
"method": "Application.GetProperties",
|
|
|
|
"params": {
|
|
|
|
"properties": ["volume", "muted"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(volume_query))
|
|
|
|
result = json.loads(result)
|
|
|
|
result = result.get('result')
|
|
|
|
|
|
|
|
volume = result.get('volume')
|
|
|
|
muted = result.get('muted')
|
|
|
|
|
|
|
|
# Postdata structure to send to Emby server
|
|
|
|
url = "{server}/:/timeline?"
|
|
|
|
postdata = {
|
|
|
|
|
|
|
|
'QueueableMediaTypes': "Video",
|
|
|
|
'CanSeek': True,
|
|
|
|
'ItemId': itemId,
|
|
|
|
'MediaSourceId': itemId,
|
|
|
|
'PlayMethod': playMethod,
|
|
|
|
'VolumeLevel': volume,
|
|
|
|
'PositionTicks': int(seekTime * 10000000),
|
|
|
|
'IsMuted': muted
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get the current audio track and subtitles
|
|
|
|
if playMethod == "Transcode":
|
|
|
|
# property set in PlayUtils.py
|
|
|
|
postdata['AudioStreamIndex'] = window("%sAudioStreamIndex" % currentFile)
|
|
|
|
postdata['SubtitleStreamIndex'] = window("%sSubtitleStreamIndex" % currentFile)
|
|
|
|
else:
|
|
|
|
# Get the current kodi audio and subtitles and convert to Emby equivalent
|
|
|
|
tracks_query = {
|
|
|
|
"jsonrpc": "2.0",
|
|
|
|
"id": 1,
|
|
|
|
"method": "Player.GetProperties",
|
|
|
|
"params": {
|
|
|
|
|
|
|
|
"playerid": 1,
|
|
|
|
"properties": ["currentsubtitle","currentaudiostream","subtitleenabled"]
|
2015-12-25 07:07:00 +11:00
|
|
|
}
|
2016-03-17 03:02:22 +11:00
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(tracks_query))
|
|
|
|
result = json.loads(result)
|
|
|
|
result = result.get('result')
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
try: # Audio tracks
|
|
|
|
indexAudio = result['currentaudiostream']['index']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
indexAudio = 0
|
|
|
|
|
|
|
|
try: # Subtitles tracks
|
|
|
|
indexSubs = result['currentsubtitle']['index']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
indexSubs = 0
|
|
|
|
|
|
|
|
try: # If subtitles are enabled
|
|
|
|
subsEnabled = result['subtitleenabled']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
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 = window("%s.indexMapping" % embyitem)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
if mapping: # Set in playbackutils.py
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-04-27 01:15:05 +10:00
|
|
|
self.logMsg("Mapping for external subtitles index: %s"
|
|
|
|
% mapping, 2)
|
2016-03-17 03:02:22 +11:00
|
|
|
externalIndex = json.loads(mapping)
|
|
|
|
|
|
|
|
if externalIndex.get(str(indexSubs)):
|
|
|
|
# If the current subtitle is in the mapping
|
|
|
|
postdata['SubtitleStreamIndex'] = externalIndex[str(indexSubs)]
|
2015-12-25 07:07:00 +11:00
|
|
|
else:
|
2016-03-17 03:02:22 +11:00
|
|
|
# Internal subtitle currently selected
|
|
|
|
subindex = indexSubs - len(externalIndex) + audioTracks + 1
|
|
|
|
postdata['SubtitleStreamIndex'] = subindex
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
else: # Direct paths enabled scenario or no external subtitles set
|
|
|
|
postdata['SubtitleStreamIndex'] = indexSubs + audioTracks + 1
|
|
|
|
else:
|
|
|
|
postdata['SubtitleStreamIndex'] = ""
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
# Post playback to server
|
|
|
|
# log("Sending POST play started: %s." % postdata, 2)
|
|
|
|
# self.doUtils(url, postBody=postdata, type="POST")
|
|
|
|
|
|
|
|
# Ensure we do have a runtime
|
|
|
|
try:
|
|
|
|
runtime = int(runtime)
|
|
|
|
except ValueError:
|
2016-06-01 03:13:29 +10:00
|
|
|
try:
|
2016-07-24 02:16:44 +10:00
|
|
|
runtime = self.getTotalTime()
|
2016-06-01 03:13:29 +10:00
|
|
|
self.logMsg("Runtime is missing, Kodi runtime: %s"
|
|
|
|
% runtime, 1)
|
|
|
|
except:
|
|
|
|
self.logMsg('Could not get kodi runtime, setting to zero', -1)
|
|
|
|
runtime = 0
|
2016-03-17 03:02:22 +11:00
|
|
|
|
|
|
|
playQueueVersion = window('playQueueVersion')
|
|
|
|
playQueueID = window('playQueueID')
|
|
|
|
playQueueItemID = window('plex_%s.playQueueItemID' % currentFile)
|
2016-05-17 02:19:05 +10:00
|
|
|
with embydb.GetEmbyDB() as emby_db:
|
|
|
|
emby_dbitem = emby_db.getItem_byId(itemId)
|
|
|
|
try:
|
|
|
|
fileid = emby_dbitem[1]
|
|
|
|
except TypeError:
|
|
|
|
self.logMsg("Could not find fileid in plex db.", 1)
|
|
|
|
fileid = None
|
2016-03-17 03:02:22 +11:00
|
|
|
# Save data map for updates and position calls
|
|
|
|
data = {
|
|
|
|
'playQueueVersion': playQueueVersion,
|
|
|
|
'playQueueID': playQueueID,
|
|
|
|
'playQueueItemID': playQueueItemID,
|
2016-06-06 02:39:26 +10:00
|
|
|
'runtime': runtime,
|
2016-03-17 03:02:22 +11:00
|
|
|
'item_id': itemId,
|
|
|
|
'refresh_id': refresh_id,
|
|
|
|
'currentfile': currentFile,
|
|
|
|
'AudioStreamIndex': postdata['AudioStreamIndex'],
|
|
|
|
'SubtitleStreamIndex': postdata['SubtitleStreamIndex'],
|
|
|
|
'playmethod': playMethod,
|
|
|
|
'Type': itemType,
|
2016-05-17 02:19:05 +10:00
|
|
|
'currentPosition': int(seekTime) * 1000,
|
|
|
|
'fileid': fileid,
|
|
|
|
'itemType': itemType,
|
|
|
|
'playcount': playcount
|
2016-03-17 03:02:22 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
self.played_info[currentFile] = data
|
2016-05-17 02:19:05 +10:00
|
|
|
self.logMsg("ADDING_FILE: %s" % data, 1)
|
2016-03-17 03:02:22 +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
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-03-17 03:02:22 +11:00
|
|
|
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-12-25 07:07:00 +11:00
|
|
|
|
2016-02-21 10:21:39 +11:00
|
|
|
def onPlayBackPaused(self):
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
currentFile = self.currentFile
|
2016-05-07 21:15:02 +10:00
|
|
|
self.logMsg("PLAYBACK_PAUSED: %s" % utils.tryDecode(currentFile), 2)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if self.played_info.get(currentFile):
|
|
|
|
self.played_info[currentFile]['paused'] = True
|
|
|
|
|
2016-02-21 10:21:39 +11:00
|
|
|
def onPlayBackResumed(self):
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
currentFile = self.currentFile
|
2016-05-07 21:15:02 +10:00
|
|
|
self.logMsg("PLAYBACK_RESUMED: %s" % utils.tryDecode(currentFile), 2)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if self.played_info.get(currentFile):
|
|
|
|
self.played_info[currentFile]['paused'] = False
|
|
|
|
|
2016-02-21 10:21:39 +11:00
|
|
|
def onPlayBackSeek(self, time, seekOffset):
|
2015-12-25 07:07:00 +11:00
|
|
|
# Make position when seeking a bit more accurate
|
|
|
|
currentFile = self.currentFile
|
2016-05-07 21:15:02 +10:00
|
|
|
self.logMsg("PLAYBACK_SEEK: %s" % utils.tryDecode(currentFile), 2)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if self.played_info.get(currentFile):
|
2016-06-01 03:02:11 +10:00
|
|
|
try:
|
2016-07-24 02:16:44 +10:00
|
|
|
position = self.getTime()
|
2016-06-01 03:02:11 +10:00
|
|
|
except RuntimeError:
|
|
|
|
# When Kodi is not playing
|
|
|
|
return
|
2016-05-17 02:19:05 +10:00
|
|
|
self.played_info[currentFile]['currentPosition'] = position * 1000
|
2016-06-01 03:02:11 +10:00
|
|
|
|
2016-02-21 10:21:39 +11:00
|
|
|
def onPlayBackStopped(self):
|
2016-03-17 04:01:07 +11:00
|
|
|
# Will be called when user stops xbmc playing a file
|
2016-02-17 19:13:37 +11:00
|
|
|
|
|
|
|
window = utils.window
|
2016-04-26 22:41:58 +10:00
|
|
|
self.logMsg("ONPLAYBACK_STOPPED", 1)
|
2016-03-17 04:01:07 +11:00
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
self.stopAll()
|
|
|
|
|
2016-03-17 04:01:07 +11:00
|
|
|
window('Plex_currently_playing_itemid', clear=True)
|
2016-05-31 16:06:42 +10:00
|
|
|
window('plex_customplaylist', clear=True)
|
|
|
|
window('plex_customplaylist.seektime', clear=True)
|
|
|
|
window('plex_customplaylist.seektime', clear=True)
|
2016-04-26 22:41:58 +10:00
|
|
|
self.logMsg("Clear playlist properties.", 1)
|
2016-03-17 03:02:22 +11:00
|
|
|
|
2016-03-17 04:01:07 +11:00
|
|
|
def onPlayBackEnded(self):
|
|
|
|
# Will be called when xbmc stops playing a file, because the file ended
|
|
|
|
self.logMsg("ONPLAYBACK_ENDED", 1)
|
|
|
|
self.onPlayBackStopped()
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
def stopAll(self):
|
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
lang = utils.language
|
|
|
|
settings = utils.settings
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
if not self.played_info:
|
|
|
|
return
|
|
|
|
|
2016-04-26 21:53:19 +10:00
|
|
|
self.logMsg("Played_information: %s" % self.played_info, 1)
|
2015-12-25 07:07:00 +11:00
|
|
|
# Process each items
|
|
|
|
for item in self.played_info:
|
|
|
|
|
|
|
|
data = self.played_info.get(item)
|
|
|
|
if data:
|
|
|
|
|
2016-04-26 21:53:19 +10:00
|
|
|
self.logMsg("Item path: %s" % item, 2)
|
|
|
|
self.logMsg("Item data: %s" % data, 2)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
runtime = data['runtime']
|
|
|
|
currentPosition = data['currentPosition']
|
|
|
|
itemid = data['item_id']
|
|
|
|
refresh_id = data['refresh_id']
|
|
|
|
currentFile = data['currentfile']
|
2016-04-26 21:53:19 +10:00
|
|
|
media_type = data['Type']
|
2015-12-25 07:07:00 +11:00
|
|
|
playMethod = data['playmethod']
|
|
|
|
|
2016-02-26 10:46:12 +11:00
|
|
|
# Prevent manually mark as watched in Kodi monitor
|
|
|
|
utils.window('emby_skipWatched%s' % itemid, value="true")
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
if currentPosition and runtime:
|
|
|
|
try:
|
2016-05-17 00:10:48 +10:00
|
|
|
percentComplete = float(currentPosition) / float(runtime)
|
2015-12-25 07:07:00 +11:00
|
|
|
except ZeroDivisionError:
|
|
|
|
# Runtime is 0.
|
|
|
|
percentComplete = 0
|
2016-06-06 02:55:12 +10:00
|
|
|
|
|
|
|
markPlayed = 0.90
|
2016-04-26 21:53:19 +10:00
|
|
|
self.logMsg("Percent complete: %s Mark played at: %s"
|
2016-06-06 02:55:12 +10:00
|
|
|
% (percentComplete, markPlayed), 1)
|
|
|
|
if percentComplete >= markPlayed:
|
2016-05-17 02:19:05 +10:00
|
|
|
# Tell Kodi that we've finished watching (Plex knows)
|
|
|
|
if (data['fileid'] is not None and
|
|
|
|
data['itemType'] in ('movie', 'episode')):
|
|
|
|
with kodidb.GetKodiDB('video') as kodi_db:
|
|
|
|
kodi_db.addPlaystate(
|
|
|
|
data['fileid'],
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
data['playcount'] + 1,
|
|
|
|
utils.DateToKodi(utils.getUnixTimestamp()))
|
2015-12-25 07:07:00 +11:00
|
|
|
# Send the delete action to the server.
|
|
|
|
offerDelete = False
|
|
|
|
|
2016-04-26 21:53:19 +10:00
|
|
|
if media_type == "Episode" and settings('deleteTV') == "true":
|
2015-12-25 07:07:00 +11:00
|
|
|
offerDelete = True
|
2016-04-26 21:53:19 +10:00
|
|
|
elif media_type == "Movie" and settings('deleteMovies') == "true":
|
2015-12-25 07:07:00 +11:00
|
|
|
offerDelete = True
|
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
if settings('offerDelete') != "true":
|
2015-12-25 07:07:00 +11:00
|
|
|
# Delete could be disabled, even if the subsetting is enabled.
|
|
|
|
offerDelete = False
|
|
|
|
|
2016-02-07 22:38:50 +11:00
|
|
|
# Plex: never delete
|
|
|
|
offerDelete = False
|
2016-06-06 02:55:12 +10:00
|
|
|
if percentComplete >= markPlayed and offerDelete:
|
2016-03-07 23:38:45 +11:00
|
|
|
resp = xbmcgui.Dialog().yesno(
|
2016-03-08 23:00:03 +11:00
|
|
|
lang(30091),
|
|
|
|
lang(33015),
|
2016-03-07 23:38:45 +11:00
|
|
|
autoclose=120000)
|
2016-02-13 09:49:21 +11:00
|
|
|
if not resp:
|
2016-04-26 21:53:19 +10:00
|
|
|
self.logMsg("User skipped deletion.", 1)
|
2016-02-13 09:49:21 +11:00
|
|
|
continue
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
2016-04-26 22:41:58 +10:00
|
|
|
self.logMsg("Deleting request: %s" % itemid, 1)
|
|
|
|
self.doUtils(url, action_type="DELETE")
|
2016-03-23 01:16:58 +11:00
|
|
|
self.stopPlayback(data)
|
2016-02-07 22:38:50 +11:00
|
|
|
|
|
|
|
# Clean the WINDOW properties
|
2016-02-07 23:35:03 +11:00
|
|
|
for filename in self.played_info:
|
|
|
|
cleanup = (
|
|
|
|
'emby_%s.itemid' % filename,
|
|
|
|
'emby_%s.runtime' % filename,
|
|
|
|
'emby_%s.refreshid' % filename,
|
|
|
|
'emby_%s.playmethod' % filename,
|
|
|
|
'emby_%s.type' % filename,
|
2016-05-17 02:19:05 +10:00
|
|
|
'emby_%s.runtime' % filename,
|
|
|
|
'emby_%s.playcount' % filename,
|
2016-02-07 23:35:03 +11:00
|
|
|
'plex_%s.playQueueItemID' % filename,
|
|
|
|
'plex_%s.playlistPosition' % filename,
|
|
|
|
'plex_%s.guid' % filename
|
|
|
|
)
|
|
|
|
for item in cleanup:
|
|
|
|
utils.window(item, clear=True)
|
2016-02-07 22:38:50 +11:00
|
|
|
|
2016-04-14 00:14:55 +10:00
|
|
|
# Stop transcoding
|
|
|
|
if playMethod == "Transcode":
|
2016-04-26 22:41:58 +10:00
|
|
|
self.logMsg("Transcoding for %s terminating" % itemid, 1)
|
|
|
|
self.doUtils(
|
2016-04-14 00:14:55 +10:00
|
|
|
"{server}/video/:/transcode/universal/stop",
|
|
|
|
parameters={'session': self.clientInfo.getDeviceId()})
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
self.played_info.clear()
|
2016-01-13 01:53:06 +11:00
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
def stopPlayback(self, data):
|
2016-03-23 01:16:58 +11:00
|
|
|
self.logMsg("stopPlayback called", 1)
|
2016-01-13 01:53:06 +11:00
|
|
|
args = {
|
2016-05-17 02:19:05 +10:00
|
|
|
'ratingKey': data['item_id'],
|
2016-01-13 01:53:06 +11:00
|
|
|
'state': 'stopped', # 'stopped', 'paused', 'buffering', 'playing'
|
2016-05-17 02:19:05 +10:00
|
|
|
'time': int(data['currentPosition']),
|
|
|
|
'duration': int(data.get('runtime', 0))
|
2015-12-25 07:07:00 +11:00
|
|
|
}
|
2016-06-06 02:39:26 +10:00
|
|
|
self.logMsg('Informing PMS about our state: %s' % args, 2)
|
2016-05-17 02:19:05 +10:00
|
|
|
self.doUtils("{server}/:/timeline?" + urlencode(args),
|
|
|
|
action_type="GET")
|