Merge conflicts player.py
This commit is contained in:
parent
a6263221fd
commit
143ef86978
1 changed files with 45 additions and 55 deletions
|
@ -1,13 +1,14 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
import logging
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import xbmc
|
import xbmc
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
|
|
||||||
import utils
|
from utils import window, settings, language as lang, DateToKodi, \
|
||||||
|
getUnixTimestamp
|
||||||
import clientinfo
|
import clientinfo
|
||||||
import downloadutils
|
import downloadutils
|
||||||
import embydb_functions as embydb
|
import embydb_functions as embydb
|
||||||
|
@ -15,8 +16,11 @@ import kodidb_functions as kodidb
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
log = logging.getLogger("PLEX."+__name__)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
@utils.logging
|
|
||||||
class Player(xbmc.Player):
|
class Player(xbmc.Player):
|
||||||
|
|
||||||
# Borg - multiple instances, shared state
|
# Borg - multiple instances, shared state
|
||||||
|
@ -35,17 +39,16 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
xbmc.Player.__init__(self)
|
xbmc.Player.__init__(self)
|
||||||
|
|
||||||
self.logMsg("Started playback monitor.", 2)
|
log.info("Started playback monitor.")
|
||||||
|
|
||||||
def GetPlayStats(self):
|
def GetPlayStats(self):
|
||||||
return self.playStats
|
return self.playStats
|
||||||
|
|
||||||
def onPlayBackStarted(self):
|
def onPlayBackStarted(self):
|
||||||
"""
|
"""
|
||||||
|
Will be called when xbmc starts playing a file.
|
||||||
Window values need to have been set in Kodimonitor.py
|
Window values need to have been set in Kodimonitor.py
|
||||||
"""
|
"""
|
||||||
window = utils.window
|
|
||||||
# Will be called when xbmc starts playing a file
|
|
||||||
self.stopAll()
|
self.stopAll()
|
||||||
|
|
||||||
# Get current file (in utf-8!)
|
# Get current file (in utf-8!)
|
||||||
|
@ -62,18 +65,16 @@ class Player(xbmc.Player):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if count == 20:
|
if count == 20:
|
||||||
self.logMsg("Cancelling playback report...", 1)
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
count += 1
|
count += 1
|
||||||
if not currentFile:
|
if not currentFile:
|
||||||
self.logMsg('Error getting a currently playing file; abort '
|
log.warn('Error getting currently playing file; abort reporting')
|
||||||
'reporting', -1)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Save currentFile for cleanup later and for references
|
# Save currentFile for cleanup later and for references
|
||||||
self.currentFile = currentFile
|
self.currentFile = currentFile
|
||||||
window('plex_lastPlayedFiled', value=utils.tryDecode(currentFile))
|
window('plex_lastPlayedFiled', value=currentFile)
|
||||||
# We may need to wait for info to be set in kodi monitor
|
# We may need to wait for info to be set in kodi monitor
|
||||||
itemId = window("emby_%s.itemid" % currentFile)
|
itemId = window("emby_%s.itemid" % currentFile)
|
||||||
count = 0
|
count = 0
|
||||||
|
@ -81,13 +82,11 @@ class Player(xbmc.Player):
|
||||||
xbmc.sleep(200)
|
xbmc.sleep(200)
|
||||||
itemId = window("emby_%s.itemid" % currentFile)
|
itemId = window("emby_%s.itemid" % currentFile)
|
||||||
if count == 5:
|
if count == 5:
|
||||||
self.logMsg("Could not find itemId, cancelling playback "
|
log.warn("Could not find itemId, cancelling playback report!")
|
||||||
"report!", -1)
|
|
||||||
return
|
return
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
self.logMsg("ONPLAYBACK_STARTED: %s itemid: %s"
|
log.info("ONPLAYBACK_STARTED: %s itemid: %s" % (currentFile, itemId))
|
||||||
% (utils.tryDecode(currentFile), itemId), 0)
|
|
||||||
|
|
||||||
embyitem = "emby_%s" % currentFile
|
embyitem = "emby_%s" % currentFile
|
||||||
runtime = window("%s.runtime" % embyitem)
|
runtime = window("%s.runtime" % embyitem)
|
||||||
|
@ -100,22 +99,23 @@ class Player(xbmc.Player):
|
||||||
playcount = 0
|
playcount = 0
|
||||||
window('emby_skipWatched%s' % itemId, value="true")
|
window('emby_skipWatched%s' % itemId, value="true")
|
||||||
|
|
||||||
self.logMsg("Playing itemtype is: %s" % itemType, 1)
|
log.debug("Playing itemtype is: %s" % itemType)
|
||||||
|
|
||||||
customseek = window('plex_customplaylist.seektime')
|
customseek = window('plex_customplaylist.seektime')
|
||||||
if customseek:
|
if customseek:
|
||||||
# Start at, when using custom playlist (play to Kodi from webclient)
|
# Start at, when using custom playlist (play to Kodi from
|
||||||
self.logMsg("Seeking to: %s" % customseek, 1)
|
# webclient)
|
||||||
|
log.info("Seeking to: %s" % customseek)
|
||||||
try:
|
try:
|
||||||
self.seekTime(int(customseek))
|
self.seekTime(int(customseek))
|
||||||
except:
|
except:
|
||||||
self.logMsg('Could not seek!', -1)
|
log.error('Could not seek!')
|
||||||
window('plex_customplaylist.seektime', clear=True)
|
window('plex_customplaylist.seektime', clear=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
seekTime = self.getTime()
|
seekTime = self.getTime()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
self.logMsg('Could not get current seektime from xbmc player', -1)
|
log.error('Could not get current seektime from xbmc player')
|
||||||
seekTime = 0
|
seekTime = 0
|
||||||
|
|
||||||
# Get playback volume
|
# Get playback volume
|
||||||
|
@ -130,7 +130,7 @@ class Player(xbmc.Player):
|
||||||
result = xbmc.executeJSONRPC(json.dumps(volume_query))
|
result = xbmc.executeJSONRPC(json.dumps(volume_query))
|
||||||
result = json.loads(result)
|
result = json.loads(result)
|
||||||
result = result.get('result')
|
result = result.get('result')
|
||||||
|
|
||||||
volume = result.get('volume')
|
volume = result.get('volume')
|
||||||
muted = result.get('muted')
|
muted = result.get('muted')
|
||||||
|
|
||||||
|
@ -196,8 +196,8 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
if mapping: # Set in playbackutils.py
|
if mapping: # Set in playbackutils.py
|
||||||
|
|
||||||
self.logMsg("Mapping for external subtitles index: %s"
|
log.debug("Mapping for external subtitles index: %s"
|
||||||
% mapping, 2)
|
% mapping)
|
||||||
externalIndex = json.loads(mapping)
|
externalIndex = json.loads(mapping)
|
||||||
|
|
||||||
if externalIndex.get(str(indexSubs)):
|
if externalIndex.get(str(indexSubs)):
|
||||||
|
@ -224,10 +224,9 @@ class Player(xbmc.Player):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
try:
|
||||||
runtime = self.getTotalTime()
|
runtime = self.getTotalTime()
|
||||||
self.logMsg("Runtime is missing, Kodi runtime: %s"
|
log.error("Runtime is missing, Kodi runtime: %s" % runtime)
|
||||||
% runtime, 1)
|
|
||||||
except:
|
except:
|
||||||
self.logMsg('Could not get kodi runtime, setting to zero', -1)
|
log.error('Could not get kodi runtime, setting to zero')
|
||||||
runtime = 0
|
runtime = 0
|
||||||
|
|
||||||
with embydb.GetEmbyDB() as emby_db:
|
with embydb.GetEmbyDB() as emby_db:
|
||||||
|
@ -235,7 +234,7 @@ class Player(xbmc.Player):
|
||||||
try:
|
try:
|
||||||
fileid = emby_dbitem[1]
|
fileid = emby_dbitem[1]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.logMsg("Could not find fileid in plex db.", 1)
|
log.info("Could not find fileid in plex db.")
|
||||||
fileid = None
|
fileid = None
|
||||||
# Save data map for updates and position calls
|
# Save data map for updates and position calls
|
||||||
data = {
|
data = {
|
||||||
|
@ -252,9 +251,9 @@ class Player(xbmc.Player):
|
||||||
'itemType': itemType,
|
'itemType': itemType,
|
||||||
'playcount': playcount
|
'playcount': playcount
|
||||||
}
|
}
|
||||||
|
|
||||||
self.played_info[currentFile] = data
|
self.played_info[currentFile] = data
|
||||||
self.logMsg("ADDING_FILE: %s" % data, 1)
|
log.info("ADDING_FILE: %s" % data)
|
||||||
|
|
||||||
# log some playback stats
|
# log some playback stats
|
||||||
'''if(itemType != None):
|
'''if(itemType != None):
|
||||||
|
@ -274,7 +273,7 @@ class Player(xbmc.Player):
|
||||||
def onPlayBackPaused(self):
|
def onPlayBackPaused(self):
|
||||||
|
|
||||||
currentFile = self.currentFile
|
currentFile = self.currentFile
|
||||||
self.logMsg("PLAYBACK_PAUSED: %s" % utils.tryDecode(currentFile), 2)
|
log.info("PLAYBACK_PAUSED: %s" % currentFile)
|
||||||
|
|
||||||
if self.played_info.get(currentFile):
|
if self.played_info.get(currentFile):
|
||||||
self.played_info[currentFile]['paused'] = True
|
self.played_info[currentFile]['paused'] = True
|
||||||
|
@ -282,7 +281,7 @@ class Player(xbmc.Player):
|
||||||
def onPlayBackResumed(self):
|
def onPlayBackResumed(self):
|
||||||
|
|
||||||
currentFile = self.currentFile
|
currentFile = self.currentFile
|
||||||
self.logMsg("PLAYBACK_RESUMED: %s" % utils.tryDecode(currentFile), 2)
|
log.info("PLAYBACK_RESUMED: %s" % currentFile)
|
||||||
|
|
||||||
if self.played_info.get(currentFile):
|
if self.played_info.get(currentFile):
|
||||||
self.played_info[currentFile]['paused'] = False
|
self.played_info[currentFile]['paused'] = False
|
||||||
|
@ -290,7 +289,7 @@ class Player(xbmc.Player):
|
||||||
def onPlayBackSeek(self, time, seekOffset):
|
def onPlayBackSeek(self, time, seekOffset):
|
||||||
# Make position when seeking a bit more accurate
|
# Make position when seeking a bit more accurate
|
||||||
currentFile = self.currentFile
|
currentFile = self.currentFile
|
||||||
self.logMsg("PLAYBACK_SEEK: %s" % utils.tryDecode(currentFile), 2)
|
self.info("PLAYBACK_SEEK: %s" % currentFile)
|
||||||
|
|
||||||
if self.played_info.get(currentFile):
|
if self.played_info.get(currentFile):
|
||||||
try:
|
try:
|
||||||
|
@ -302,9 +301,7 @@ class Player(xbmc.Player):
|
||||||
|
|
||||||
def onPlayBackStopped(self):
|
def onPlayBackStopped(self):
|
||||||
# Will be called when user stops xbmc playing a file
|
# Will be called when user stops xbmc playing a file
|
||||||
|
log.info("ONPLAYBACK_STOPPED")
|
||||||
window = utils.window
|
|
||||||
self.logMsg("ONPLAYBACK_STOPPED", 1)
|
|
||||||
|
|
||||||
self.stopAll()
|
self.stopAll()
|
||||||
|
|
||||||
|
@ -312,30 +309,23 @@ class Player(xbmc.Player):
|
||||||
window('plex_customplaylist', clear=True)
|
window('plex_customplaylist', clear=True)
|
||||||
window('plex_customplaylist.seektime', clear=True)
|
window('plex_customplaylist.seektime', clear=True)
|
||||||
window('plex_customplaylist.seektime', clear=True)
|
window('plex_customplaylist.seektime', clear=True)
|
||||||
self.logMsg("Clear playlist properties.", 1)
|
log.debug("Cleared playlist properties.")
|
||||||
|
|
||||||
def onPlayBackEnded(self):
|
def onPlayBackEnded(self):
|
||||||
# Will be called when xbmc stops playing a file, because the file ended
|
# Will be called when xbmc stops playing a file, because the file ended
|
||||||
self.logMsg("ONPLAYBACK_ENDED", 1)
|
log.info("ONPLAYBACK_ENDED")
|
||||||
self.onPlayBackStopped()
|
self.onPlayBackStopped()
|
||||||
|
|
||||||
def stopAll(self):
|
def stopAll(self):
|
||||||
|
|
||||||
lang = utils.language
|
|
||||||
settings = utils.settings
|
|
||||||
|
|
||||||
if not self.played_info:
|
if not self.played_info:
|
||||||
return
|
return
|
||||||
|
log.info("Played_information: %s" % self.played_info)
|
||||||
self.logMsg("Played_information: %s" % self.played_info, 1)
|
|
||||||
# Process each items
|
# Process each items
|
||||||
for item in self.played_info:
|
for item in self.played_info:
|
||||||
|
|
||||||
data = self.played_info.get(item)
|
data = self.played_info.get(item)
|
||||||
if data:
|
if data:
|
||||||
|
log.debug("Item path: %s" % item)
|
||||||
self.logMsg("Item path: %s" % item, 2)
|
log.debug("Item data: %s" % data)
|
||||||
self.logMsg("Item data: %s" % data, 2)
|
|
||||||
|
|
||||||
runtime = data['runtime']
|
runtime = data['runtime']
|
||||||
currentPosition = data['currentPosition']
|
currentPosition = data['currentPosition']
|
||||||
|
@ -346,7 +336,7 @@ class Player(xbmc.Player):
|
||||||
playMethod = data['playmethod']
|
playMethod = data['playmethod']
|
||||||
|
|
||||||
# Prevent manually mark as watched in Kodi monitor
|
# Prevent manually mark as watched in Kodi monitor
|
||||||
utils.window('emby_skipWatched%s' % itemid, value="true")
|
window('emby_skipWatched%s' % itemid, value="true")
|
||||||
|
|
||||||
if currentPosition and runtime:
|
if currentPosition and runtime:
|
||||||
try:
|
try:
|
||||||
|
@ -356,8 +346,8 @@ class Player(xbmc.Player):
|
||||||
percentComplete = 0
|
percentComplete = 0
|
||||||
|
|
||||||
markPlayed = 0.90
|
markPlayed = 0.90
|
||||||
self.logMsg("Percent complete: %s Mark played at: %s"
|
log.info("Percent complete: %s Mark played at: %s"
|
||||||
% (percentComplete, markPlayed), 1)
|
% (percentComplete, markPlayed))
|
||||||
if percentComplete >= markPlayed:
|
if percentComplete >= markPlayed:
|
||||||
# Tell Kodi that we've finished watching (Plex knows)
|
# Tell Kodi that we've finished watching (Plex knows)
|
||||||
if (data['fileid'] is not None and
|
if (data['fileid'] is not None and
|
||||||
|
@ -368,7 +358,7 @@ class Player(xbmc.Player):
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
data['playcount'] + 1,
|
data['playcount'] + 1,
|
||||||
utils.DateToKodi(utils.getUnixTimestamp()))
|
DateToKodi(getUnixTimestamp()))
|
||||||
# Send the delete action to the server.
|
# Send the delete action to the server.
|
||||||
offerDelete = False
|
offerDelete = False
|
||||||
|
|
||||||
|
@ -389,11 +379,11 @@ class Player(xbmc.Player):
|
||||||
lang(33015),
|
lang(33015),
|
||||||
autoclose=120000)
|
autoclose=120000)
|
||||||
if not resp:
|
if not resp:
|
||||||
self.logMsg("User skipped deletion.", 1)
|
log.info("User skipped deletion.")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url = "{server}/emby/Items/%s?format=json" % itemid
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
||||||
self.logMsg("Deleting request: %s" % itemid, 1)
|
log.info("Deleting request: %s" % itemid)
|
||||||
self.doUtils(url, action_type="DELETE")
|
self.doUtils(url, action_type="DELETE")
|
||||||
|
|
||||||
# Clean the WINDOW properties
|
# Clean the WINDOW properties
|
||||||
|
@ -409,11 +399,11 @@ class Player(xbmc.Player):
|
||||||
'plex_%s.playlistPosition' % filename
|
'plex_%s.playlistPosition' % filename
|
||||||
)
|
)
|
||||||
for item in cleanup:
|
for item in cleanup:
|
||||||
utils.window(item, clear=True)
|
window(item, clear=True)
|
||||||
|
|
||||||
# Stop transcoding
|
# Stop transcoding
|
||||||
if playMethod == "Transcode":
|
if playMethod == "Transcode":
|
||||||
self.logMsg("Transcoding for %s terminating" % itemid, 1)
|
log.info("Transcoding for %s terminating" % itemid)
|
||||||
self.doUtils(
|
self.doUtils(
|
||||||
"{server}/video/:/transcode/universal/stop",
|
"{server}/video/:/transcode/universal/stop",
|
||||||
parameters={'session': self.clientInfo.getDeviceId()})
|
parameters={'session': self.clientInfo.getDeviceId()})
|
||||||
|
|
Loading…
Reference in a new issue