Plexcompanion 1st version for entrypoint.py, playbackutils.py, PlexAPI.py

This commit is contained in:
tomkat83 2016-01-31 16:13:40 +01:00
parent 87f9c9ef61
commit 6aa3f62b79
6 changed files with 195 additions and 137 deletions

View file

@ -1425,7 +1425,13 @@ class API():
""" """
Returns the type of media, e.g. 'movie' or 'clip' for trailers Returns the type of media, e.g. 'movie' or 'clip' for trailers
""" """
return self.item['type'] # XML
try:
item = self.item.attrib
# JSON
except AttributeError:
item = self.item
return item.get('type', '')
def getChecksum(self): def getChecksum(self):
""" """
@ -1449,15 +1455,13 @@ class API():
Can be used on both XML and JSON Can be used on both XML and JSON
Returns the Plex key such as '246922' as a string Returns the Plex key such as '246922' as a string
""" """
item = self.item
# XML # XML
try: try:
item = item[0].attrib result = self.item.attrib
# JSON # JSON
except (AttributeError, KeyError): except AttributeError:
pass item = self.item
key = item['ratingKey'] return item['ratingKey']
return str(key)
def getKey(self): def getKey(self):
""" """
@ -1887,7 +1891,13 @@ class API():
If not found, empty str is returned If not found, empty str is returned
""" """
return self.item.get('playQueueItemID') # XML:
try:
item = self.item.attrib
# JSON
except AttributeError:
item = self.item
return item.get('playQueueItemID', '')
def getDataFromPartOrMedia(self, key): def getDataFromPartOrMedia(self, key):
""" """
@ -1896,8 +1906,15 @@ class API():
If all fails, None is returned. If all fails, None is returned.
""" """
media = self.item['_children'][0] # JSON
part = media['_children'][self.part] try:
media = self.item['_children'][0]
part = media['_children'][self.part]
# XML
except TypeError:
media = self.item[0].attrib
part = self.item[0][self.part].attrib
try: try:
try: try:
value = part[key] value = part[key]
@ -2242,8 +2259,8 @@ class API():
} }
xargs = PlexAPI().getXArgsDeviceInfo(options=options) xargs = PlexAPI().getXArgsDeviceInfo(options=options)
# For Direct Playing # For Direct Playing
path = self.getDataFromPartOrMedia('key')
if action == "DirectPlay": if action == "DirectPlay":
path = self.item['_children'][0]['_children'][self.partNumber]['key']
transcodePath = self.server + path transcodePath = self.server + path
# Be sure to have exactly ONE '?' in the path (might already have # Be sure to have exactly ONE '?' in the path (might already have
# been returned, e.g. trailers!) # been returned, e.g. trailers!)
@ -2257,7 +2274,6 @@ class API():
# For Direct Streaming or Transcoding # For Direct Streaming or Transcoding
transcodePath = self.server + \ transcodePath = self.server + \
'/video/:/transcode/universal/start.m3u8?' '/video/:/transcode/universal/start.m3u8?'
path = self.getDataFromPartOrMedia('key')
args = { args = {
'path': path, 'path': path,
'mediaIndex': 0, # Probably refering to XML reply sheme 'mediaIndex': 0, # Probably refering to XML reply sheme

View file

@ -21,6 +21,13 @@ def PlexToKodiTimefactor():
return 1.0 / 1000.0 return 1.0 / 1000.0
def ConvertPlexToKodiTime(plexTime):
"""
Converts Plextime to Koditime. Returns an int (in seconds).
"""
return int(float(plexTime) * PlexToKodiTimefactor())
def GetItemClassFromType(itemType): def GetItemClassFromType(itemType):
classes = { classes = {
'movie': 'Movies', 'movie': 'Movies',
@ -94,26 +101,21 @@ def EmbyItemtypes():
def GetPlayQueue(playQueueID): def GetPlayQueue(playQueueID):
""" """
Fetches the PMS playqueue with the playQueueID as a JSON Fetches the PMS playqueue with the playQueueID as an XML
Returns False if something went wrong Returns False if something went wrong
""" """
url = "{server}/playQueues/%s" % playQueueID url = "{server}/playQueues/%s" % playQueueID
headerOptions = {'Accept': 'application/json'} args = {'Accept': 'application/xml'}
json = downloadutils.DownloadUtils().downloadUrl(url, headerOptions=headerOptions) xml = downloadutils.DownloadUtils().downloadUrl(url, headerOptions=args)
try: try:
json = json.json() xml.attrib['playQueueID']
except: except (AttributeError, KeyError):
return False return False
try: return xml
json['_children']
json['playQueueID']
except KeyError:
return False
return json
def GetPlexMetadata(key): def GetPlexMetadata(key, JSON=True):
""" """
Returns raw API metadata for key as an etree XML. Returns raw API metadata for key as an etree XML.
@ -139,7 +141,10 @@ def GetPlexMetadata(key):
'includeConcerts': 1 'includeConcerts': 1
} }
url = url + '?' + urlencode(arguments) url = url + '?' + urlencode(arguments)
headerOptions = {'Accept': 'application/xml'} if not JSON:
headerOptions = {'Accept': 'application/xml'}
else:
headerOptions = {}
xml = downloadutils.DownloadUtils().downloadUrl(url, headerOptions=headerOptions) xml = downloadutils.DownloadUtils().downloadUrl(url, headerOptions=headerOptions)
# Did we receive a valid XML? # Did we receive a valid XML?
try: try:

View file

@ -60,7 +60,8 @@ def plexCompanion(fullurl, params=None):
utils.window('plex_machineIdentifier')), -1) utils.window('plex_machineIdentifier')), -1)
return return
utils.window('plex_key', params.get('key')) utils.window('plex_key', params.get('key'))
library, key, query = PlexFunctions(params.get('containerKey')) library, key, query = PlexFunctions.ParseContainerKey(
params.get('containerKey'))
# Construct a container key that works always (get rid of playlist args) # Construct a container key that works always (get rid of playlist args)
utils.window('plex_containerKey', '/'+library+'/'+key) utils.window('plex_containerKey', '/'+library+'/'+key)
# Assume it's video when something goes wrong # Assume it's video when something goes wrong
@ -69,42 +70,57 @@ def plexCompanion(fullurl, params=None):
if 'playQueues' in library: if 'playQueues' in library:
utils.logMsg(title, "Playing a playQueue. Query was: %s" % query, 1) utils.logMsg(title, "Playing a playQueue. Query was: %s" % query, 1)
# Playing a playlist that we need to fetch from PMS # Playing a playlist that we need to fetch from PMS
playQueue = PlexFunctions.GetPlayQueue(key) xml = PlexFunctions.GetPlayQueue(key)
if not playQueue: if not xml:
utils.logMsg( utils.logMsg(
title, "Error getting PMS playlist for key %s" % key, -1) title, "Error getting PMS playlist for key %s" % key, -1)
return else:
PassPlaylist(xml, resume=int(params.get('offset', '0')))
else:
utils.logMsg(
title, "Not knowing what to do for now - no playQueue sent", -1)
# Set window properties to make them available for other threads
utils.window('plex_playQueueID', playQueue['playQueueID'])
utils.window('plex_playQueueVersion', playQueue['playQueueVersion'])
utils.window('plex_playQueueShuffled', playQueue['playQueueShuffled'])
utils.window(
'plex_playQueueSelectedItemID',
playQueue['playQueueSelectedItemID'])
utils.window(
'plex_playQueueSelectedItemOffset',
playQueue['playQueueSelectedItemOffset'])
pbutils.PlaybackUtils(playQueue['_children']).StartPlay( def PassPlaylist(xml, resume=0):
resume=playQueue['playQueueSelectedItemOffset'], # Set window properties to make them available later for other threads
resumeItem=playQueue['playQueueSelectedItemID']) windowArgs = [
'playQueueID',
'playQueueVersion',
'playQueueShuffled']
for arg in windowArgs:
utils.window(arg, utils.XMLAtt(xml, arg))
# Start playing # Get resume point
item = PlexFunctions.GetPlexMetadata(itemid) resume1 = utils.IntFromStr(
pbutils.PlaybackUtils(item).play(itemid, dbid, seektime=resume) utils.XMLAtt(xml, 'playQueueSelectedItemOffset'))
resume2 = resume
# Convert Plextime to Koditime
resume = PlexFunctions.ConvertPlexToKodiTime(max(resume1, resume2))
pbutils.PlaybackUtils(xml).StartPlay(
resume=resume,
resumeItem=utils.XMLAtt(xml, 'playQueueSelectedItemID'))
def doPlayback(itemid, dbid): def doPlayback(itemid, dbid):
# Get a first XML to get the librarySectionUUID utils.logMsg(title, "doPlayback called with %s %s"
item = PlexFunctions.GetPlexMetadata(itemid) % (itemid, dbid), 1)
# Use that to call the playlist item = PlexFunctions.GetPlexMetadata(itemid, JSON=True)
xmlPlaylist = PlexAPI.API(item).GetPlexPlaylist() playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
if xmlPlaylist: # If current playlist is NOT empty, we only need to update the item url
pbutils.PlaybackUtils(xmlPlaylist).play(itemid, dbid) if playlist.size() != 0:
utils.logMsg(title, "Playlist is not empty, hence update url only", 1)
pbutils.PlaybackUtils(item).StartPlay()
else: else:
# No playlist received e.g. when directly playing trailers # Get a first XML to get the librarySectionUUID
pbutils.PlaybackUtils(item).play(itemid, dbid) # Use librarySectionUUID to call the playlist
xmlPlaylist = PlexAPI.API(item).GetPlexPlaylist()
if xmlPlaylist:
PassPlaylist(xmlPlaylist)
else:
# No playlist received e.g. when directly playing trailers
pbutils.PlaybackUtils(item).StartPlay()
##### DO RESET AUTH ##### ##### DO RESET AUTH #####
def resetAuth(): def resetAuth():

View file

@ -39,41 +39,45 @@ class PlaybackUtils():
self.emby = embyserver.Read_EmbyServer() self.emby = embyserver.Read_EmbyServer()
self.pl = playlist.Playlist() self.pl = playlist.Playlist()
def StartPlay(self, resume=None, resumeItem=None): def StartPlay(self, resume=0, resumeItem=""):
self.logMsg("StartPlay called with resume=%s, resumeItem=%s" self.logMsg("StartPlay called with resume=%s, resumeItem=%s"
% (resume, resumeItem), 1) % (resume, resumeItem), 1)
# Setup Kodi playlist (e.g. make new one or append or even update)
# Why should we have different behaviour if user is on home screen?!? # Why should we have different behaviour if user is on home screen?!?
# self.homeScreen = xbmc.getCondVisibility('Window.IsActive(home)') # self.homeScreen = xbmc.getCondVisibility('Window.IsActive(home)')
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) self.playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
# Clear playlist since we're always using PMS playQueues
self.playlist.clear()
self.startPos = max(self.playlist.getposition(), 0) # Can return -1 self.startPos = max(self.playlist.getposition(), 0) # Can return -1
self.sizePlaylist = self.playlist.size() sizePlaylist = self.playlist.size()
self.currentPosition = self.startPos self.currentPosition = self.startPos
self.logMsg("Playlist start position: %s" % self.startPos, 1) self.logMsg("Playlist start position: %s" % self.startPos, 1)
self.logMsg("Playlist position we're starting with: %s" self.logMsg("Playlist position we're starting with: %s"
% self.currentPosition, 1) % self.currentPosition, 1)
self.logMsg("Playlist size: %s" % self.sizePlaylist, 1) self.logMsg("Playlist size: %s" % sizePlaylist, 1)
# Might have been called AFTER a playlist has been setup to only
# update the playitem's url
self.updateUrlOnly = True if sizePlaylist != 0 else False
self.plexResumeItemId = resumeItem self.plexResumeItemId = resumeItem
# Where should we ultimately start playback? # Where should we ultimately start playback?
self.resumePost = self.startPos self.resumePos = self.startPos
if resume:
if resume == '0':
resume = None
else:
resume = int(resume)
# Run through the passed PMS playlist and construct playlist # Run through the passed PMS playlist and construct playlist
startitem = None
for mediaItem in self.item: for mediaItem in self.item:
self.AddMediaItemToPlaylist(mediaItem) listitem = self.AddMediaItemToPlaylist(mediaItem)
# Kick off playback if listitem:
startitem = listitem
# Return the updated play Url if we've already setup the playlist
if self.updateUrlOnly:
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, startitem)
return
# Kick off initial playback
self.logMsg("Starting playback", 1)
Player = xbmc.Player() Player = xbmc.Player()
Player.play(self.playlist, startpos=self.resumePost) Player.play(self.playlist, startpos=self.resumePos)
if resume: if resume != 0:
try: try:
Player.seekTime(resume) Player.seekTime(resume)
except: except:
@ -90,6 +94,11 @@ class PlaybackUtils():
API = PlexAPI.API(item) API = PlexAPI.API(item)
playutils = putils.PlayUtils(item) playutils = putils.PlayUtils(item)
# If we're only updating an url, we've been handed metadata for only
# one part - no need to run over all parts
if self.updateUrlOnly:
return playutils.getPlayUrl()[0]
# e.g. itemid='219155' # e.g. itemid='219155'
itemid = API.getRatingKey() itemid = API.getRatingKey()
# Get DB id from Kodi by using plex id, if that works # Get DB id from Kodi by using plex id, if that works
@ -104,7 +113,8 @@ class PlaybackUtils():
embyconn.close() embyconn.close()
# Get playurls per part and process them # Get playurls per part and process them
for playurl in playutils.getPlayUrl(): returnListItem = None
for counter, playurl in enumerate(playutils.getPlayUrl()):
# One new listitem per part # One new listitem per part
listitem = xbmcgui.ListItem() listitem = xbmcgui.ListItem()
# For items that are not (yet) synced to Kodi lib, e.g. trailers # For items that are not (yet) synced to Kodi lib, e.g. trailers
@ -130,40 +140,39 @@ class PlaybackUtils():
playQueueItemID = API.GetPlayQueueItemID() playQueueItemID = API.GetPlayQueueItemID()
# Is this the position where we should start playback? # Is this the position where we should start playback?
if playQueueItemID == self.plexResumeItemId: if counter == 0:
self.logMsg( if playQueueItemID == self.plexResumeItemId:
"Figure we should start playback at position %s " self.logMsg(
"with playQueueItemID %s" "Figure we should start playback at position %s "
% (self.currentPosition, playQueueItemID), 2) "with playQueueItemID %s"
self.resumePost = self.currentPosition % (self.currentPosition, playQueueItemID), 2)
self.resumePost = self.currentPosition
returnListItem = listitem
# We need to keep track of playQueueItemIDs for Plex Companion # We need to keep track of playQueueItemIDs for Plex Companion
utils.window( utils.window(
'plex_%s.playQueueItemID' % playurl, API.GetPlayQueueItemID()) 'plex_%s.playQueueItemID' % playurl, playQueueItemID)
utils.window( utils.window(
'plex_%s.playlistPosition' % playurl, self.currentPosition) 'plex_%s.playlistPosition'
% playurl, str(self.currentPosition))
# Log the playlist that we end up with # Log the playlist that we end up with
self.pl.verifyPlaylist() self.pl.verifyPlaylist()
def play(self, item): return returnListItem
API = PlexAPI.API(item) def play(self, itemid, dbid=None):
"""
Original one
"""
self.logMsg("Play called.", 1)
doUtils = self.doUtils
item = self.item
API = self.API
listitem = xbmcgui.ListItem() listitem = xbmcgui.ListItem()
playutils = putils.PlayUtils(item) playutils = putils.PlayUtils(item)
# e.g. itemid='219155'
itemid = API.getRatingKey()
# Get DB id from Kodi by using plex id, if that works
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby = embydb_functions.Embydb_Functions(embycursor)
try:
dbid = emby.getItem_byId(itemid)[0]
except TypeError:
# Trailers and the like that are not in the kodi DB
dbid = None
embyconn.close()
playurl = playutils.getPlayUrl() playurl = playutils.getPlayUrl()
if not playurl: if not playurl:
return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem) return xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, listitem)
@ -184,7 +193,6 @@ class PlaybackUtils():
propertiesPlayback = utils.window('emby_playbackProps') == "true" propertiesPlayback = utils.window('emby_playbackProps') == "true"
introsPlaylist = False introsPlaylist = False
partsPlaylist = False
dummyPlaylist = False dummyPlaylist = False
self.logMsg("Playlist start position: %s" % startPos, 1) self.logMsg("Playlist start position: %s" % startPos, 1)
@ -194,7 +202,7 @@ class PlaybackUtils():
############### RESUME POINT ################ ############### RESUME POINT ################
userdata = API.getUserData() userdata = API.getUserData()
seektime = userdata['Resume'] seektime = API.adjustResume(userdata['Resume'])
# We need to ensure we add the intro and additional parts only once. # We need to ensure we add the intro and additional parts only once.
# Otherwise we get a loop. # Otherwise we get a loop.
@ -212,39 +220,41 @@ class PlaybackUtils():
# Remove the original item from playlist # Remove the original item from playlist
self.pl.removefromPlaylist(startPos+1) self.pl.removefromPlaylist(startPos+1)
# Readd the original item to playlist - via jsonrpc so we have full metadata # Readd the original item to playlist - via jsonrpc so we have full metadata
self.pl.insertintoPlaylist(currentPosition+1, dbid, item[-1].attrib['type'].lower()) self.pl.insertintoPlaylist(currentPosition+1, dbid, item['Type'].lower())
currentPosition += 1 currentPosition += 1
############### -- CHECK FOR INTROS ################ ############### -- CHECK FOR INTROS ################
if utils.settings('enableCinema') == "true" and not seektime: if utils.settings('enableCinema') == "true" and not seektime:
# if we have any play them when the movie/show is not being resumed # if we have any play them when the movie/show is not being resumed
playListSize = int(item.attrib['size']) url = "{server}/emby/Users/{UserId}/Items/%s/Intros?format=json" % itemid
if playListSize > 1: intros = doUtils.downloadUrl(url)
if intros['TotalRecordCount'] != 0:
getTrailers = True getTrailers = True
if utils.settings('askCinema') == "true": if utils.settings('askCinema') == "true":
resp = xbmcgui.Dialog().yesno(self.addonName, "Play trailers?") resp = xbmcgui.Dialog().yesno("Emby Cinema Mode", "Play trailers?")
if not resp: if not resp:
# User selected to not play trailers # User selected to not play trailers
getTrailers = False getTrailers = False
self.logMsg("Skip trailers.", 1) self.logMsg("Skip trailers.", 1)
if getTrailers: if getTrailers:
for i in range(0, playListSize - 1): for intro in intros['Items']:
# The server randomly returns intros, process them # The server randomly returns intros, process them.
# Set the child in XML Plex response to a trailer
API.setChildNumber(i)
introListItem = xbmcgui.ListItem() introListItem = xbmcgui.ListItem()
introPlayurl = playutils.getPlayUrl(child=i) introPlayurl = putils.PlayUtils(intro).getPlayUrl()
self.logMsg("Adding Trailer: %s" % introPlayurl, 1) self.logMsg("Adding Intro: %s" % introPlayurl, 1)
# Set listitem and properties for intros # Set listitem and properties for intros
self.setProperties(introPlayurl, introListItem) pbutils = PlaybackUtils(intro)
pbutils.setProperties(introPlayurl, introListItem)
self.pl.insertintoPlaylist(currentPosition, url=introPlayurl) self.pl.insertintoPlaylist(currentPosition, url=introPlayurl)
introsPlaylist = True introsPlaylist = True
currentPosition += 1 currentPosition += 1
self.logMsg("Key: %s" % API.getRatingKey(), 1)
self.logMsg("Successfally added trailer number %s" % i, 1)
# Set "working point" to the movie (last one in playlist)
API.setChildNumber(-1)
############### -- ADD MAIN ITEM ONLY FOR HOMESCREEN ############### ############### -- ADD MAIN ITEM ONLY FOR HOMESCREEN ###############
@ -252,37 +262,32 @@ class PlaybackUtils():
# Extend our current playlist with the actual item to play # Extend our current playlist with the actual item to play
# only if there's no playlist first # only if there's no playlist first
self.logMsg("Adding main item to playlist.", 1) self.logMsg("Adding main item to playlist.", 1)
# self.pl.addtoPlaylist(dbid, item['Type'].lower()) self.pl.addtoPlaylist(dbid, item['Type'].lower())
self.pl.addtoPlaylist(dbid, item[-1].attrib['type'].lower())
# Ensure that additional parts are played after the main item # Ensure that additional parts are played after the main item
currentPosition += 1 currentPosition += 1
############### -- CHECK FOR ADDITIONAL PARTS ################ ############### -- CHECK FOR ADDITIONAL PARTS ################
parts = API.GetParts()
partcount = len(parts) if item.get('PartCount'):
if partcount > 1:
# Only add to the playlist after intros have played # Only add to the playlist after intros have played
partsPlaylist = True partcount = item['PartCount']
i = 0 url = "{server}/emby/Videos/%s/AdditionalParts?format=json" % itemid
for part in parts: parts = doUtils.downloadUrl(url)
API.setPartNumber(i) for part in parts['Items']:
additionalListItem = xbmcgui.ListItem() additionalListItem = xbmcgui.ListItem()
additionalPlayurl = playutils.getPlayUrl( additionalPlayurl = putils.PlayUtils(part).getPlayUrl()
child=-1, self.logMsg("Adding additional part: %s" % partcount, 1)
partIndex=i)
self.logMsg("Adding additional part: %s" % i, 1)
# Set listitem and properties for each additional parts # Set listitem and properties for each additional parts
pbutils = PlaybackUtils(item) pbutils = PlaybackUtils(part)
pbutils.setProperties(additionalPlayurl, additionalListItem) pbutils.setProperties(additionalPlayurl, additionalListItem)
pbutils.setArtwork(additionalListItem) pbutils.setArtwork(additionalListItem)
playlist.add(additionalPlayurl, additionalListItem, index=currentPosition) playlist.add(additionalPlayurl, additionalListItem, index=currentPosition)
self.pl.verifyPlaylist() self.pl.verifyPlaylist()
currentPosition += 1 currentPosition += 1
i += 1
API.setPartNumber(0)
if dummyPlaylist: if dummyPlaylist:
# Added a dummy file to the playlist, # Added a dummy file to the playlist,
@ -301,22 +306,21 @@ class PlaybackUtils():
# For transcoding only, ask for audio/subs pref # For transcoding only, ask for audio/subs pref
if utils.window('emby_%s.playmethod' % playurl) == "Transcode": if utils.window('emby_%s.playmethod' % playurl) == "Transcode":
playurl = playutils.audioSubsPref(playurl, listitem, child=self.API.getChildNumber()) playurl = playutils.audioSubsPref(playurl, listitem)
utils.window('emby_%s.playmethod' % playurl, value="Transcode") utils.window('emby_%s.playmethod' % playurl, value="Transcode")
listitem.setPath(playurl) listitem.setPath(playurl)
self.setProperties(playurl, listitem) self.setProperties(playurl, listitem)
############### PLAYBACK ################ ############### PLAYBACK ################
customPlaylist = utils.window('emby_customPlaylist')
if homeScreen and seektime: if homeScreen and seektime:
self.logMsg("Play as a widget item.", 1) self.logMsg("Play as a widget item.", 1)
self.setListItem(listitem) self.setListItem(listitem)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
elif ((introsPlaylist and customPlaylist == "true") or elif ((introsPlaylist and utils.window('emby_customPlaylist') == "true") or
(homeScreen and not sizePlaylist) or (homeScreen and not sizePlaylist)):
(partsPlaylist and customPlaylist == "true")):
# Playlist was created just now, play it. # Playlist was created just now, play it.
self.logMsg("Play playlist.", 1) self.logMsg("Play playlist.", 1)
xbmc.Player().play(playlist, startpos=startPos) xbmc.Player().play(playlist, startpos=startPos)

View file

@ -34,9 +34,7 @@ class PlayUtils():
Returns a list of playurls, one per part in item Returns a list of playurls, one per part in item
""" """
playurls = [] playurls = []
# TODO: multiple media parts for e.g. trailers: replace [0] here for partNumber, part in enumerate(self.item[0]):
partCount = len(self.item['_children'][0]['_children'])
for partNumber in range(partCount):
playurl = None playurl = None
self.API.setPartNumber(partNumber) self.API.setPartNumber(partNumber)

View file

@ -140,6 +140,25 @@ def logging(cls):
return cls return cls
def XMLAtt(xml, key):
try:
result = xml.attrib['key']
except KeyError:
result = ''
return result
def IntFromStr(string):
"""
Returns an int from string or the int 0 if something happened
"""
try:
result = int(string)
except:
result = 0
return result
def getUnixTimestamp(secondsIntoTheFuture=None): def getUnixTimestamp(secondsIntoTheFuture=None):
""" """
Returns a Unix time stamp (seconds passed since January 1 1970) for NOW as Returns a Unix time stamp (seconds passed since January 1 1970) for NOW as