2015-12-25 07:07:00 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2016-02-20 06:03:06 +11:00
|
|
|
###############################################################################
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
import json
|
2016-08-30 23:51:11 +10:00
|
|
|
import logging
|
2015-12-25 07:07:00 +11:00
|
|
|
import os
|
|
|
|
import sys
|
2016-04-17 21:36:41 +10:00
|
|
|
import urllib
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcvfs
|
|
|
|
import xbmcplugin
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
from utils import window, settings, language as lang
|
|
|
|
from utils import tryDecode, tryEncode, CatchExceptions
|
2015-12-25 07:07:00 +11:00
|
|
|
import clientinfo
|
|
|
|
import downloadutils
|
2017-01-05 06:57:16 +11:00
|
|
|
import plexdb_functions as plexdb
|
2015-12-25 07:07:00 +11:00
|
|
|
import playbackutils as pbutils
|
|
|
|
|
2016-01-28 02:33:02 +11:00
|
|
|
import PlexFunctions
|
2016-03-15 03:47:05 +11:00
|
|
|
import PlexAPI
|
2017-01-03 02:42:07 +11:00
|
|
|
from PKC_listitem import convert_PKC_to_listitem
|
2017-01-10 05:56:57 +11:00
|
|
|
from playqueue import Playqueue
|
2016-01-02 00:40:40 +11:00
|
|
|
|
2016-02-20 06:03:06 +11:00
|
|
|
###############################################################################
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
log = logging.getLogger("PLEX."+__name__)
|
|
|
|
|
|
|
|
addonName = "PlexKodiConnect"
|
|
|
|
|
|
|
|
###############################################################################
|
2016-01-30 06:07:21 +11:00
|
|
|
|
|
|
|
|
2016-03-24 22:34:39 +11:00
|
|
|
def chooseServer():
|
|
|
|
"""
|
2016-05-30 00:52:00 +10:00
|
|
|
Lets user choose from list of PMS
|
2016-03-24 22:34:39 +11:00
|
|
|
"""
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("Choosing PMS server requested, starting")
|
2016-03-24 22:34:39 +11:00
|
|
|
|
|
|
|
import initialsetup
|
2016-05-25 04:43:52 +10:00
|
|
|
setup = initialsetup.InitialSetup()
|
2016-05-30 00:52:00 +10:00
|
|
|
server = setup.PickPMS(showDialog=True)
|
2016-05-25 04:43:52 +10:00
|
|
|
if server is None:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('We did not connect to a new PMS, aborting')
|
|
|
|
window('suspend_Userclient', clear=True)
|
|
|
|
window('suspend_LibraryThread', clear=True)
|
2016-05-25 04:43:52 +10:00
|
|
|
return
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("User chose server %s" % server['name'])
|
2016-05-25 04:43:52 +10:00
|
|
|
setup.WritePMStoSettings(server)
|
2016-03-24 22:34:39 +11:00
|
|
|
|
2016-05-30 01:36:07 +10:00
|
|
|
if not __LogOut():
|
2016-05-30 00:52:00 +10:00
|
|
|
return
|
2016-03-24 22:34:39 +11:00
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
from utils import deletePlaylists, deleteNodes
|
2016-05-30 01:17:33 +10:00
|
|
|
# First remove playlists
|
2016-08-30 23:51:11 +10:00
|
|
|
deletePlaylists()
|
2016-05-30 01:17:33 +10:00
|
|
|
# Remove video nodes
|
2016-08-30 23:51:11 +10:00
|
|
|
deleteNodes()
|
2016-05-30 01:17:33 +10:00
|
|
|
|
2016-05-30 00:52:00 +10:00
|
|
|
# Log in again
|
2016-05-30 01:36:07 +10:00
|
|
|
__LogIn()
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("Choosing new PMS complete")
|
2016-05-30 00:52:00 +10:00
|
|
|
# '<PMS> connected'
|
|
|
|
xbmcgui.Dialog().notification(
|
2016-03-08 19:20:06 +11:00
|
|
|
heading=addonName,
|
2016-08-30 23:51:11 +10:00
|
|
|
message='%s %s' % (server['name'], lang(39220)),
|
2016-03-08 19:20:06 +11:00
|
|
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
2016-03-24 22:34:39 +11:00
|
|
|
time=3000,
|
2016-03-08 19:20:06 +11:00
|
|
|
sound=False)
|
2016-03-24 02:07:09 +11:00
|
|
|
|
2016-03-24 22:34:39 +11:00
|
|
|
|
2016-05-30 00:52:00 +10:00
|
|
|
def togglePlexTV():
|
2016-08-30 23:51:11 +10:00
|
|
|
if settings('plexToken'):
|
|
|
|
log.info('Reseting plex.tv credentials in settings')
|
|
|
|
settings('plexLogin', value="")
|
|
|
|
settings('plexToken', value=""),
|
|
|
|
settings('plexid', value="")
|
|
|
|
settings('plexHomeSize', value="1")
|
|
|
|
settings('plexAvatar', value="")
|
|
|
|
settings('plex_status', value="Not logged in to plex.tv")
|
|
|
|
|
|
|
|
window('plex_token', clear=True)
|
|
|
|
window('plex_username', clear=True)
|
2016-05-30 00:52:00 +10:00
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info('Login to plex.tv')
|
2016-05-30 00:52:00 +10:00
|
|
|
import initialsetup
|
|
|
|
initialsetup.InitialSetup().PlexTVSignIn()
|
|
|
|
xbmcgui.Dialog().notification(
|
|
|
|
heading=addonName,
|
2016-08-30 23:51:11 +10:00
|
|
|
message=lang(39221),
|
2016-05-30 00:52:00 +10:00
|
|
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
|
|
|
time=3000,
|
|
|
|
sound=False)
|
2016-03-04 23:34:30 +11:00
|
|
|
|
|
|
|
|
2017-01-03 02:42:07 +11:00
|
|
|
def Plex_Node(url, viewOffset, plex_type, playdirectly=False):
|
2016-06-20 02:30:21 +10:00
|
|
|
"""
|
|
|
|
Called only for a SINGLE element for Plex.tv watch later
|
|
|
|
|
|
|
|
Always to return with a "setResolvedUrl"
|
|
|
|
"""
|
2017-01-03 01:41:38 +11:00
|
|
|
log.info('Plex_Node called with url: %s, viewOffset: %s'
|
|
|
|
% (url, viewOffset))
|
2016-06-20 02:30:21 +10:00
|
|
|
# Plex redirect, e.g. watch later. Need to get actual URLs
|
2017-01-03 02:42:07 +11:00
|
|
|
xml = downloadutils.DownloadUtils().downloadUrl(url)
|
|
|
|
try:
|
|
|
|
xml[0].attrib
|
|
|
|
except:
|
|
|
|
log.error('Could not download PMS metadata')
|
|
|
|
return
|
2016-06-20 02:53:45 +10:00
|
|
|
if viewOffset != '0':
|
|
|
|
try:
|
2016-10-30 00:23:48 +11:00
|
|
|
viewOffset = int(PlexFunctions.PLEX_TO_KODI_TIMEFACTOR *
|
2016-06-20 02:53:45 +10:00
|
|
|
float(viewOffset))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
window('plex_customplaylist.seektime', value=str(viewOffset))
|
|
|
|
log.info('Set resume point to %s' % str(viewOffset))
|
2017-01-03 02:42:07 +11:00
|
|
|
typus = PlexFunctions.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type]
|
2017-01-10 05:56:57 +11:00
|
|
|
playqueue = Playqueue().get_playqueue_from_type(typus)
|
|
|
|
result = pbutils.PlaybackUtils(xml, playqueue).play(
|
2017-01-03 02:42:07 +11:00
|
|
|
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)
|
2016-06-20 02:30:21 +10:00
|
|
|
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
##### DO RESET AUTH #####
|
|
|
|
def resetAuth():
|
|
|
|
# User tried login and failed too many times
|
|
|
|
resp = xbmcgui.Dialog().yesno(
|
2016-03-04 00:00:48 +11:00
|
|
|
heading="Warning",
|
2016-08-30 23:55:57 +10:00
|
|
|
line1=lang(39206))
|
2015-12-25 07:07:00 +11:00
|
|
|
if resp == 1:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("Reset login attempts.")
|
|
|
|
window('plex_serverStatus', value="Auth")
|
2015-12-25 07:07:00 +11:00
|
|
|
else:
|
2015-12-27 21:49:14 +11:00
|
|
|
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
2016-08-30 23:51:11 +10:00
|
|
|
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
def addDirectoryItem(label, path, folder=True):
|
|
|
|
li = xbmcgui.ListItem(label, path=path)
|
2015-12-27 21:49:14 +11:00
|
|
|
li.setThumbnailImage("special://home/addons/plugin.video.plexkodiconnect/icon.png")
|
|
|
|
li.setArt({"fanart":"special://home/addons/plugin.video.plexkodiconnect/fanart.jpg"})
|
|
|
|
li.setArt({"landscape":"special://home/addons/plugin.video.plexkodiconnect/fanart.jpg"})
|
2015-12-25 07:07:00 +11:00
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=path, listitem=li, isFolder=folder)
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
def doMainListing():
|
2016-08-30 23:51:11 +10:00
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'files')
|
2015-12-25 07:07:00 +11:00
|
|
|
# Get emby nodes from the window props
|
2016-08-30 23:51:11 +10:00
|
|
|
plexprops = window('Plex.nodes.total')
|
2016-05-31 16:06:42 +10:00
|
|
|
if plexprops:
|
|
|
|
totalnodes = int(plexprops)
|
2015-12-25 07:07:00 +11:00
|
|
|
for i in range(totalnodes):
|
2016-08-30 23:51:11 +10:00
|
|
|
path = window('Plex.nodes.%s.index' % i)
|
2015-12-25 07:07:00 +11:00
|
|
|
if not path:
|
2016-08-30 23:51:11 +10:00
|
|
|
path = window('Plex.nodes.%s.content' % i)
|
|
|
|
label = window('Plex.nodes.%s.title' % i)
|
|
|
|
node_type = window('Plex.nodes.%s.type' % i)
|
2016-01-18 19:45:39 +11:00
|
|
|
#because we do not use seperate entrypoints for each content type, we need to figure out which items to show in each listing.
|
2016-01-22 21:10:42 +11:00
|
|
|
#for now we just only show picture nodes in the picture library video nodes in the video library and all nodes in any other window
|
2016-04-26 21:53:19 +10:00
|
|
|
if path and xbmc.getCondVisibility("Window.IsActive(Pictures)") and node_type == "photos":
|
2015-12-25 07:07:00 +11:00
|
|
|
addDirectoryItem(label, path)
|
2016-04-26 21:53:19 +10:00
|
|
|
elif path and xbmc.getCondVisibility("Window.IsActive(VideoLibrary)") and node_type != "photos":
|
2016-01-19 06:48:44 +11:00
|
|
|
addDirectoryItem(label, path)
|
|
|
|
elif path and not xbmc.getCondVisibility("Window.IsActive(VideoLibrary) | Window.IsActive(Pictures) | Window.IsActive(MusicLibrary)"):
|
2015-12-25 07:07:00 +11:00
|
|
|
addDirectoryItem(label, path)
|
2016-01-20 07:27:58 +11:00
|
|
|
|
2016-04-17 21:36:41 +10:00
|
|
|
# Plex Watch later
|
2016-08-30 23:51:11 +10:00
|
|
|
addDirectoryItem(lang(39211),
|
2016-04-17 21:36:41 +10:00
|
|
|
"plugin://plugin.video.plexkodiconnect/?mode=watchlater")
|
2016-03-11 02:04:01 +11:00
|
|
|
# Plex user switch
|
2016-08-30 23:51:11 +10:00
|
|
|
addDirectoryItem(lang(39200) + window('plex_username'),
|
2016-03-11 02:04:01 +11:00
|
|
|
"plugin://plugin.video.plexkodiconnect/"
|
|
|
|
"?mode=switchuser")
|
2016-01-25 20:36:24 +11:00
|
|
|
|
2016-01-20 07:27:58 +11:00
|
|
|
#experimental live tv nodes
|
2016-03-03 20:11:32 +11:00
|
|
|
# addDirectoryItem("Live Tv Channels (experimental)", "plugin://plugin.video.plexkodiconnect/?mode=browsecontent&type=tvchannels&folderid=root")
|
|
|
|
# addDirectoryItem("Live Tv Recordings (experimental)", "plugin://plugin.video.plexkodiconnect/?mode=browsecontent&type=recordings&folderid=root")
|
2016-01-20 07:27:58 +11:00
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
# some extra entries for settings and stuff. TODO --> localize the labels
|
2016-08-30 23:51:11 +10:00
|
|
|
addDirectoryItem(lang(39201), "plugin://plugin.video.plexkodiconnect/?mode=settings")
|
2016-03-03 20:11:32 +11:00
|
|
|
# addDirectoryItem("Add user to session", "plugin://plugin.video.plexkodiconnect/?mode=adduser")
|
2016-08-30 23:51:11 +10:00
|
|
|
addDirectoryItem(lang(39203), "plugin://plugin.video.plexkodiconnect/?mode=refreshplaylist")
|
|
|
|
addDirectoryItem(lang(39204), "plugin://plugin.video.plexkodiconnect/?mode=manualsync")
|
2015-12-25 07:07:00 +11:00
|
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
|
|
|
2016-02-29 16:20:59 +11:00
|
|
|
|
|
|
|
##### Generate a new deviceId
|
|
|
|
def resetDeviceId():
|
|
|
|
|
|
|
|
dialog = xbmcgui.Dialog()
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
deviceId_old = window('plex_client_Id')
|
2016-02-29 16:20:59 +11:00
|
|
|
try:
|
|
|
|
deviceId = clientinfo.ClientInfo().getDeviceId(reset=True)
|
|
|
|
except Exception as e:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error("Failed to generate a new device Id: %s" % e)
|
|
|
|
dialog.ok(heading=addonName, line1=lang(33032))
|
2016-02-29 16:20:59 +11:00
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("Successfully removed old deviceId: %s New deviceId: %s"
|
|
|
|
% (deviceId_old, deviceId))
|
2016-06-12 20:56:06 +10:00
|
|
|
# "Kodi will now restart to apply the changes"
|
2016-08-30 23:51:11 +10:00
|
|
|
dialog.ok(heading=addonName, line1=lang(33033))
|
2016-02-29 16:20:59 +11:00
|
|
|
xbmc.executebuiltin('RestartApp')
|
|
|
|
|
2016-03-10 10:05:35 +11:00
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
def deleteItem():
|
2016-03-10 10:05:35 +11:00
|
|
|
# Serves as a keymap action
|
2016-08-30 23:51:11 +10:00
|
|
|
if xbmc.getInfoLabel('ListItem.Property(plexid)'):
|
|
|
|
# If we already have the plexid
|
2016-05-31 16:06:42 +10:00
|
|
|
plexid = xbmc.getInfoLabel('ListItem.Property(plexid)')
|
2016-03-10 10:05:35 +11:00
|
|
|
else:
|
2016-03-10 13:15:45 +11:00
|
|
|
dbid = xbmc.getInfoLabel('ListItem.DBID')
|
|
|
|
itemtype = xbmc.getInfoLabel('ListItem.DBTYPE')
|
|
|
|
|
|
|
|
if not itemtype:
|
|
|
|
|
|
|
|
if xbmc.getCondVisibility('Container.Content(albums)'):
|
|
|
|
itemtype = "album"
|
|
|
|
elif xbmc.getCondVisibility('Container.Content(artists)'):
|
|
|
|
itemtype = "artist"
|
|
|
|
elif xbmc.getCondVisibility('Container.Content(songs)'):
|
|
|
|
itemtype = "song"
|
|
|
|
elif xbmc.getCondVisibility('Container.Content(pictures)'):
|
|
|
|
itemtype = "picture"
|
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error("Unknown type, unable to proceed.")
|
2016-03-10 13:15:45 +11:00
|
|
|
return
|
|
|
|
|
2017-01-05 06:57:16 +11:00
|
|
|
with plexdb.Get_Plex_DB() as plexcursor:
|
|
|
|
item = plexcursor.getItem_byKodiId(dbid, itemtype)
|
2016-03-10 10:05:35 +11:00
|
|
|
|
|
|
|
try:
|
2016-05-31 16:06:42 +10:00
|
|
|
plexid = item[0]
|
2016-03-10 10:05:35 +11:00
|
|
|
except TypeError:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error("Unknown plexid, unable to proceed.")
|
2016-03-10 10:05:35 +11:00
|
|
|
return
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
if settings('skipContextMenu') != "true":
|
2016-03-10 10:05:35 +11:00
|
|
|
resp = xbmcgui.Dialog().yesno(
|
|
|
|
heading="Confirm delete",
|
|
|
|
line1=("Delete file from Emby Server? This will "
|
|
|
|
"also delete the file(s) from disk!"))
|
|
|
|
if not resp:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.debug("User skipped deletion for: %s." % plexid)
|
2016-03-10 10:05:35 +11:00
|
|
|
return
|
|
|
|
doUtils = downloadutils.DownloadUtils()
|
2016-05-31 16:06:42 +10:00
|
|
|
url = "{server}/emby/Items/%s?format=json" % plexid
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("Deleting request: %s" % plexid)
|
2016-04-26 21:53:19 +10:00
|
|
|
doUtils.downloadUrl(url, action_type="DELETE")
|
2016-03-10 10:05:35 +11:00
|
|
|
|
2016-01-25 20:36:24 +11:00
|
|
|
|
|
|
|
def switchPlexUser():
|
|
|
|
"""
|
|
|
|
Signs out currently logged in user (if applicable). Triggers sign-in of a
|
|
|
|
new user
|
|
|
|
"""
|
|
|
|
# Guess these user avatars are a future feature. Skipping for now
|
|
|
|
# Delete any userimages. Since there's always only 1 user: position = 0
|
|
|
|
# position = 0
|
2016-08-30 23:51:11 +10:00
|
|
|
# window('EmbyAdditionalUserImage.%s' % position, clear=True)
|
|
|
|
log.info("Plex home user switch requested")
|
2016-05-30 01:36:07 +10:00
|
|
|
if not __LogOut():
|
2016-05-30 00:52:00 +10:00
|
|
|
return
|
2016-03-10 01:53:46 +11:00
|
|
|
|
2016-05-30 00:52:00 +10:00
|
|
|
# First remove playlists of old user
|
2016-08-30 23:51:11 +10:00
|
|
|
from utils import deletePlaylists, deleteNodes
|
|
|
|
deletePlaylists()
|
2016-04-08 00:13:02 +10:00
|
|
|
# Remove video nodes
|
2016-08-30 23:51:11 +10:00
|
|
|
deleteNodes()
|
2016-05-30 00:52:00 +10:00
|
|
|
__LogIn()
|
2016-01-25 20:36:24 +11:00
|
|
|
|
|
|
|
|
2015-12-26 20:42:13 +11:00
|
|
|
##### REFRESH EMBY PLAYLISTS #####
|
|
|
|
def refreshPlaylist():
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info('Requesting playlist/nodes refresh')
|
|
|
|
window('plex_runLibScan', value="views")
|
2015-12-26 20:42:13 +11:00
|
|
|
|
|
|
|
|
2016-01-22 21:10:42 +11:00
|
|
|
#### SHOW SUBFOLDERS FOR NODE #####
|
|
|
|
def GetSubFolders(nodeindex):
|
|
|
|
nodetypes = ["",".recent",".recentepisodes",".inprogress",".inprogressepisodes",".unwatched",".nextepisodes",".sets",".genres",".random",".recommended"]
|
|
|
|
for node in nodetypes:
|
2016-08-30 23:51:11 +10:00
|
|
|
title = window('Plex.nodes.%s%s.title' %(nodeindex,node))
|
2016-01-22 21:10:42 +11:00
|
|
|
if title:
|
2016-08-30 23:51:11 +10:00
|
|
|
path = window('Plex.nodes.%s%s.content' %(nodeindex,node))
|
2016-01-22 21:10:42 +11:00
|
|
|
addDirectoryItem(title, path)
|
|
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
|
|
|
2016-01-20 07:27:58 +11:00
|
|
|
##### BROWSE EMBY NODES DIRECTLY #####
|
2016-04-26 21:53:19 +10:00
|
|
|
def BrowseContent(viewname, browse_type="", folderid=""):
|
|
|
|
|
2016-01-12 08:20:34 +11:00
|
|
|
emby = embyserver.Read_EmbyServer()
|
2016-01-20 07:27:58 +11:00
|
|
|
art = artwork.Artwork()
|
|
|
|
doUtils = downloadutils.DownloadUtils()
|
2016-01-22 21:10:42 +11:00
|
|
|
|
|
|
|
#folderid used as filter ?
|
2016-03-15 23:09:51 +11:00
|
|
|
if folderid in ["recent","recentepisodes","inprogress","inprogressepisodes","unwatched","nextepisodes","sets","genres","random","recommended"]:
|
2016-04-26 21:53:19 +10:00
|
|
|
filter_type = folderid
|
2016-01-22 21:10:42 +11:00
|
|
|
folderid = ""
|
|
|
|
else:
|
2016-04-26 21:53:19 +10:00
|
|
|
filter_type = ""
|
2016-01-22 21:10:42 +11:00
|
|
|
|
2016-01-13 11:03:35 +11:00
|
|
|
xbmcplugin.setPluginCategory(int(sys.argv[1]), viewname)
|
|
|
|
#get views for root level
|
2016-01-12 08:20:34 +11:00
|
|
|
if not folderid:
|
2016-03-15 03:47:05 +11:00
|
|
|
views = PlexFunctions.GetPlexCollections()
|
2016-01-12 08:20:34 +11:00
|
|
|
for view in views:
|
2016-08-30 23:51:11 +10:00
|
|
|
if view.get("name") == tryDecode(viewname):
|
2016-01-12 08:20:34 +11:00
|
|
|
folderid = view.get("id")
|
2016-04-26 21:53:19 +10:00
|
|
|
break
|
2016-08-30 23:51:11 +10:00
|
|
|
|
2016-04-26 21:53:19 +10:00
|
|
|
if viewname is not None:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("viewname: %s - type: %s - folderid: %s - filter: %s"
|
|
|
|
% (tryDecode(viewname),
|
|
|
|
tryDecode(browse_type),
|
|
|
|
tryDecode(folderid),
|
|
|
|
tryDecode(filter_type)))
|
2016-01-13 11:03:35 +11:00
|
|
|
#set the correct params for the content type
|
|
|
|
#only proceed if we have a folderid
|
2016-01-12 08:20:34 +11:00
|
|
|
if folderid:
|
2016-04-26 21:53:19 +10:00
|
|
|
if browse_type.lower() == "homevideos":
|
2016-01-13 11:03:35 +11:00
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
|
|
|
itemtype = "Video,Folder,PhotoAlbum"
|
2016-04-26 21:53:19 +10:00
|
|
|
elif browse_type.lower() == "photos":
|
2016-01-13 11:03:35 +11:00
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'files')
|
2016-03-05 10:20:24 +11:00
|
|
|
itemtype = "Photo,PhotoAlbum,Folder"
|
2016-01-13 11:03:35 +11:00
|
|
|
else:
|
|
|
|
itemtype = ""
|
|
|
|
|
|
|
|
#get the actual listing
|
2016-04-26 21:53:19 +10:00
|
|
|
if browse_type == "recordings":
|
2016-01-20 07:27:58 +11:00
|
|
|
listing = emby.getTvRecordings(folderid)
|
2016-04-26 21:53:19 +10:00
|
|
|
elif browse_type == "tvchannels":
|
2016-01-20 07:27:58 +11:00
|
|
|
listing = emby.getTvChannels()
|
2016-04-26 21:53:19 +10:00
|
|
|
elif filter_type == "recent":
|
2016-01-22 21:10:42 +11:00
|
|
|
listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[0], sortby="DateCreated", recursive=True, limit=25, sortorder="Descending")
|
2016-04-26 21:53:19 +10:00
|
|
|
elif filter_type == "random":
|
2016-01-22 21:10:42 +11:00
|
|
|
listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[0], sortby="Random", recursive=True, limit=150, sortorder="Descending")
|
2016-04-26 21:53:19 +10:00
|
|
|
elif filter_type == "recommended":
|
|
|
|
listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[0], sortby="SortName", recursive=True, limit=25, sortorder="Ascending", filter_type="IsFavorite")
|
|
|
|
elif filter_type == "sets":
|
|
|
|
listing = emby.getFilteredSection(folderid, itemtype=itemtype.split(",")[1], sortby="SortName", recursive=True, limit=25, sortorder="Ascending", filter_type="IsFavorite")
|
2016-01-13 11:03:35 +11:00
|
|
|
else:
|
2016-01-13 11:26:07 +11:00
|
|
|
listing = emby.getFilteredSection(folderid, itemtype=itemtype, recursive=False)
|
2016-01-13 11:03:35 +11:00
|
|
|
|
|
|
|
#process the listing
|
2016-01-13 11:26:07 +11:00
|
|
|
if listing:
|
|
|
|
for item in listing.get("Items"):
|
2016-01-20 07:27:58 +11:00
|
|
|
li = createListItemFromEmbyItem(item,art,doUtils)
|
2016-01-13 11:26:07 +11:00
|
|
|
if item.get("IsFolder") == True:
|
|
|
|
#for folders we add an additional browse request, passing the folderId
|
2016-05-07 21:15:02 +10:00
|
|
|
path = "%s?id=%s&mode=browsecontent&type=%s&folderid=%s" \
|
2016-08-30 23:51:11 +10:00
|
|
|
% (tryDecode(sys.argv[0]),
|
|
|
|
tryDecode(viewname),
|
|
|
|
tryDecode(browse_type),
|
|
|
|
tryDecode(item.get("Id")))
|
2016-01-13 11:26:07 +11:00
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=path, listitem=li, isFolder=True)
|
|
|
|
else:
|
|
|
|
#playable item, set plugin path and mediastreams
|
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=li.getProperty("path"), listitem=li)
|
2016-01-12 08:20:34 +11:00
|
|
|
|
|
|
|
|
2016-04-26 21:53:19 +10:00
|
|
|
if filter_type == "recent":
|
2016-01-13 11:03:35 +11:00
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
|
|
|
|
else:
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE)
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RATING)
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
|
|
|
|
|
2016-03-04 20:00:25 +11:00
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
##### BROWSE EMBY CHANNELS #####
|
|
|
|
def BrowseChannels(itemid, folderid=None):
|
|
|
|
|
|
|
|
_addon_id = int(sys.argv[1])
|
|
|
|
_addon_url = sys.argv[0]
|
|
|
|
doUtils = downloadutils.DownloadUtils()
|
|
|
|
art = artwork.Artwork()
|
|
|
|
|
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'files')
|
|
|
|
if folderid:
|
|
|
|
url = (
|
|
|
|
"{server}/emby/Channels/%s/Items?userid={UserId}&folderid=%s&format=json"
|
|
|
|
% (itemid, folderid))
|
|
|
|
elif itemid == "0":
|
|
|
|
# id 0 is the root channels folder
|
|
|
|
url = "{server}/emby/Channels?{UserId}&format=json"
|
|
|
|
else:
|
|
|
|
url = "{server}/emby/Channels/%s/Items?UserId={UserId}&format=json" % itemid
|
|
|
|
|
|
|
|
result = doUtils.downloadUrl(url)
|
2016-01-20 07:27:58 +11:00
|
|
|
if result and result.get("Items"):
|
|
|
|
for item in result.get("Items"):
|
2015-12-25 07:07:00 +11:00
|
|
|
itemid = item['Id']
|
|
|
|
itemtype = item['Type']
|
2016-01-20 07:27:58 +11:00
|
|
|
li = createListItemFromEmbyItem(item,art,doUtils)
|
2016-04-05 20:02:15 +10:00
|
|
|
if itemtype == "ChannelFolderItem":
|
|
|
|
isFolder = True
|
|
|
|
else:
|
|
|
|
isFolder = False
|
2015-12-25 07:07:00 +11:00
|
|
|
channelId = item.get('ChannelId', "")
|
|
|
|
channelName = item.get('ChannelName', "")
|
|
|
|
if itemtype == "Channel":
|
|
|
|
path = "%s?id=%s&mode=channels" % (_addon_url, itemid)
|
|
|
|
xbmcplugin.addDirectoryItem(handle=_addon_id, url=path, listitem=li, isFolder=True)
|
|
|
|
elif isFolder:
|
|
|
|
path = "%s?id=%s&mode=channelsfolder&folderid=%s" % (_addon_url, channelId, itemid)
|
|
|
|
xbmcplugin.addDirectoryItem(handle=_addon_id, url=path, listitem=li, isFolder=True)
|
|
|
|
else:
|
|
|
|
path = "%s?id=%s&mode=play" % (_addon_url, itemid)
|
|
|
|
li.setProperty('IsPlayable', 'true')
|
|
|
|
xbmcplugin.addDirectoryItem(handle=_addon_id, url=path, listitem=li)
|
|
|
|
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
|
|
|
|
##### LISTITEM SETUP FOR VIDEONODES #####
|
2016-04-27 18:37:24 +10:00
|
|
|
def createListItem(item, appendShowTitle=False, appendSxxExx=False):
|
2015-12-25 07:07:00 +11:00
|
|
|
title = item['title']
|
|
|
|
li = xbmcgui.ListItem(title)
|
|
|
|
li.setProperty('IsPlayable', "true")
|
|
|
|
|
2016-04-27 18:37:24 +10:00
|
|
|
metadata = {
|
2015-12-25 07:07:00 +11:00
|
|
|
'duration': str(item['runtime']/60),
|
|
|
|
'Plot': item['plot'],
|
|
|
|
'Playcount': item['playcount']
|
|
|
|
}
|
|
|
|
|
|
|
|
if "episode" in item:
|
|
|
|
episode = item['episode']
|
|
|
|
metadata['Episode'] = episode
|
|
|
|
|
|
|
|
if "season" in item:
|
|
|
|
season = item['season']
|
|
|
|
metadata['Season'] = season
|
|
|
|
|
|
|
|
if season and episode:
|
|
|
|
li.setProperty('episodeno', "s%.2de%.2d" % (season, episode))
|
2016-04-27 18:37:24 +10:00
|
|
|
if appendSxxExx is True:
|
|
|
|
title = "S%.2dE%.2d - %s" % (season, episode, title)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if "firstaired" in item:
|
|
|
|
metadata['Premiered'] = item['firstaired']
|
|
|
|
|
|
|
|
if "showtitle" in item:
|
|
|
|
metadata['TVshowTitle'] = item['showtitle']
|
2016-04-27 18:37:24 +10:00
|
|
|
if appendShowTitle is True:
|
|
|
|
title = item['showtitle'] + ' - ' + title
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if "rating" in item:
|
|
|
|
metadata['Rating'] = str(round(float(item['rating']),1))
|
|
|
|
|
|
|
|
if "director" in item:
|
|
|
|
metadata['Director'] = " / ".join(item['director'])
|
|
|
|
|
|
|
|
if "writer" in item:
|
|
|
|
metadata['Writer'] = " / ".join(item['writer'])
|
|
|
|
|
|
|
|
if "cast" in item:
|
|
|
|
cast = []
|
|
|
|
castandrole = []
|
|
|
|
for person in item['cast']:
|
|
|
|
name = person['name']
|
|
|
|
cast.append(name)
|
|
|
|
castandrole.append((name, person['role']))
|
|
|
|
metadata['Cast'] = cast
|
|
|
|
metadata['CastAndRole'] = castandrole
|
|
|
|
|
2016-04-27 18:37:24 +10:00
|
|
|
metadata['Title'] = title
|
|
|
|
li.setLabel(title)
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
li.setInfo(type="Video", infoLabels=metadata)
|
|
|
|
li.setProperty('resumetime', str(item['resume']['position']))
|
|
|
|
li.setProperty('totaltime', str(item['resume']['total']))
|
|
|
|
li.setArt(item['art'])
|
|
|
|
li.setThumbnailImage(item['art'].get('thumb',''))
|
2017-01-03 00:07:24 +11:00
|
|
|
li.setArt({'icon': 'DefaultTVShows.png'})
|
2015-12-25 07:07:00 +11:00
|
|
|
li.setProperty('dbid', str(item['episodeid']))
|
|
|
|
li.setProperty('fanart_image', item['art'].get('tvshow.fanart',''))
|
|
|
|
for key, value in item['streamdetails'].iteritems():
|
|
|
|
for stream in value:
|
|
|
|
li.addStreamInfo(key, stream)
|
|
|
|
|
|
|
|
return li
|
|
|
|
|
|
|
|
##### GET NEXTUP EPISODES FOR TAGNAME #####
|
|
|
|
def getNextUpEpisodes(tagname, limit):
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
# if the addon is called with nextup parameter,
|
|
|
|
# we return the nextepisodes list of the given tagname
|
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
|
|
|
# First we get a list of all the TV shows - filtered by tag
|
|
|
|
query = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': "libTvShows",
|
|
|
|
'method': "VideoLibrary.GetTVShows",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'sort': {'order': "descending", 'method': "lastplayed"},
|
|
|
|
'filter': {
|
|
|
|
'and': [
|
|
|
|
{'operator': "true", 'field': "inprogress", 'value': ""},
|
2016-02-06 07:30:32 +11:00
|
|
|
{'operator': "is", 'field': "tag", 'value': "%s" % tagname}
|
2015-12-25 07:07:00 +11:00
|
|
|
]},
|
|
|
|
'properties': ['title', 'studio', 'mpaa', 'file', 'art']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
# If we found any, find the oldest unwatched show for each one.
|
|
|
|
try:
|
|
|
|
items = result['result']['tvshows']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for item in items:
|
2016-08-30 23:51:11 +10:00
|
|
|
if settings('ignoreSpecialsNextEpisodes') == "true":
|
2015-12-25 07:07:00 +11:00
|
|
|
query = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "VideoLibrary.GetEpisodes",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'tvshowid': item['tvshowid'],
|
|
|
|
'sort': {'method': "episode"},
|
|
|
|
'filter': {
|
|
|
|
'and': [
|
|
|
|
{'operator': "lessthan", 'field': "playcount", 'value': "1"},
|
|
|
|
{'operator': "greaterthan", 'field': "season", 'value': "0"}
|
|
|
|
]},
|
|
|
|
'properties': [
|
|
|
|
"title", "playcount", "season", "episode", "showtitle",
|
|
|
|
"plot", "file", "rating", "resume", "tvshowid", "art",
|
|
|
|
"streamdetails", "firstaired", "runtime", "writer",
|
|
|
|
"dateadded", "lastplayed"
|
|
|
|
],
|
|
|
|
'limits': {"end": 1}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
query = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "VideoLibrary.GetEpisodes",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'tvshowid': item['tvshowid'],
|
|
|
|
'sort': {'method': "episode"},
|
|
|
|
'filter': {'operator': "lessthan", 'field': "playcount", 'value': "1"},
|
|
|
|
'properties': [
|
|
|
|
"title", "playcount", "season", "episode", "showtitle",
|
|
|
|
"plot", "file", "rating", "resume", "tvshowid", "art",
|
|
|
|
"streamdetails", "firstaired", "runtime", "writer",
|
|
|
|
"dateadded", "lastplayed"
|
|
|
|
],
|
|
|
|
'limits': {"end": 1}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
try:
|
|
|
|
episodes = result['result']['episodes']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for episode in episodes:
|
|
|
|
li = createListItem(episode)
|
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
2015-12-26 18:50:32 +11:00
|
|
|
url=episode['file'],
|
2015-12-25 07:07:00 +11:00
|
|
|
listitem=li)
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
if count == limit:
|
|
|
|
break
|
|
|
|
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
|
|
|
|
##### GET INPROGRESS EPISODES FOR TAGNAME #####
|
|
|
|
def getInProgressEpisodes(tagname, limit):
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
# if the addon is called with inprogressepisodes parameter,
|
|
|
|
# we return the inprogressepisodes list of the given tagname
|
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
|
|
|
# First we get a list of all the in-progress TV shows - filtered by tag
|
|
|
|
query = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': "libTvShows",
|
|
|
|
'method': "VideoLibrary.GetTVShows",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'sort': {'order': "descending", 'method': "lastplayed"},
|
|
|
|
'filter': {
|
|
|
|
'and': [
|
|
|
|
{'operator': "true", 'field': "inprogress", 'value': ""},
|
2016-02-06 07:30:32 +11:00
|
|
|
{'operator': "is", 'field': "tag", 'value': "%s" % tagname}
|
2015-12-25 07:07:00 +11:00
|
|
|
]},
|
|
|
|
'properties': ['title', 'studio', 'mpaa', 'file', 'art']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
# If we found any, find the oldest unwatched show for each one.
|
|
|
|
try:
|
|
|
|
items = result['result']['tvshows']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for item in items:
|
|
|
|
query = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "VideoLibrary.GetEpisodes",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'tvshowid': item['tvshowid'],
|
|
|
|
'sort': {'method': "episode"},
|
|
|
|
'filter': {'operator': "true", 'field': "inprogress", 'value': ""},
|
|
|
|
'properties': [
|
|
|
|
"title", "playcount", "season", "episode", "showtitle", "plot",
|
|
|
|
"file", "rating", "resume", "tvshowid", "art", "cast",
|
|
|
|
"streamdetails", "firstaired", "runtime", "writer",
|
|
|
|
"dateadded", "lastplayed"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
try:
|
|
|
|
episodes = result['result']['episodes']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
for episode in episodes:
|
|
|
|
li = createListItem(episode)
|
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
2015-12-26 18:50:32 +11:00
|
|
|
url=episode['file'],
|
2015-12-25 07:07:00 +11:00
|
|
|
listitem=li)
|
|
|
|
count += 1
|
|
|
|
|
|
|
|
if count == limit:
|
|
|
|
break
|
|
|
|
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
|
|
|
|
##### GET RECENT EPISODES FOR TAGNAME #####
|
2016-03-16 00:19:56 +11:00
|
|
|
# def getRecentEpisodes(tagname, limit):
|
|
|
|
def getRecentEpisodes(viewid, mediatype, tagname, limit):
|
2015-12-25 07:07:00 +11:00
|
|
|
count = 0
|
|
|
|
# if the addon is called with recentepisodes parameter,
|
|
|
|
# we return the recentepisodes list of the given tagname
|
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
2016-08-30 23:51:11 +10:00
|
|
|
appendShowTitle = settings('RecentTvAppendShow') == 'true'
|
|
|
|
appendSxxExx = settings('RecentTvAppendSeason') == 'true'
|
2015-12-25 07:07:00 +11:00
|
|
|
# First we get a list of all the TV shows - filtered by tag
|
|
|
|
query = {
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': "libTvShows",
|
|
|
|
'method': "VideoLibrary.GetTVShows",
|
|
|
|
'params': {
|
|
|
|
'sort': {'order': "descending", 'method': "dateadded"},
|
2016-02-06 07:30:32 +11:00
|
|
|
'filter': {'operator': "is", 'field': "tag", 'value': "%s" % tagname},
|
2015-12-25 07:07:00 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
# If we found any, find the oldest unwatched show for each one.
|
|
|
|
try:
|
2016-03-16 00:19:56 +11:00
|
|
|
items = result['result'][mediatype]
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
# No items, empty folder
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
return
|
|
|
|
|
|
|
|
allshowsIds = set()
|
|
|
|
for item in items:
|
|
|
|
allshowsIds.add(item['tvshowid'])
|
|
|
|
|
|
|
|
query = {
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "VideoLibrary.GetEpisodes",
|
|
|
|
'params': {
|
|
|
|
'sort': {'order': "descending", 'method': "dateadded"},
|
|
|
|
'properties': [
|
|
|
|
"title", "playcount", "season", "episode", "showtitle", "plot",
|
|
|
|
"file", "rating", "resume", "tvshowid", "art", "streamdetails",
|
|
|
|
"firstaired", "runtime", "cast", "writer", "dateadded", "lastplayed"
|
|
|
|
],
|
|
|
|
"limits": {"end": limit}
|
|
|
|
}
|
|
|
|
}
|
2016-08-30 23:51:11 +10:00
|
|
|
if settings('TVShowWatched') == 'false':
|
2016-05-16 01:24:44 +10:00
|
|
|
query['params']['filter'] = {
|
|
|
|
'operator': "lessthan",
|
|
|
|
'field': "playcount",
|
|
|
|
'value': "1"
|
|
|
|
}
|
2016-03-16 00:19:56 +11:00
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
try:
|
|
|
|
episodes = result['result']['episodes']
|
2015-12-25 07:07:00 +11:00
|
|
|
except (KeyError, TypeError):
|
|
|
|
pass
|
|
|
|
else:
|
2016-03-16 00:19:56 +11:00
|
|
|
for episode in episodes:
|
|
|
|
if episode['tvshowid'] in allshowsIds:
|
2016-04-27 18:37:24 +10:00
|
|
|
li = createListItem(episode,
|
|
|
|
appendShowTitle=appendShowTitle,
|
|
|
|
appendSxxExx=appendSxxExx)
|
2016-03-16 00:19:56 +11:00
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
|
|
|
url=episode['file'],
|
|
|
|
listitem=li)
|
|
|
|
count += 1
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-03-16 00:19:56 +11:00
|
|
|
if count == limit:
|
|
|
|
break
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
|
2016-04-09 23:46:51 +10:00
|
|
|
|
|
|
|
def getVideoFiles(plexId, params):
|
|
|
|
"""
|
|
|
|
GET VIDEO EXTRAS FOR LISTITEM
|
|
|
|
|
|
|
|
returns the video files for the item as plugin listing, can be used for
|
|
|
|
browsing the actual files or videoextras etc.
|
|
|
|
"""
|
|
|
|
if plexId is None:
|
|
|
|
filename = params.get('filename')
|
|
|
|
if filename is not None:
|
|
|
|
filename = filename[0]
|
|
|
|
import re
|
|
|
|
regex = re.compile(r'''library/metadata/(\d+)''')
|
|
|
|
filename = regex.findall(filename)
|
|
|
|
try:
|
|
|
|
plexId = filename[0]
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if plexId is None:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info('No Plex ID found, abort getting Extras')
|
2016-04-09 23:46:51 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
|
|
|
|
|
|
item = PlexFunctions.GetPlexMetadata(plexId)
|
|
|
|
try:
|
|
|
|
path = item[0][0][0].attrib['file']
|
|
|
|
except:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('Could not get file path for item %s' % plexId)
|
2016-04-09 23:46:51 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
|
|
# Assign network protocol
|
|
|
|
if path.startswith('\\\\'):
|
|
|
|
path = path.replace('\\\\', 'smb://')
|
|
|
|
path = path.replace('\\', '/')
|
|
|
|
# Plex returns Windows paths as e.g. 'c:\slfkjelf\slfje\file.mkv'
|
|
|
|
elif '\\' in path:
|
|
|
|
path = path.replace('\\', '\\\\')
|
|
|
|
# Directory only, get rid of filename (!! exists() needs / or \ at end)
|
|
|
|
path = path.replace(os.path.basename(path), '')
|
|
|
|
# Only proceed if we can access this folder
|
|
|
|
if xbmcvfs.exists(path):
|
|
|
|
# Careful, returns encoded strings!
|
|
|
|
dirs, files = xbmcvfs.listdir(path)
|
|
|
|
for file in files:
|
2016-08-30 23:51:11 +10:00
|
|
|
file = path + tryDecode(file)
|
2016-04-09 23:46:51 +10:00
|
|
|
li = xbmcgui.ListItem(file, path=file)
|
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
|
2016-08-30 23:51:11 +10:00
|
|
|
url=tryEncode(file),
|
2016-04-09 23:46:51 +10:00
|
|
|
listitem=li)
|
|
|
|
for dir in dirs:
|
2016-08-30 23:51:11 +10:00
|
|
|
dir = path + tryDecode(dir)
|
2016-04-09 23:46:51 +10:00
|
|
|
li = xbmcgui.ListItem(dir, path=dir)
|
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
|
2016-08-30 23:51:11 +10:00
|
|
|
url=tryEncode(dir),
|
2016-04-09 23:46:51 +10:00
|
|
|
listitem=li,
|
|
|
|
isFolder=True)
|
2016-04-09 23:51:30 +10:00
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.warn('Kodi cannot access folder %s' % path)
|
2016-03-05 08:00:24 +11:00
|
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
2016-04-09 23:46:51 +10:00
|
|
|
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
@CatchExceptions(warnuser=False)
|
2016-06-20 00:42:44 +10:00
|
|
|
def getExtraFanArt(plexid, plexPath):
|
|
|
|
"""
|
|
|
|
Get extrafanart for listitem
|
|
|
|
will be called by skinhelper script to get the extrafanart
|
|
|
|
for tvshows we get the plexid just from the path
|
|
|
|
"""
|
2016-08-30 23:51:11 +10:00
|
|
|
log.debug('Called with plexid: %s, plexPath: %s' % (plexid, plexPath))
|
2016-06-20 00:42:44 +10:00
|
|
|
if not plexid:
|
|
|
|
if "plugin.video.plexkodiconnect" in plexPath:
|
|
|
|
plexid = plexPath.split("/")[-2]
|
|
|
|
if not plexid:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('Could not get a plexid, aborting')
|
2016-06-20 00:42:44 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
|
|
|
2016-07-23 00:55:57 +10:00
|
|
|
# We need to store the images locally for this to work
|
|
|
|
# because of the caching system in xbmc
|
2016-08-30 23:51:11 +10:00
|
|
|
fanartDir = tryDecode(xbmc.translatePath(
|
2016-07-23 00:55:57 +10:00
|
|
|
"special://thumbnails/plex/%s/" % plexid))
|
|
|
|
if not xbmcvfs.exists(fanartDir):
|
|
|
|
# Download the images to the cache directory
|
2016-08-30 23:51:11 +10:00
|
|
|
xbmcvfs.mkdirs(tryEncode(fanartDir))
|
2016-07-23 00:55:57 +10:00
|
|
|
xml = PlexFunctions.GetPlexMetadata(plexid)
|
|
|
|
if xml is None:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('Could not download metadata for %s' % plexid)
|
2016-07-23 00:55:57 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
2016-06-20 00:42:44 +10:00
|
|
|
|
2016-07-23 00:55:57 +10:00
|
|
|
API = PlexAPI.API(xml[0])
|
|
|
|
backdrops = API.getAllArtwork()['Backdrop']
|
|
|
|
for count, backdrop in enumerate(backdrops):
|
|
|
|
# Same ordering as in artwork
|
|
|
|
if os.path.supports_unicode_filenames:
|
|
|
|
fanartFile = os.path.join(fanartDir,
|
|
|
|
"fanart%.3d.jpg" % count)
|
|
|
|
else:
|
|
|
|
fanartFile = os.path.join(
|
2016-08-30 23:51:11 +10:00
|
|
|
tryEncode(fanartDir),
|
|
|
|
tryEncode("fanart%.3d.jpg" % count))
|
2016-07-23 00:55:57 +10:00
|
|
|
li = xbmcgui.ListItem("%.3d" % count, path=fanartFile)
|
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
|
|
|
url=fanartFile,
|
|
|
|
listitem=li)
|
|
|
|
xbmcvfs.copy(backdrop, fanartFile)
|
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info("Found cached backdrop.")
|
2016-07-23 00:55:57 +10:00
|
|
|
# Use existing cached images
|
|
|
|
dirs, files = xbmcvfs.listdir(fanartDir)
|
|
|
|
for file in files:
|
2016-08-30 23:51:11 +10:00
|
|
|
fanartFile = os.path.join(fanartDir, tryDecode(file))
|
2016-07-23 00:55:57 +10:00
|
|
|
li = xbmcgui.ListItem(file, path=fanartFile)
|
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
|
|
|
|
url=fanartFile,
|
|
|
|
listitem=li)
|
2016-03-04 00:00:48 +11:00
|
|
|
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
|
|
|
|
|
|
|
|
|
|
def RunLibScan(mode):
|
2016-08-30 23:51:11 +10:00
|
|
|
if window('plex_online') != "true":
|
2016-03-04 00:00:48 +11:00
|
|
|
# Server is not online, do not run the sync
|
|
|
|
xbmcgui.Dialog().ok(heading=addonName,
|
2016-08-30 23:51:11 +10:00
|
|
|
line1=lang(39205))
|
2016-03-04 00:00:48 +11:00
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
window('plex_runLibScan', value='full')
|
2016-03-15 03:47:05 +11:00
|
|
|
|
|
|
|
|
2016-06-05 02:48:22 +10:00
|
|
|
def BrowsePlexContent(viewid, mediatype="", folderid=""):
|
2016-03-15 03:47:05 +11:00
|
|
|
"""
|
2016-06-05 02:48:22 +10:00
|
|
|
Browse Plex Photos:
|
2016-03-15 03:47:05 +11:00
|
|
|
viewid: PMS name of the library
|
2016-06-05 02:48:22 +10:00
|
|
|
mediatype: mediatype, 'photos'
|
|
|
|
nodetype: e.g. 'ondeck' (TBD!!)
|
2016-03-15 03:47:05 +11:00
|
|
|
"""
|
2016-08-30 23:51:11 +10:00
|
|
|
log.debug("BrowsePlexContent called with viewid: %s, mediatype: "
|
|
|
|
"%s, folderid: %s" % (viewid, mediatype, folderid))
|
2016-03-15 03:47:05 +11:00
|
|
|
|
2016-06-05 02:48:22 +10:00
|
|
|
if not folderid:
|
2016-06-13 01:22:22 +10:00
|
|
|
# Top-level navigation, so get the content of this section
|
2016-06-05 02:48:22 +10:00
|
|
|
# Get all sections
|
|
|
|
xml = PlexFunctions.GetPlexSectionResults(
|
|
|
|
viewid,
|
2016-08-30 23:51:11 +10:00
|
|
|
containerSize=int(settings('limitindex')))
|
2016-06-05 02:48:22 +10:00
|
|
|
try:
|
|
|
|
xml.attrib
|
|
|
|
except AttributeError:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error("Error download section %s" % viewid)
|
2016-06-13 01:22:22 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
2016-06-05 02:48:22 +10:00
|
|
|
else:
|
2016-06-13 01:22:22 +10:00
|
|
|
# folderid was passed so we can directly access the folder
|
2016-06-05 02:48:22 +10:00
|
|
|
xml = downloadutils.DownloadUtils().downloadUrl(
|
|
|
|
"{server}%s" % folderid)
|
|
|
|
try:
|
|
|
|
xml.attrib
|
|
|
|
except AttributeError:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error("Error downloading %s" % folderid)
|
2016-06-13 01:22:22 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
2016-06-05 02:48:22 +10:00
|
|
|
|
2016-06-13 01:22:22 +10:00
|
|
|
# Set the folder's name
|
2016-06-05 02:48:22 +10:00
|
|
|
xbmcplugin.setPluginCategory(int(sys.argv[1]),
|
|
|
|
xml.attrib.get('librarySectionTitle'))
|
2016-03-15 03:47:05 +11:00
|
|
|
|
|
|
|
# set the correct params for the content type
|
2016-06-19 22:58:42 +10:00
|
|
|
if mediatype == "photos":
|
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'photos')
|
2016-03-15 03:47:05 +11:00
|
|
|
|
|
|
|
# process the listing
|
|
|
|
for item in xml:
|
|
|
|
API = PlexAPI.API(item)
|
|
|
|
if item.tag == 'Directory':
|
2016-06-19 22:58:42 +10:00
|
|
|
li = xbmcgui.ListItem(item.attrib.get('title', 'Missing title'))
|
2016-03-15 03:47:05 +11:00
|
|
|
# for folders we add an additional browse request, passing the
|
|
|
|
# folderId
|
|
|
|
li.setProperty('IsFolder', 'true')
|
|
|
|
li.setProperty('IsPlayable', 'false')
|
2016-06-05 02:48:22 +10:00
|
|
|
path = "%s?id=%s&mode=browseplex&type=%s&folderid=%s" \
|
2016-06-13 01:22:22 +10:00
|
|
|
% (sys.argv[0], viewid, mediatype, API.getKey())
|
2017-01-09 01:03:41 +11:00
|
|
|
API.set_listitem_artwork(li)
|
2016-06-13 01:22:22 +10:00
|
|
|
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
|
|
|
|
url=path,
|
|
|
|
listitem=li,
|
|
|
|
isFolder=True)
|
2016-03-15 03:47:05 +11:00
|
|
|
else:
|
2016-06-19 22:58:42 +10:00
|
|
|
li = API.CreateListItemFromPlexItem()
|
2017-01-09 01:03:41 +11:00
|
|
|
API.set_listitem_artwork(li)
|
2016-03-15 03:47:05 +11:00
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
2016-06-19 22:58:42 +10:00
|
|
|
url=li.getProperty("path"),
|
2016-03-15 03:47:05 +11:00
|
|
|
listitem=li)
|
|
|
|
|
2016-06-19 22:58:42 +10:00
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]),
|
|
|
|
xbmcplugin.SORT_METHOD_VIDEO_TITLE)
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]),
|
|
|
|
xbmcplugin.SORT_METHOD_DATE)
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]),
|
|
|
|
xbmcplugin.SORT_METHOD_VIDEO_RATING)
|
|
|
|
xbmcplugin.addSortMethod(int(sys.argv[1]),
|
|
|
|
xbmcplugin.SORT_METHOD_VIDEO_RUNTIME)
|
2016-03-15 03:47:05 +11:00
|
|
|
|
2016-06-13 01:22:22 +10:00
|
|
|
xbmcplugin.endOfDirectory(
|
|
|
|
handle=int(sys.argv[1]),
|
2016-08-30 23:51:11 +10:00
|
|
|
cacheToDisc=settings('enableTextureCache') == 'true')
|
2016-03-15 23:09:51 +11:00
|
|
|
|
|
|
|
|
|
|
|
def getOnDeck(viewid, mediatype, tagname, limit):
|
|
|
|
"""
|
|
|
|
Retrieves Plex On Deck items, currently only for TV shows
|
|
|
|
|
|
|
|
Input:
|
|
|
|
viewid: Plex id of the library section, e.g. '1'
|
|
|
|
mediatype: Kodi mediatype, e.g. 'tvshows', 'movies',
|
|
|
|
'homevideos', 'photos'
|
|
|
|
tagname: Name of the Plex library, e.g. "My Movies"
|
2016-03-16 00:19:56 +11:00
|
|
|
limit: Max. number of items to retrieve, e.g. 50
|
2016-03-15 23:09:51 +11:00
|
|
|
"""
|
2016-04-18 19:23:05 +10:00
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
2016-08-30 23:51:11 +10:00
|
|
|
appendShowTitle = settings('OnDeckTvAppendShow') == 'true'
|
|
|
|
appendSxxExx = settings('OnDeckTvAppendSeason') == 'true'
|
|
|
|
directpaths = settings('useDirectPaths') == 'true'
|
|
|
|
if settings('OnDeckTVextended') == 'false':
|
2016-04-18 19:23:05 +10:00
|
|
|
# Chances are that this view is used on Kodi startup
|
|
|
|
# Wait till we've connected to a PMS. At most 30s
|
|
|
|
counter = 0
|
2016-08-30 23:51:11 +10:00
|
|
|
while window('plex_authenticated') != 'true':
|
2016-04-18 19:23:05 +10:00
|
|
|
counter += 1
|
|
|
|
if counter >= 300:
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('Aborting On Deck view, we were not authenticated '
|
|
|
|
'for the PMS')
|
2016-05-13 04:43:53 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
2016-04-18 19:23:05 +10:00
|
|
|
xbmc.sleep(100)
|
|
|
|
xml = downloadutils.DownloadUtils().downloadUrl(
|
|
|
|
'{server}/library/sections/%s/onDeck' % viewid)
|
|
|
|
if xml in (None, 401):
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('Could not download PMS xml for view %s' % viewid)
|
2016-04-18 19:23:05 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
2016-04-22 18:26:40 +10:00
|
|
|
for item in xml:
|
|
|
|
API = PlexAPI.API(item)
|
2016-04-27 18:37:24 +10:00
|
|
|
listitem = API.CreateListItemFromPlexItem(
|
|
|
|
appendShowTitle=appendShowTitle,
|
|
|
|
appendSxxExx=appendSxxExx)
|
2016-04-22 18:26:40 +10:00
|
|
|
API.AddStreamInfo(listitem)
|
2017-01-09 01:03:41 +11:00
|
|
|
API.set_listitem_artwork(listitem)
|
2016-05-17 03:27:43 +10:00
|
|
|
if directpaths:
|
2016-05-13 04:43:53 +10:00
|
|
|
url = API.getFilePath()
|
|
|
|
else:
|
|
|
|
params = {
|
|
|
|
'mode': "play",
|
|
|
|
'id': API.getRatingKey(),
|
|
|
|
'dbid': listitem.getProperty('dbid')
|
|
|
|
}
|
2017-01-03 00:07:24 +11:00
|
|
|
url = "plugin://plugin.video.plexkodiconnect/tvshows/?%s" \
|
2016-05-13 04:43:53 +10:00
|
|
|
% urllib.urlencode(params)
|
2016-04-22 18:26:40 +10:00
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
2016-05-13 04:43:53 +10:00
|
|
|
url=url,
|
2016-04-22 18:26:40 +10:00
|
|
|
listitem=listitem)
|
2016-04-18 19:23:05 +10:00
|
|
|
return xbmcplugin.endOfDirectory(
|
|
|
|
handle=int(sys.argv[1]),
|
2016-08-30 23:51:11 +10:00
|
|
|
cacheToDisc=settings('enableTextureCache') == 'true')
|
2016-04-18 19:23:05 +10:00
|
|
|
|
2016-03-15 23:09:51 +11:00
|
|
|
# if the addon is called with nextup parameter,
|
|
|
|
# we return the nextepisodes list of the given tagname
|
|
|
|
# First we get a list of all the TV shows - filtered by tag
|
|
|
|
query = {
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': "libTvShows",
|
|
|
|
'method': "VideoLibrary.GetTVShows",
|
|
|
|
'params': {
|
|
|
|
'sort': {'order': "descending", 'method': "lastplayed"},
|
|
|
|
'filter': {
|
|
|
|
'and': [
|
|
|
|
{'operator': "true", 'field': "inprogress", 'value': ""},
|
|
|
|
{'operator': "is", 'field': "tag", 'value': "%s" % tagname}
|
|
|
|
]}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
# If we found any, find the oldest unwatched show for each one.
|
|
|
|
try:
|
|
|
|
items = result['result'][mediatype]
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
# Now items retrieved - empty directory
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
|
|
|
return
|
|
|
|
|
|
|
|
query = {
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "VideoLibrary.GetEpisodes",
|
|
|
|
'params': {
|
|
|
|
'sort': {'method': "episode"},
|
|
|
|
'limits': {"end": 1},
|
|
|
|
'properties': [
|
|
|
|
"title", "playcount", "season", "episode", "showtitle",
|
|
|
|
"plot", "file", "rating", "resume", "tvshowid", "art",
|
|
|
|
"streamdetails", "firstaired", "runtime", "cast", "writer",
|
|
|
|
"dateadded", "lastplayed"
|
|
|
|
],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
if settings('ignoreSpecialsNextEpisodes') == "true":
|
2016-03-15 23:09:51 +11:00
|
|
|
query['params']['filter'] = {
|
|
|
|
'and': [
|
|
|
|
{'operator': "lessthan", 'field': "playcount", 'value': "1"},
|
|
|
|
{'operator': "greaterthan", 'field': "season", 'value': "0"}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
query['params']['filter'] = {
|
|
|
|
'or': [
|
|
|
|
{'operator': "lessthan", 'field': "playcount", 'value': "1"},
|
|
|
|
{'operator': "true", 'field': "inprogress", 'value': ""}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Are there any episodes still in progress/not yet finished watching?!?
|
|
|
|
# Then we should show this episode, NOT the "next up"
|
|
|
|
inprogrQuery = {
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "VideoLibrary.GetEpisodes",
|
|
|
|
'params': {
|
|
|
|
'sort': {'method': "episode"},
|
|
|
|
'filter': {'operator': "true", 'field': "inprogress", 'value': ""},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inprogrQuery['params']['properties'] = query['params']['properties']
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
for item in items:
|
|
|
|
inprogrQuery['params']['tvshowid'] = item['tvshowid']
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(inprogrQuery))
|
|
|
|
result = json.loads(result)
|
|
|
|
try:
|
|
|
|
episodes = result['result']['episodes']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
# No, there are no episodes not yet finished. Get "next up"
|
|
|
|
query['params']['tvshowid'] = item['tvshowid']
|
|
|
|
result = xbmc.executeJSONRPC(json.dumps(query))
|
|
|
|
result = json.loads(result)
|
|
|
|
try:
|
|
|
|
episodes = result['result']['episodes']
|
|
|
|
except (KeyError, TypeError):
|
|
|
|
# Also no episodes currently coming up
|
|
|
|
continue
|
|
|
|
for episode in episodes:
|
|
|
|
# There will always be only 1 episode ('limit=1')
|
2016-04-27 18:37:24 +10:00
|
|
|
li = createListItem(episode,
|
|
|
|
appendShowTitle=appendShowTitle,
|
|
|
|
appendSxxExx=appendSxxExx)
|
2016-03-15 23:09:51 +11:00
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
|
|
|
url=episode['file'],
|
2016-04-19 23:20:03 +10:00
|
|
|
listitem=li,
|
2016-03-15 23:09:51 +11:00
|
|
|
isFolder=False)
|
|
|
|
|
|
|
|
count += 1
|
|
|
|
if count >= limit:
|
|
|
|
break
|
|
|
|
|
|
|
|
xbmcplugin.endOfDirectory(handle=int(sys.argv[1]))
|
2016-04-17 21:36:41 +10:00
|
|
|
|
|
|
|
|
|
|
|
def watchlater():
|
|
|
|
"""
|
|
|
|
Listing for plex.tv Watch Later section (if signed in to plex.tv)
|
|
|
|
"""
|
2016-08-30 23:51:11 +10:00
|
|
|
if window('plex_token') == '':
|
|
|
|
log.error('No watch later - not signed in to plex.tv')
|
2016-04-17 21:36:41 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
2016-10-24 04:38:21 +11:00
|
|
|
if window('plex_restricteduser') == 'true':
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('No watch later - restricted user')
|
2016-04-17 21:36:41 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
|
|
|
|
|
|
|
xml = downloadutils.DownloadUtils().downloadUrl(
|
|
|
|
'https://plex.tv/pms/playlists/queue/all',
|
|
|
|
authenticate=False,
|
2016-08-30 23:51:11 +10:00
|
|
|
headerOptions={'X-Plex-Token': window('plex_token')})
|
2016-04-17 21:36:41 +10:00
|
|
|
if xml in (None, 401):
|
2016-08-30 23:51:11 +10:00
|
|
|
log.error('Could not download watch later list from plex.tv')
|
2016-04-17 21:36:41 +10:00
|
|
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
|
|
|
|
2016-08-30 23:51:11 +10:00
|
|
|
log.info('Displaying watch later plex.tv items')
|
2016-04-17 21:36:41 +10:00
|
|
|
xbmcplugin.setContent(int(sys.argv[1]), 'movies')
|
2016-06-20 02:30:21 +10:00
|
|
|
url = "plugin://plugin.video.plexkodiconnect/"
|
2016-04-17 21:36:41 +10:00
|
|
|
params = {
|
2017-01-03 01:41:38 +11:00
|
|
|
'mode': "Plex_Node",
|
2016-04-17 21:36:41 +10:00
|
|
|
}
|
|
|
|
for item in xml:
|
|
|
|
API = PlexAPI.API(item)
|
|
|
|
listitem = API.CreateListItemFromPlexItem()
|
|
|
|
API.AddStreamInfo(listitem)
|
2017-01-09 01:03:41 +11:00
|
|
|
API.set_listitem_artwork(listitem)
|
2016-04-17 21:36:41 +10:00
|
|
|
params['id'] = item.attrib.get('key')
|
2016-06-20 02:53:45 +10:00
|
|
|
params['viewOffset'] = item.attrib.get('viewOffset', '0')
|
2017-01-03 02:42:07 +11:00
|
|
|
params['plex_type'] = item.attrib.get('type')
|
2016-04-17 21:36:41 +10:00
|
|
|
xbmcplugin.addDirectoryItem(
|
|
|
|
handle=int(sys.argv[1]),
|
|
|
|
url="%s?%s" % (url, urllib.urlencode(params)),
|
|
|
|
listitem=listitem)
|
|
|
|
|
|
|
|
xbmcplugin.endOfDirectory(
|
|
|
|
handle=int(sys.argv[1]),
|
2016-08-30 23:51:11 +10:00
|
|
|
cacheToDisc=settings('enableTextureCache') == 'true')
|
2016-05-30 00:52:00 +10:00
|
|
|
|
|
|
|
|
|
|
|
def enterPMS():
|
|
|
|
"""
|
|
|
|
Opens dialogs for the user the plug in the PMS details
|
|
|
|
"""
|
|
|
|
dialog = xbmcgui.Dialog()
|
|
|
|
# "Enter your Plex Media Server's IP or URL. Examples are:"
|
|
|
|
dialog.ok(addonName,
|
2016-08-30 23:51:11 +10:00
|
|
|
lang(39215),
|
2016-05-30 00:52:00 +10:00
|
|
|
'192.168.1.2',
|
|
|
|
'plex.myServer.org')
|
|
|
|
ip = dialog.input("Enter PMS IP or URL")
|
|
|
|
if ip == '':
|
|
|
|
return
|
|
|
|
port = dialog.input("Enter PMS port", '32400', xbmcgui.INPUT_NUMERIC)
|
|
|
|
if port == '':
|
|
|
|
return
|
|
|
|
url = '%s:%s' % (ip, port)
|
|
|
|
# "Does your Plex Media Server support SSL connections?
|
|
|
|
# (https instead of http)"
|
2016-08-30 23:51:11 +10:00
|
|
|
https = dialog.yesno(addonName, lang(39217))
|
2016-05-30 00:52:00 +10:00
|
|
|
if https:
|
|
|
|
url = 'https://%s' % url
|
|
|
|
else:
|
|
|
|
url = 'http://%s' % url
|
|
|
|
https = 'true' if https else 'false'
|
|
|
|
|
|
|
|
machineIdentifier = PlexFunctions.GetMachineIdentifier(url)
|
|
|
|
if machineIdentifier is None:
|
|
|
|
# "Error contacting url
|
|
|
|
# Abort (Yes) or save address anyway (No)"
|
|
|
|
if dialog.yesno(addonName, '%s %s. %s'
|
2016-08-30 23:51:11 +10:00
|
|
|
% (lang(39218), url, lang(39219))):
|
2016-05-30 00:52:00 +10:00
|
|
|
return
|
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
settings('plex_machineIdentifier', '')
|
2016-05-30 00:52:00 +10:00
|
|
|
else:
|
2016-08-30 23:51:11 +10:00
|
|
|
settings('plex_machineIdentifier', machineIdentifier)
|
2016-09-26 01:35:40 +10:00
|
|
|
log.info('Set new PMS to https %s, ip %s, port %s, machineIdentifier %s'
|
2016-08-30 23:51:11 +10:00
|
|
|
% (https, ip, port, machineIdentifier))
|
|
|
|
settings('https', value=https)
|
|
|
|
settings('ipaddress', value=ip)
|
|
|
|
settings('port', value=port)
|
2016-05-30 01:40:15 +10:00
|
|
|
# Chances are this is a local PMS, so disable SSL certificate check
|
2016-08-30 23:51:11 +10:00
|
|
|
settings('sslverify', value='false')
|
2016-05-30 00:52:00 +10:00
|
|
|
|
|
|
|
# Sign out to trigger new login
|
|
|
|
if __LogOut():
|
|
|
|
# Only login again if logout was successful
|
|
|
|
__LogIn()
|
|
|
|
|
|
|
|
|
2016-05-30 01:36:07 +10:00
|
|
|
def __LogIn():
|
2016-05-30 00:52:00 +10:00
|
|
|
"""
|
|
|
|
Resets (clears) window properties to enable (re-)login:
|
|
|
|
suspend_Userclient
|
|
|
|
plex_runLibScan: set to 'full' to trigger lib sync
|
|
|
|
|
|
|
|
suspend_LibraryThread is cleared in service.py if user was signed out!
|
|
|
|
"""
|
2016-08-30 23:51:11 +10:00
|
|
|
window('plex_runLibScan', value='full')
|
2016-05-30 00:52:00 +10:00
|
|
|
# Restart user client
|
2016-08-30 23:51:11 +10:00
|
|
|
window('suspend_Userclient', clear=True)
|
2016-05-30 00:52:00 +10:00
|
|
|
|
|
|
|
|
2016-05-30 01:36:07 +10:00
|
|
|
def __LogOut():
|
2016-05-30 00:52:00 +10:00
|
|
|
"""
|
|
|
|
Finishes lib scans, logs out user. The following window attributes are set:
|
|
|
|
suspend_LibraryThread: 'true'
|
|
|
|
suspend_Userclient: 'true'
|
|
|
|
|
|
|
|
Returns True if successfully signed out, False otherwise
|
|
|
|
"""
|
|
|
|
dialog = xbmcgui.Dialog()
|
|
|
|
# Resetting, please wait
|
|
|
|
dialog.notification(
|
|
|
|
heading=addonName,
|
2016-08-30 23:51:11 +10:00
|
|
|
message=lang(39207),
|
2016-05-30 00:52:00 +10:00
|
|
|
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
|
|
|
time=3000,
|
|
|
|
sound=False)
|
|
|
|
# Pause library sync thread
|
2016-08-30 23:51:11 +10:00
|
|
|
window('suspend_LibraryThread', value='true')
|
2016-05-30 00:52:00 +10:00
|
|
|
# Wait max for 10 seconds for all lib scans to shutdown
|
|
|
|
counter = 0
|
2016-08-30 23:51:11 +10:00
|
|
|
while window('plex_dbScan') == 'true':
|
2016-05-30 00:52:00 +10:00
|
|
|
if counter > 200:
|
|
|
|
# Failed to reset PMS and plex.tv connects. Try to restart Kodi.
|
2016-08-30 23:51:11 +10:00
|
|
|
dialog.ok(addonName, lang(39208))
|
2016-05-30 00:52:00 +10:00
|
|
|
# Resuming threads, just in case
|
2016-08-30 23:51:11 +10:00
|
|
|
window('suspend_LibraryThread', clear=True)
|
|
|
|
log.error("Could not stop library sync, aborting")
|
2016-05-30 00:52:00 +10:00
|
|
|
return False
|
|
|
|
counter += 1
|
|
|
|
xbmc.sleep(50)
|
2016-08-30 23:51:11 +10:00
|
|
|
log.debug("Successfully stopped library sync")
|
2016-05-30 00:52:00 +10:00
|
|
|
|
2016-05-30 01:36:07 +10:00
|
|
|
# Log out currently signed in user:
|
2016-08-30 23:51:11 +10:00
|
|
|
window('plex_serverStatus', value="401")
|
2016-05-30 01:36:07 +10:00
|
|
|
# Above method needs to have run its course! Hence wait
|
|
|
|
counter = 0
|
2016-08-30 23:51:11 +10:00
|
|
|
while window('plex_serverStatus') == "401":
|
2016-05-30 01:36:07 +10:00
|
|
|
if counter > 100:
|
|
|
|
# 'Failed to reset PKC. Try to restart Kodi.'
|
2016-08-30 23:51:11 +10:00
|
|
|
dialog.ok(addonName, lang(39208))
|
|
|
|
log.error("Could not sign out user, aborting")
|
2016-05-30 01:36:07 +10:00
|
|
|
return False
|
|
|
|
counter += 1
|
|
|
|
xbmc.sleep(50)
|
|
|
|
# Suspend the user client during procedure
|
2016-08-30 23:51:11 +10:00
|
|
|
window('suspend_Userclient', value='true')
|
2016-05-30 00:52:00 +10:00
|
|
|
return True
|