More fixes to Watch Later
This commit is contained in:
parent
5b9b432ca9
commit
06bd8856b5
5 changed files with 35 additions and 17 deletions
|
@ -159,7 +159,9 @@ class Main():
|
||||||
elif mode == "companion":
|
elif mode == "companion":
|
||||||
modes[mode](itemid, params=ARGV[2])
|
modes[mode](itemid, params=ARGV[2])
|
||||||
elif mode == 'Plex_Node':
|
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:
|
else:
|
||||||
modes[mode]()
|
modes[mode]()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -79,9 +79,10 @@ class PlexCompanion(Thread):
|
||||||
data.get('address') == 'node.plexapp.com'):
|
data.get('address') == 'node.plexapp.com'):
|
||||||
# E.g. watch later initiated by Companion
|
# E.g. watch later initiated by Companion
|
||||||
thread = Thread(target=Plex_Node,
|
thread = Thread(target=Plex_Node,
|
||||||
args=(data.get('key'),
|
args=('{server}%s' % data.get('key'),
|
||||||
data.get('offset'),
|
data.get('offset'),
|
||||||
data.get('type')))
|
data.get('type'),
|
||||||
|
True),)
|
||||||
thread.setDaemon(True)
|
thread.setDaemon(True)
|
||||||
thread.start()
|
thread.start()
|
||||||
elif task['action'] == 'playlist':
|
elif task['action'] == 'playlist':
|
||||||
|
|
|
@ -61,6 +61,7 @@ KODITYPE_FROM_PLEXTYPE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE = {
|
KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE = {
|
||||||
|
'video': 'video',
|
||||||
'movie': 'video',
|
'movie': 'video',
|
||||||
'episode': 'video',
|
'episode': 'video',
|
||||||
'season': 'video',
|
'season': 'video',
|
||||||
|
|
|
@ -22,7 +22,7 @@ import playbackutils as pbutils
|
||||||
|
|
||||||
import PlexFunctions
|
import PlexFunctions
|
||||||
import PlexAPI
|
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))
|
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
|
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'
|
log.info('Plex_Node called with url: %s, viewOffset: %s'
|
||||||
% (url, viewOffset))
|
% (url, viewOffset))
|
||||||
# Plex redirect, e.g. watch later. Need to get actual URLs
|
# Plex redirect, e.g. watch later. Need to get actual URLs
|
||||||
xml = downloadutils.DownloadUtils().downloadUrl('{server}%s' % url)
|
xml = downloadutils.DownloadUtils().downloadUrl(url)
|
||||||
if xml in (None, 401):
|
try:
|
||||||
log.error("Could not resolve url %s" % url)
|
xml[0].attrib
|
||||||
return xbmcplugin.setResolvedUrl(
|
except:
|
||||||
int(sys.argv[1]), False, xbmcgui.ListItem())
|
log.error('Could not download PMS metadata')
|
||||||
|
return
|
||||||
if viewOffset != '0':
|
if viewOffset != '0':
|
||||||
try:
|
try:
|
||||||
viewOffset = int(PlexFunctions.PLEX_TO_KODI_TIMEFACTOR *
|
viewOffset = int(PlexFunctions.PLEX_TO_KODI_TIMEFACTOR *
|
||||||
|
@ -143,9 +144,19 @@ def Plex_Node(url, viewOffset, playlist_type):
|
||||||
else:
|
else:
|
||||||
window('plex_customplaylist.seektime', value=str(viewOffset))
|
window('plex_customplaylist.seektime', value=str(viewOffset))
|
||||||
log.info('Set resume point to %s' % str(viewOffset))
|
log.info('Set resume point to %s' % str(viewOffset))
|
||||||
pbutils.PlaybackUtils(xml, playlist_type=playlist_type).play(
|
typus = PlexFunctions.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type]
|
||||||
None, 'plexnode')
|
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
|
return
|
||||||
|
if playdirectly:
|
||||||
|
xbmc.Player().play(listitem.getfilename(), listitem)
|
||||||
|
else:
|
||||||
|
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)
|
||||||
|
|
||||||
|
|
||||||
##### DO RESET AUTH #####
|
##### DO RESET AUTH #####
|
||||||
|
@ -1248,6 +1259,7 @@ def watchlater():
|
||||||
pbutils.PlaybackUtils(item).setArtwork(listitem)
|
pbutils.PlaybackUtils(item).setArtwork(listitem)
|
||||||
params['id'] = item.attrib.get('key')
|
params['id'] = item.attrib.get('key')
|
||||||
params['viewOffset'] = item.attrib.get('viewOffset', '0')
|
params['viewOffset'] = item.attrib.get('viewOffset', '0')
|
||||||
|
params['plex_type'] = item.attrib.get('type')
|
||||||
xbmcplugin.addDirectoryItem(
|
xbmcplugin.addDirectoryItem(
|
||||||
handle=int(sys.argv[1]),
|
handle=int(sys.argv[1]),
|
||||||
url="%s?%s" % (url, urllib.urlencode(params)),
|
url="%s?%s" % (url, urllib.urlencode(params)),
|
||||||
|
|
|
@ -185,11 +185,11 @@ def get_playlist_details_from_xml(playlist, xml):
|
||||||
try:
|
try:
|
||||||
playlist.ID = xml.attrib['%sID' % playlist.kind]
|
playlist.ID = xml.attrib['%sID' % playlist.kind]
|
||||||
playlist.version = xml.attrib['%sVersion' % 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.shuffled = xml.attrib['%sShuffled' % playlist.kind]
|
||||||
|
playlist.selectedItemID = xml.attrib.get(
|
||||||
|
'%sSelectedItemID' % playlist.kind)
|
||||||
|
playlist.selectedItemOffset = xml.attrib.get(
|
||||||
|
'%sSelectedItemOffset' % playlist.kind)
|
||||||
except:
|
except:
|
||||||
log.error('Could not parse xml answer from PMS for playlist %s'
|
log.error('Could not parse xml answer from PMS for playlist %s'
|
||||||
% playlist)
|
% 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")
|
xml = DU().downloadUrl(url, action_type="PUT")
|
||||||
try:
|
try:
|
||||||
item.ID = xml[-1].attrib['%sItemID' % playlist.kind]
|
item.ID = xml[-1].attrib['%sItemID' % playlist.kind]
|
||||||
|
except IndexError:
|
||||||
|
log.info('Could not get playlist children. Adding a dummy')
|
||||||
except (TypeError, AttributeError, KeyError):
|
except (TypeError, AttributeError, KeyError):
|
||||||
log.error('Could not add item %s to playlist %s'
|
log.error('Could not add item %s to playlist %s'
|
||||||
% (kodi_item, playlist))
|
% (kodi_item, playlist))
|
||||||
|
|
Loading…
Reference in a new issue