More fixes to Watch Later

This commit is contained in:
tomkat83 2017-01-02 16:42:07 +01:00
parent 5b9b432ca9
commit 06bd8856b5
5 changed files with 35 additions and 17 deletions

View file

@ -159,7 +159,9 @@ class Main():
elif mode == "companion":
modes[mode](itemid, params=ARGV[2])
elif mode == 'Plex_Node':
modes[mode](params.get('id'), params.get('viewOffset'))
modes[mode](params.get('id'),
params.get('viewOffset'),
params.get('plex_type'))
else:
modes[mode]()
else:

View file

@ -79,9 +79,10 @@ class PlexCompanion(Thread):
data.get('address') == 'node.plexapp.com'):
# E.g. watch later initiated by Companion
thread = Thread(target=Plex_Node,
args=(data.get('key'),
args=('{server}%s' % data.get('key'),
data.get('offset'),
data.get('type')))
data.get('type'),
True),)
thread.setDaemon(True)
thread.start()
elif task['action'] == 'playlist':

View file

@ -61,6 +61,7 @@ KODITYPE_FROM_PLEXTYPE = {
}
KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE = {
'video': 'video',
'movie': 'video',
'episode': 'video',
'season': 'video',

View file

@ -22,7 +22,7 @@ import playbackutils as pbutils
import PlexFunctions
import PlexAPI
from playqueue import Playqueue
from PKC_listitem import convert_PKC_to_listitem
###############################################################################
@ -120,7 +120,7 @@ def PassPlaylist(xml, resume=None):
resumeId=xml.attrib.get('playQueueSelectedItemID', None))
def Plex_Node(url, viewOffset, playlist_type):
def Plex_Node(url, viewOffset, plex_type, playdirectly=False):
"""
Called only for a SINGLE element for Plex.tv watch later
@ -129,11 +129,12 @@ def Plex_Node(url, viewOffset, playlist_type):
log.info('Plex_Node called with url: %s, viewOffset: %s'
% (url, viewOffset))
# Plex redirect, e.g. watch later. Need to get actual URLs
xml = downloadutils.DownloadUtils().downloadUrl('{server}%s' % url)
if xml in (None, 401):
log.error("Could not resolve url %s" % url)
return xbmcplugin.setResolvedUrl(
int(sys.argv[1]), False, xbmcgui.ListItem())
xml = downloadutils.DownloadUtils().downloadUrl(url)
try:
xml[0].attrib
except:
log.error('Could not download PMS metadata')
return
if viewOffset != '0':
try:
viewOffset = int(PlexFunctions.PLEX_TO_KODI_TIMEFACTOR *
@ -143,9 +144,19 @@ def Plex_Node(url, viewOffset, playlist_type):
else:
window('plex_customplaylist.seektime', value=str(viewOffset))
log.info('Set resume point to %s' % str(viewOffset))
pbutils.PlaybackUtils(xml, playlist_type=playlist_type).play(
None, 'plexnode')
typus = PlexFunctions.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type]
result = pbutils.PlaybackUtils(xml[0],playlist_type=typus).play(
None,
kodi_id='plexnode',
plex_lib_UUID=xml.attrib.get('librarySectionUUID'))
if result.listitem:
listitem = convert_PKC_to_listitem(result.listitem)
else:
return
if playdirectly:
xbmc.Player().play(listitem.getfilename(), listitem)
else:
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
##### DO RESET AUTH #####
@ -1248,6 +1259,7 @@ def watchlater():
pbutils.PlaybackUtils(item).setArtwork(listitem)
params['id'] = item.attrib.get('key')
params['viewOffset'] = item.attrib.get('viewOffset', '0')
params['plex_type'] = item.attrib.get('type')
xbmcplugin.addDirectoryItem(
handle=int(sys.argv[1]),
url="%s?%s" % (url, urllib.urlencode(params)),

View file

@ -185,11 +185,11 @@ def get_playlist_details_from_xml(playlist, xml):
try:
playlist.ID = xml.attrib['%sID' % playlist.kind]
playlist.version = xml.attrib['%sVersion' % playlist.kind]
playlist.selectedItemID = xml.attrib['%sSelectedItemID'
% playlist.kind]
playlist.selectedItemOffset = xml.attrib['%sSelectedItemOffset'
% playlist.kind]
playlist.shuffled = xml.attrib['%sShuffled' % playlist.kind]
playlist.selectedItemID = xml.attrib.get(
'%sSelectedItemID' % playlist.kind)
playlist.selectedItemOffset = xml.attrib.get(
'%sSelectedItemOffset' % playlist.kind)
except:
log.error('Could not parse xml answer from PMS for playlist %s'
% playlist)
@ -309,6 +309,8 @@ def add_item_to_PMS_playlist(playlist, pos, plex_id=None, kodi_item=None):
xml = DU().downloadUrl(url, action_type="PUT")
try:
item.ID = xml[-1].attrib['%sItemID' % playlist.kind]
except IndexError:
log.info('Could not get playlist children. Adding a dummy')
except (TypeError, AttributeError, KeyError):
log.error('Could not add item %s to playlist %s'
% (kodi_item, playlist))