Merge commit 'a4673b03777322ebed8acf665b399c8219276544'

This commit is contained in:
tomkat83 2016-03-14 17:48:08 +01:00
commit e7349f5c12
13 changed files with 152 additions and 80 deletions

View file

@ -145,14 +145,14 @@
<!-- Video nodes -->
<string id="30170">Recently Added TV Shows</string><!-- Verified -->
<string id="30171">On Deck TV Shows</string><!-- Verified -->
<string id="30171">In Progress TV Shows</string><!-- Verified -->
<string id="30172">All Music</string>
<string id="30173">Channels</string><!-- Verified -->
<string id="30174">Recently Added Movies</string><!-- Verified -->
<string id="30175">Recently Added Episodes</string><!-- Verified -->
<string id="30176">Recently Added Albums</string>
<string id="30177">On Deck Movies</string><!-- Verified -->
<string id="30178">On Deck Episodes</string><!-- Verified -->
<string id="30177">In Progress Movies</string><!-- Verified -->
<string id="30178">In Progress Episodes</string><!-- Verified -->
<string id="30179">Next Episodes</string><!-- Verified -->
<string id="30180">Favorite Movies</string><!-- Verified -->
<string id="30181">Favorite Shows</string><!-- Verified -->
@ -277,7 +277,7 @@
<string id="30512">Force artwork caching</string>
<string id="30513">Limit artwork cache threads (recommended for rpi)</string>
<string id="30514">Enable fast startup (requires server plugin)</string>
<string id="30515">Maximum items to request from the server at once</string>
<string id="30515">Maximum items to request from the server at once (restart!)</string>
<string id="30516">Playback</string>
<string id="30517">[COLOR yellow]Enter network credentials[/COLOR]</string>
<string id="30518">Enable Plex Trailers (Plexpass is needed)</string>
@ -379,6 +379,7 @@
<string id="39207">Reseting PMS connections, please wait</string>
<string id="39208">Failed to reset PMS and plex.tv connects. Try to restart Kodi.</string>
<string id="39209">[COLOR yellow]Log-in to plex.tv[/COLOR]</string>
<string id="39210">Not yet connected to Plex Server</string>
<!-- Plex Artwork.py -->
@ -408,6 +409,6 @@
<string id="39405">Plex playlists/nodes refreshed</string>
<string id="39406">Plex playlists/nodes refresh failed</string>
<string id="39407">Full library sync finished</string>
<string id="39408">Sync had to skip some items because they could not be processed. Please post your Kodi logs to the Plex forum.</string>
<string id="39408">Sync had to skip some items because they could not be processed. Kodi may be instable now!! Please post your Kodi logs to the Plex forum.</string>
</strings>

View file

@ -173,14 +173,14 @@
<string id="30169">Addresse : </string>
<string id="30170">Zuletzt hinzugefügte Serien</string>
<string id="30171">Aktuell Serien</string>
<string id="30171">Begonnene Serien</string>
<string id="30172">Alles an Musik</string>
<string id="30173">Kanäle</string>
<string id="30174">Zuletzt hinzugefügte Filme</string>
<string id="30175">Zuletzt hinzugefügte Episoden</string>
<string id="30176">Zuletzt hinzugefügte Alben</string>
<string id="30177">Aktuelle Filme</string>
<string id="30178">Aktuelle Episoden</string>
<string id="30177">Begonnene Filme</string>
<string id="30178">Begonnene Episoden</string>
<string id="30179">Nächste Episoden</string>
<string id="30180">Favorisierte Filme</string>
<string id="30181">Favorisierte Serien</string>
@ -252,6 +252,8 @@
<string id="30249">Unterdrücke Server-Verbindungsmeldungen beim Starten</string>
<string id="30250">Benutze lokale Pfade anstelle von Addon-Umleitungen beim Abspielen</string>
<string id="30515">Max. Anzahl gleichzeitig nachgefragter PMS Einträge (Neustart!)</string>
<string id="33010">Plex Media Server Authorisierung ist zu häufig fehlgeschlagen. In den Einstellungen können die Anzahl erfolgloser Versuche zurückgesetzt werden.</string>
<!-- Default views -->
@ -310,8 +312,7 @@
<string id="39207">PMS Verbindungen werden zurückgesetzt</string>
<string id="39208">PMS und plex.tv Verbindungen konnten nicht zurückgesetzt werden. Bitte versuchen Sie, Kodi neu zu starten, um das Problem zu beheben.</string>
<string id="39209">[COLOR yellow]Bei plex.tv einloggen[/COLOR]</string>
<string id="39210">Noch nicht mit Plex Server verbunden</string>
<!-- Plex Artwork.py -->
<string id="39250">Alle Plex Bilder in Kodi zwischenzuspeichern kann sehr lange dauern. Möchten Sie wirklich fortfahren?</string>
@ -340,6 +341,6 @@
<string id="39405">Plex Playlisten/Nodes aktualisiert</string>
<string id="39406">Plex Playlisten/Nodes Aktualisierung fehlgeschlagen</string>
<string id="39407">Plex Bibliotheken aktualisiert</string>
<string id="39408">Einige Plex Einträge mussten übersprungen werden, da sie nicht verarbeitet werden konnten. Bitte teilen Sie Ihr Kodi log im Plex Forum.</string>
<string id="39408">Einige Plex Einträge mussten übersprungen werden, da sie nicht verarbeitet werden konnten. Kodi ist nun möglicherweise instabil!! Bitte teilen Sie Ihr Kodi log im Plex Forum.</string>
</strings>

View file

@ -1056,8 +1056,6 @@ class PlexAPI():
self.logMsg("No URL for user avatar.", 1)
return False
for user in users:
self.logMsg('type user: %s, type username: %s'
% (type(user['title']), type(username)))
if username in user['title']:
url = user['thumb']
self.logMsg("Avatar url for user %s is: %s" % (username, url), 1)
@ -2092,7 +2090,7 @@ class API():
allartworks['Backdrop'].append(background)
if not allartworks['Primary']:
primary = item['parentThumb']
primary = item.get('parentThumb')
if primary:
primary = "%s%s" % (self.server, primary)
primary = self.addPlexCredentialsToUrl(primary)

View file

@ -84,12 +84,12 @@ class PlexCompanion(threading.Thread):
self.logMsg("Client is still registered", 1)
else:
self.logMsg("Client is no longer registered", 1)
self.logMsg("PlexBMC Helper still running on port %s"
self.logMsg("Plex Companion still running on port %s"
% self.port, 1)
message_count = 0
if not is_running:
self.logMsg("PleXBMC Helper has started", 0)
self.logMsg("Plex Companion has started", 0)
is_running = True
subscribers.subMgr.notify()
@ -106,4 +106,4 @@ class PlexCompanion(threading.Thread):
finally:
httpd.socket.close()
requests.dumpConnections()
self.logMsg("----===## STOP PlexBMC Helper ##===----", 0)
self.logMsg("----===## STOP Plex Companion ##===----", 0)

View file

@ -3,7 +3,7 @@ from urllib import urlencode
from ast import literal_eval
from urlparse import urlparse, parse_qs
import re
import time
from copy import deepcopy
from xbmcaddon import Addon
@ -185,7 +185,7 @@ def GetPlexMetadata(key):
return xml
def GetAllPlexChildren(key):
def GetAllPlexChildren(key, containerSize=None):
"""
Returns a list (raw xml API dump) of all Plex children for the key.
(e.g. /library/metadata/194853/children pointing to a season)
@ -193,18 +193,11 @@ def GetAllPlexChildren(key):
Input:
key Key to a Plex item, e.g. 12345
"""
xml = downloadutils.DownloadUtils().downloadUrl(
"{server}/library/metadata/%s/children" % key)
try:
xml.attrib
except AttributeError:
logMsg(
title, "Error retrieving all children for Plex item %s" % key, -1)
xml = None
return xml
url = "{server}/library/metadata/%s/children?" % key
return DownloadChunks(url, containerSize)
def GetPlexSectionResults(viewId, args=None):
def GetPlexSectionResults(viewId, args=None, containerSize=None):
"""
Returns a list (XML API dump) of all Plex items in the Plex
section with key = viewId.
@ -214,26 +207,76 @@ def GetPlexSectionResults(viewId, args=None):
Returns None if something went wrong
"""
result = []
url = "{server}/library/sections/%s/all" % viewId
url = "{server}/library/sections/%s/all?" % viewId
if args:
url += "?" + urlencode(args)
result = downloadutils.DownloadUtils().downloadUrl(url)
try:
result.tag
# Nope, not an XML, abort
except AttributeError:
logMsg(title,
"Error retrieving all items for Plex section %s"
% viewId, -1)
result = None
return result
url += urlencode(args) + '&'
return DownloadChunks(url, containerSize)
def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None):
def DownloadChunks(url, containerSize):
"""
Downloads PMS url in chunks of containerSize (int).
If containerSize is None: ONE xml is fetched directly
url MUST end with '?' (if no other url encoded args are present) or '&'
Returns a stitched-together xml or None.
"""
if containerSize is None:
# Get rid of '?' or '&' at the end of url
xml = downloadutils.DownloadUtils().downloadUrl(url[:-1])
try:
xml.attrib
except AttributeError:
# Nope, not an XML, abort
logMsg(title, "Error getting url %s" % url[:-1], -1)
return None
else:
return xml
xml = None
pos = 0
errorCounter = 0
while errorCounter < 10:
args = {
'X-Plex-Container-Size': containerSize,
'X-Plex-Container-Start': pos
}
xmlpart = downloadutils.DownloadUtils().downloadUrl(
url + urlencode(args))
# If something went wrong - skip in the hope that it works next time
try:
xmlpart.attrib
except AttributeError:
logMsg(title, 'Error while downloading chunks: %s'
% (url + urlencode(args)), -1)
pos += containerSize
errorCounter += 1
continue
# Very first run: starting xml (to retain data in xml's root!)
if xml is None:
xml = deepcopy(xmlpart)
if len(xmlpart) < containerSize:
break
else:
pos += containerSize
continue
# Build answer xml - containing the entire library
for child in xmlpart:
xml.append(child)
# Done as soon as we don't receive a full complement of items
if len(xmlpart) < containerSize:
break
pos += containerSize
if errorCounter == 10:
logMsg(title, 'Fatal error while downloading chunks for %s' % url, -1)
return None
return xml
def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None,
containerSize=None):
"""
Returns a list (raw XML API dump) of all Plex subitems for the key.
(e.g. /library/sections/2/allLeaves pointing to all TV shows)
@ -244,6 +287,7 @@ def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None):
since that point of time until now.
updatedAt Unix timestamp; only retrieves PMS items updated
by the PMS since that point of time until now.
containerSize Number of items simultaneously fetched from PMS
If lastViewedAt and updatedAt=None, ALL PMS items are returned.
@ -260,19 +304,11 @@ def GetAllPlexLeaves(viewId, lastViewedAt=None, updatedAt=None):
if updatedAt:
args.append('updatedAt>=%s' % updatedAt)
if args:
url += '?' + '&'.join(args)
url += '?' + '&'.join(args) + '&'
else:
url += '?'
xml = downloadutils.DownloadUtils().downloadUrl(url)
try:
xml.attrib
# Nope, not an XML, abort
except AttributeError:
logMsg(title,
"Error retrieving all leaves for Plex section %s"
% viewId, -1)
xml = None
return xml
return DownloadChunks(url, containerSize)
def GetPlexCollections(mediatype):

View file

@ -421,7 +421,7 @@ class Artwork():
cursor.execute(query, (imageUrl, kodiId, mediaType, imageType))
# Cache fanart and poster in Kodi texture cache
if cacheimage and imageType in ("fanart", "poster"):
if cacheimage and imageType in ("fanart", "poster", "thumb"):
self.CacheTexture(imageUrl)
def deleteArtwork(self, kodiid, mediatype, cursor):

View file

@ -159,6 +159,18 @@ def doPlayback(itemid, dbid):
"""
Called only for a SINGLE element, not playQueues
"""
if utils.window('plex_authenticated') != "true":
utils.logMsg('doPlayback', 'Not yet authenticated for a PMS, abort '
'starting playback', -1)
string = xbmcaddon.Addon().getLocalizedString
# Not yet connected to a PMS server
xbmcgui.Dialog().notification(
heading=addonName,
message=string(39210),
icon=xbmcgui.NOTIFICATION_ERROR,
time=7000,
sound=True)
return False
item = PlexFunctions.GetPlexMetadata(itemid)
if item is None:

View file

@ -43,6 +43,8 @@ class Items(object):
self.artwork = artwork.Artwork()
self.emby = embyserver.Read_EmbyServer()
self.userid = utils.window('currUserId')
self.server = utils.window('pms_server')
def __enter__(self):
"""
@ -1445,8 +1447,21 @@ class TVShows(Items):
people = API.getPeopleList()
kodi_db.addPeople(episodeid, people, "episode")
# Process artwork
allartworks = API.getAllArtwork()
artwork.addArtwork(allartworks, episodeid, "episode", kodicursor)
# Wide "screenshot" of particular episode
poster = item.attrib.get('thumb')
if poster:
poster = API.addPlexCredentialsToUrl(
"%s%s" % (self.server, poster))
artwork.addOrUpdateArt(
poster, episodeid, "episode", "thumb", kodicursor)
# poster of TV show itself
# poster = item.attrib.get('grandparentThumb')
# if poster:
# poster = API.addPlexCredentialsToUrl(
# "%s%s" % (self.server, poster))
# artwork.addOrUpdateArt(
# poster, episodeid, "episode", "poster", kodicursor)
# Process stream details
streams = API.getMediaStreams()
kodi_db.addStreams(fileid, streams, runtime)
@ -1609,8 +1624,6 @@ class Music(Items):
self.enableimportsongrating = utils.settings('enableImportSongRating') == "true"
self.enableexportsongrating = utils.settings('enableExportSongRating') == "true"
self.enableupdatesongrating = utils.settings('enableUpdateSongRating') == "true"
self.userid = utils.window('currUserId')
self.server = utils.window('pms_server')
def __enter__(self):
"""

View file

@ -237,6 +237,7 @@ class LibrarySync(Thread):
else False
self.enableBackgroundSync = True if utils.settings(
'enableBackgroundSync') == "true" else False
self.limitindex = int(utils.settings('limitindex'))
# Time offset between Kodi and PMS in seconds (=Koditime - PMStime)
self.timeoffset = 0
@ -340,7 +341,8 @@ class LibrarySync(Thread):
xbmc.sleep(2000)
# Get all PMS items to find the item we changed
items = PlexFunctions.GetAllPlexLeaves(libraryId,
lastViewedAt=timestamp)
lastViewedAt=timestamp,
containerSize=self.limitindex)
# Toggle watched state back
PlexFunctions.scrobble(plexId, 'unwatched')
# Get server timestamp for this change
@ -482,7 +484,9 @@ class LibrarySync(Thread):
self.updatelist = []
# Get items per view
items = PlexFunctions.GetAllPlexLeaves(
view['id'], updatedAt=self.getPMSfromKodiTime(lastSync))
view['id'],
updatedAt=self.getPMSfromKodiTime(lastSync),
containerSize=self.limitindex)
# Just skip if something went wrong
if not items:
continue
@ -516,7 +520,9 @@ class LibrarySync(Thread):
songupdate = False
for view in self.views:
items = PlexFunctions.GetAllPlexLeaves(
view['id'], lastViewedAt=self.getPMSfromKodiTime(lastSync))
view['id'],
lastViewedAt=self.getPMSfromKodiTime(lastSync),
containerSize=self.limitindex)
for item in items:
itemId = item.attrib.get('ratingKey')
# Skipping items 'title=All episodes' without a 'ratingKey'
@ -1070,7 +1076,8 @@ class LibrarySync(Thread):
# Get items per view
viewId = view['id']
viewName = view['name']
all_plexmovies = PlexFunctions.GetPlexSectionResults(viewId)
all_plexmovies = PlexFunctions.GetPlexSectionResults(
viewId, args=None, containerSize=self.limitindex)
if not all_plexmovies:
self.logMsg("Couldnt get section items, aborting for view.", 1)
continue
@ -1107,7 +1114,8 @@ class LibrarySync(Thread):
"""
xml = PlexFunctions.GetAllPlexLeaves(viewId,
lastViewedAt=lastViewedAt,
updatedAt=updatedAt)
updatedAt=updatedAt,
containerSize=self.limitindex)
# Return if there are no items in PMS reply - it's faster
try:
xml[0].attrib
@ -1202,7 +1210,8 @@ class LibrarySync(Thread):
# Get items per view
viewId = view['id']
viewName = view['name']
allPlexTvShows = PlexFunctions.GetPlexSectionResults(viewId)
allPlexTvShows = PlexFunctions.GetPlexSectionResults(
viewId, containerSize=self.limitindex)
if not allPlexTvShows:
self.logMsg(
"Error downloading show view xml for view %s" % viewId, -1)
@ -1228,7 +1237,8 @@ class LibrarySync(Thread):
if self.threadStopped():
return False
# Grab all seasons to tvshow from PMS
seasons = PlexFunctions.GetAllPlexChildren(tvShowId)
seasons = PlexFunctions.GetAllPlexChildren(
tvShowId, containerSize=self.limitindex)
if not seasons:
self.logMsg(
"Error downloading season xml for show %s" % tvShowId, -1)
@ -1252,7 +1262,8 @@ class LibrarySync(Thread):
if self.threadStopped():
return False
# Grab all episodes to tvshow from PMS
episodes = PlexFunctions.GetAllPlexLeaves(view['id'])
episodes = PlexFunctions.GetAllPlexLeaves(
view['id'], containerSize=self.limitindex)
if not episodes:
self.logMsg(
"Error downloading episod xml for view %s"
@ -1265,7 +1276,7 @@ class LibrarySync(Thread):
None,
None)
self.logMsg("Analyzed all episodes of TV show with Plex Id %s"
% tvShowId, 1)
% view['id'], 1)
# Process self.updatelist
self.GetAndProcessXMLs(itemType)
@ -1350,7 +1361,7 @@ class LibrarySync(Thread):
viewId = view['id']
viewName = view['name']
itemsXML = PlexFunctions.GetPlexSectionResults(
viewId, args=urlArgs)
viewId, args=urlArgs, containerSize=self.limitindex)
if not itemsXML:
self.logMsg("Error downloading xml for view %s"
% viewId, -1)

View file

@ -155,7 +155,7 @@ class SubscriptionManager:
serv = getServerByHost(self.server)
url = serv.get('protocol', 'http') + '://' \
+ serv.get('server', 'localhost') + ':' \
+ serv.get('port', 32400) + "/:/timeline"
+ serv.get('port', '32400') + "/:/timeline"
self.download.downloadUrl(url, type="GET", parameters=params)
# requests.getwithparams(serv.get('server', 'localhost'), serv.get('port', 32400), "/:/timeline", params, getPlexHeaders(), serv.get('protocol', 'http'))
printDebug("params: %s" % params)

View file

@ -179,9 +179,6 @@ class UserClient(threading.Thread):
if authenticated is False:
self.logMsg('Testing validity of current token', 0)
window('currUserId', value=userId)
window('plex_username', value=username)
window('pms_token', value=self.currToken)
res = PlexAPI.PlexAPI().CheckConnection(
self.currServer, self.currToken)
if res is False:
@ -205,6 +202,7 @@ class UserClient(threading.Thread):
window('pms_server', value=self.currServer)
window('plex_machineIdentifier', value=self.machineIdentifier)
window('plex_servername', value=self.servername)
window('plex_authenticated', value='true')
# Set DownloadUtils values
doUtils.setUsername(username)
@ -331,6 +329,7 @@ class UserClient(threading.Thread):
settings = utils.settings
window = utils.window
window('plex_authenticated', clear=True)
window('pms_token', clear=True)
window('plex_token', clear=True)
window('pms_server', clear=True)
@ -410,7 +409,7 @@ class UserClient(threading.Thread):
self.auth = True
# Minimize CPU load
xbmc.sleep(500)
xbmc.sleep(100)
self.doUtils.stopSession()
log("##===---- UserClient Stopped ----===##", 0)

View file

@ -49,7 +49,7 @@
<setting id="serverSync" type="bool" label="30514" default="true" visible="false"/><!-- Enable fast startup (requires server plugin) -->
<setting id="dbSyncIndicator" label="30507" type="bool" default="true" />
<setting type="sep" /><!-- show syncing progress -->
<setting id="limitindex" type="number" label="30515" default="200" option="int" visible="false"/><!-- Maximum items to request from the server at once -->
<setting id="limitindex" type="number" label="30515" default="200" option="int" /><!-- Maximum items to request from the server at once -->
<setting id="enableTextureCache" label="30512" type="bool" default="true" /> <!-- Force Artwork Caching -->
<setting id="imageCacheLimit" type="enum" label="30513" values="Disabled|5|10|15|20|25" default="5" visible="eq(-1,true)" subsetting="true" /> <!-- Limit artwork cache threads -->
<setting id="syncThreadNumber" type="slider" label="39003" default="5" option="int" range="1,1,20"/>

View file

@ -78,7 +78,8 @@ class Service():
"emby_shouldStop", "currUserId", "emby_dbScan", "emby_sessionId",
"emby_initialScan", "emby_customplaylist", "emby_playbackProps",
"plex_runLibScan", "plex_username", "pms_token", "plex_token",
"pms_server", "plex_machineIdentifier", "plex_servername"
"pms_server", "plex_machineIdentifier", "plex_servername",
"plex_authenticated"
]
for prop in properties:
window(prop, clear=True)