Plex Photos! Choose "Refresh Plex playlists/nodes" to use the new feature
This commit is contained in:
parent
6689b265f2
commit
c13343c62f
2 changed files with 112 additions and 75 deletions
|
@ -2289,19 +2289,80 @@ class API():
|
|||
self.logMsg('Found external subs: %s' % externalsubs)
|
||||
return externalsubs
|
||||
|
||||
def GetFileSize(self):
|
||||
"""
|
||||
Returns the item's filesize in bytes or 0 (int) if unsuccessful
|
||||
"""
|
||||
try:
|
||||
ans = int(self.item[0][0].attrib['size'])
|
||||
except:
|
||||
ans = 0
|
||||
return ans
|
||||
def CreateListItemFromPlexItem(self,
|
||||
listItem=None,
|
||||
appendShowTitle=False,
|
||||
appendSxxExx=False):
|
||||
if self.getType() == 'photo':
|
||||
listItem = self.__createPhotoListItem(listItem)
|
||||
else:
|
||||
listItem = self.__createVideoListItem(listItem,
|
||||
appendShowTitle,
|
||||
appendSxxExx)
|
||||
return listItem
|
||||
|
||||
def CreateListItemFromPlexItem(self, listItem=None,
|
||||
appendShowTitle=False, appendSxxExx=False):
|
||||
def GetKodiPremierDate(self):
|
||||
"""
|
||||
Takes Plex' originallyAvailableAt of the form "yyyy-mm-dd" and returns
|
||||
Kodi's "dd.mm.yyyy"
|
||||
"""
|
||||
date = self.getPremiereDate()
|
||||
if date is None:
|
||||
return
|
||||
try:
|
||||
date = re.sub(r'(\d+)-(\d+)-(\d+)', r'\3.\2.\1', date)
|
||||
except:
|
||||
date = None
|
||||
return date
|
||||
|
||||
def __createPhotoListItem(self, listItem=None):
|
||||
"""
|
||||
Use for photo items only
|
||||
"""
|
||||
title, _ = self.getTitle()
|
||||
if listItem is None:
|
||||
listItem = xbmcgui.ListItem(title)
|
||||
else:
|
||||
listItem.setLabel(title)
|
||||
listItem.setProperty('IsPlayable', 'true')
|
||||
# Always use HTTP, not direct paths
|
||||
# Kodi has problems accessing photos directly
|
||||
path = '%s%s' % (utils.window('pms_server'),
|
||||
self.item[0][0].attrib['key'])
|
||||
path = utils.tryEncode(self.addPlexCredentialsToUrl(path))
|
||||
metadata = {
|
||||
'date': self.GetKodiPremierDate(),
|
||||
'picturepath': path,
|
||||
'size': long(self.item[0][0].attrib.get('size', 0)),
|
||||
'exif:width': self.item[0].attrib.get('width', ''),
|
||||
'exif:height': self.item[0].attrib.get('height', ''),
|
||||
'title': title
|
||||
}
|
||||
listItem.setInfo('pictures', infoLabels=metadata)
|
||||
try:
|
||||
if int(metadata['exif:width']) > int(metadata['exif:height']):
|
||||
# add image as fanart for use with skinhelper auto thumb/
|
||||
# backgrund creation
|
||||
listItem.setArt({'fanart': path})
|
||||
except ValueError:
|
||||
pass
|
||||
# Stuff that we CANNOT set with listItem.setInfo
|
||||
listItem.setProperty('path', path)
|
||||
listItem.setProperty('plot', self.getPlot())
|
||||
listItem.setProperty('plexid', self.getRatingKey())
|
||||
# We do NOT set these props
|
||||
# listItem.setProperty('isPlayable', 'true')
|
||||
# listItem.setProperty('isFolder', 'true')
|
||||
# Further stuff
|
||||
listItem.setIconImage('DefaultPicture.png')
|
||||
return listItem
|
||||
|
||||
def __createVideoListItem(self,
|
||||
listItem=None,
|
||||
appendShowTitle=False,
|
||||
appendSxxExx=False):
|
||||
"""
|
||||
Use for video items only
|
||||
Call on a child level of PMS xml response (e.g. in a for loop)
|
||||
|
||||
listItem : existing xbmcgui.ListItem to work with
|
||||
|
@ -2318,7 +2379,6 @@ class API():
|
|||
listItem = xbmcgui.ListItem(title)
|
||||
listItem.setProperty('IsPlayable', 'true')
|
||||
|
||||
if typus != 'photo':
|
||||
# Video items, e.g. movies and episodes or clips
|
||||
people = self.getPeople()
|
||||
userdata = self.getUserData()
|
||||
|
@ -2343,9 +2403,6 @@ class API():
|
|||
}
|
||||
listItem.setProperty('resumetime', str(userdata['Resume']))
|
||||
listItem.setProperty('totaltime', str(userdata['Runtime']))
|
||||
else:
|
||||
# E.g. photo
|
||||
metadata = {'size': self.GetFileSize()}
|
||||
|
||||
if typus == "episode":
|
||||
# Only for tv shows
|
||||
|
@ -2362,11 +2419,9 @@ class API():
|
|||
title = "S%.2dE%.2d - %s" % (season, episode, title)
|
||||
listItem.setIconImage('DefaultTVShows.png')
|
||||
if appendShowTitle is True:
|
||||
title = show + ' - ' + title
|
||||
title = "%s - %s " % (show, title)
|
||||
elif typus == "movie":
|
||||
listItem.setIconImage('DefaultMovies.png')
|
||||
elif typus == "photo":
|
||||
listItem.setIconImage('DefaultPicture.png')
|
||||
else:
|
||||
# E.g. clips, trailers, ...
|
||||
listItem.setIconImage('DefaultVideo.png')
|
||||
|
@ -2382,10 +2437,7 @@ class API():
|
|||
# Expensive operation
|
||||
metadata['title'] = title
|
||||
listItem.setLabel(title)
|
||||
if typus != 'photo':
|
||||
listItem.setInfo('video', infoLabels=metadata)
|
||||
else:
|
||||
listItem.setInfo('pictures', infoLabels=metadata)
|
||||
return listItem
|
||||
|
||||
def AddStreamInfo(self, listItem):
|
||||
|
|
|
@ -1393,56 +1393,41 @@ def BrowsePlexContent(viewid, mediatype="", folderid=""):
|
|||
xml.attrib.get('librarySectionTitle'))
|
||||
|
||||
# set the correct params for the content type
|
||||
if mediatype.lower() == "homevideos, tvshows":
|
||||
xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
|
||||
elif mediatype.lower() == "photos":
|
||||
xbmcplugin.setContent(int(sys.argv[1]), 'files')
|
||||
if mediatype == "photos":
|
||||
xbmcplugin.setContent(int(sys.argv[1]), 'photos')
|
||||
|
||||
# process the listing
|
||||
for item in xml:
|
||||
API = PlexAPI.API(item)
|
||||
li = API.CreateListItemFromPlexItem()
|
||||
if item.tag == 'Directory':
|
||||
li = xbmcgui.ListItem(item.attrib.get('title', 'Missing title'))
|
||||
# for folders we add an additional browse request, passing the
|
||||
# folderId
|
||||
li.setProperty('IsFolder', 'true')
|
||||
li.setProperty('IsPlayable', 'false')
|
||||
path = "%s?id=%s&mode=browseplex&type=%s&folderid=%s" \
|
||||
% (sys.argv[0], viewid, mediatype, API.getKey())
|
||||
pbutils.PlaybackUtils(item).setArtwork(li)
|
||||
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
|
||||
url=path,
|
||||
listitem=li,
|
||||
isFolder=True)
|
||||
else:
|
||||
if item.attrib.get('type') == 'photo':
|
||||
# pictures
|
||||
if utils.settings('useDirectPaths') == '0':
|
||||
# Addon paths
|
||||
path = '%s%s' % (utils.window('pms_server'),
|
||||
item[0][0].attrib['key'])
|
||||
path = API.addPlexCredentialsToUrl(path)
|
||||
else:
|
||||
# Direct paths
|
||||
path = item[0][0].attrib['file']
|
||||
li.setProperty('picturepath', path)
|
||||
else:
|
||||
# videos
|
||||
path = "%s?id=%s&mode=play" % (sys.argv[0], API.getRatingKey())
|
||||
li.setProperty("path", path)
|
||||
API.AddStreamInfo(li)
|
||||
li = API.CreateListItemFromPlexItem()
|
||||
pbutils.PlaybackUtils(item).setArtwork(li)
|
||||
xbmcplugin.addDirectoryItem(
|
||||
handle=int(sys.argv[1]),
|
||||
url=path,
|
||||
url=li.getProperty("path"),
|
||||
listitem=li)
|
||||
|
||||
if filter == "recent":
|
||||
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)
|
||||
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)
|
||||
|
||||
xbmcplugin.endOfDirectory(
|
||||
handle=int(sys.argv[1]),
|
||||
|
|
Loading…
Reference in a new issue