Plex Photos! Choose "Refresh Plex playlists/nodes" to use the new feature

This commit is contained in:
tomkat83 2016-06-19 14:58:42 +02:00
parent 6689b265f2
commit c13343c62f
2 changed files with 112 additions and 75 deletions

View file

@ -2289,19 +2289,80 @@ class API():
self.logMsg('Found external subs: %s' % externalsubs) self.logMsg('Found external subs: %s' % externalsubs)
return externalsubs return externalsubs
def GetFileSize(self): def CreateListItemFromPlexItem(self,
""" listItem=None,
Returns the item's filesize in bytes or 0 (int) if unsuccessful appendShowTitle=False,
""" appendSxxExx=False):
try: if self.getType() == 'photo':
ans = int(self.item[0][0].attrib['size']) listItem = self.__createPhotoListItem(listItem)
except: else:
ans = 0 listItem = self.__createVideoListItem(listItem,
return ans appendShowTitle,
appendSxxExx)
return listItem
def CreateListItemFromPlexItem(self, listItem=None, def GetKodiPremierDate(self):
appendShowTitle=False, appendSxxExx=False):
""" """
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) Call on a child level of PMS xml response (e.g. in a for loop)
listItem : existing xbmcgui.ListItem to work with listItem : existing xbmcgui.ListItem to work with
@ -2318,34 +2379,30 @@ class API():
listItem = xbmcgui.ListItem(title) listItem = xbmcgui.ListItem(title)
listItem.setProperty('IsPlayable', 'true') listItem.setProperty('IsPlayable', 'true')
if typus != 'photo': # Video items, e.g. movies and episodes or clips
# Video items, e.g. movies and episodes or clips people = self.getPeople()
people = self.getPeople() userdata = self.getUserData()
userdata = self.getUserData() metadata = {
metadata = { 'genre': self.joinList(self.getGenres()),
'genre': self.joinList(self.getGenres()), 'year': self.getYear(),
'year': self.getYear(), 'rating': self.getAudienceRating(),
'rating': self.getAudienceRating(), 'playcount': userdata['PlayCount'],
'playcount': userdata['PlayCount'], 'cast': people['Cast'],
'cast': people['Cast'], 'director': self.joinList(people.get('Director')),
'director': self.joinList(people.get('Director')), 'plot': self.getPlot(),
'plot': self.getPlot(), 'sorttitle': sorttitle,
'sorttitle': sorttitle, 'duration': userdata['Runtime'],
'duration': userdata['Runtime'], 'studio': self.joinList(self.getStudios()),
'studio': self.joinList(self.getStudios()), 'tagline': self.getTagline(),
'tagline': self.getTagline(), 'writer': self.joinList(people.get('Writer')),
'writer': self.joinList(people.get('Writer')), 'premiered': self.getPremiereDate(),
'premiered': self.getPremiereDate(), 'dateadded': self.getDateCreated(),
'dateadded': self.getDateCreated(), 'lastplayed': userdata['LastPlayedDate'],
'lastplayed': userdata['LastPlayedDate'], 'mpaa': self.getMpaa(),
'mpaa': self.getMpaa(), 'aired': self.getPremiereDate()
'aired': self.getPremiereDate() }
} listItem.setProperty('resumetime', str(userdata['Resume']))
listItem.setProperty('resumetime', str(userdata['Resume'])) listItem.setProperty('totaltime', str(userdata['Runtime']))
listItem.setProperty('totaltime', str(userdata['Runtime']))
else:
# E.g. photo
metadata = {'size': self.GetFileSize()}
if typus == "episode": if typus == "episode":
# Only for tv shows # Only for tv shows
@ -2362,11 +2419,9 @@ class API():
title = "S%.2dE%.2d - %s" % (season, episode, title) title = "S%.2dE%.2d - %s" % (season, episode, title)
listItem.setIconImage('DefaultTVShows.png') listItem.setIconImage('DefaultTVShows.png')
if appendShowTitle is True: if appendShowTitle is True:
title = show + ' - ' + title title = "%s - %s " % (show, title)
elif typus == "movie": elif typus == "movie":
listItem.setIconImage('DefaultMovies.png') listItem.setIconImage('DefaultMovies.png')
elif typus == "photo":
listItem.setIconImage('DefaultPicture.png')
else: else:
# E.g. clips, trailers, ... # E.g. clips, trailers, ...
listItem.setIconImage('DefaultVideo.png') listItem.setIconImage('DefaultVideo.png')
@ -2382,10 +2437,7 @@ class API():
# Expensive operation # Expensive operation
metadata['title'] = title metadata['title'] = title
listItem.setLabel(title) listItem.setLabel(title)
if typus != 'photo': listItem.setInfo('video', infoLabels=metadata)
listItem.setInfo('video', infoLabels=metadata)
else:
listItem.setInfo('pictures', infoLabels=metadata)
return listItem return listItem
def AddStreamInfo(self, listItem): def AddStreamInfo(self, listItem):

View file

@ -1393,56 +1393,41 @@ def BrowsePlexContent(viewid, mediatype="", folderid=""):
xml.attrib.get('librarySectionTitle')) xml.attrib.get('librarySectionTitle'))
# set the correct params for the content type # set the correct params for the content type
if mediatype.lower() == "homevideos, tvshows": if mediatype == "photos":
xbmcplugin.setContent(int(sys.argv[1]), 'episodes') xbmcplugin.setContent(int(sys.argv[1]), 'photos')
elif mediatype.lower() == "photos":
xbmcplugin.setContent(int(sys.argv[1]), 'files')
# process the listing # process the listing
for item in xml: for item in xml:
API = PlexAPI.API(item) API = PlexAPI.API(item)
li = API.CreateListItemFromPlexItem()
if item.tag == 'Directory': if item.tag == 'Directory':
li = xbmcgui.ListItem(item.attrib.get('title', 'Missing title'))
# for folders we add an additional browse request, passing the # for folders we add an additional browse request, passing the
# folderId # folderId
li.setProperty('IsFolder', 'true') li.setProperty('IsFolder', 'true')
li.setProperty('IsPlayable', 'false') li.setProperty('IsPlayable', 'false')
path = "%s?id=%s&mode=browseplex&type=%s&folderid=%s" \ path = "%s?id=%s&mode=browseplex&type=%s&folderid=%s" \
% (sys.argv[0], viewid, mediatype, API.getKey()) % (sys.argv[0], viewid, mediatype, API.getKey())
pbutils.PlaybackUtils(item).setArtwork(li)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
url=path, url=path,
listitem=li, listitem=li,
isFolder=True) isFolder=True)
else: else:
if item.attrib.get('type') == 'photo': li = API.CreateListItemFromPlexItem()
# 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)
pbutils.PlaybackUtils(item).setArtwork(li) pbutils.PlaybackUtils(item).setArtwork(li)
xbmcplugin.addDirectoryItem( xbmcplugin.addDirectoryItem(
handle=int(sys.argv[1]), handle=int(sys.argv[1]),
url=path, url=li.getProperty("path"),
listitem=li) listitem=li)
if filter == "recent": xbmcplugin.addSortMethod(int(sys.argv[1]),
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) xbmcplugin.SORT_METHOD_VIDEO_TITLE)
else: xbmcplugin.addSortMethod(int(sys.argv[1]),
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_TITLE) xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(int(sys.argv[1]),
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_VIDEO_RATING) 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_RUNTIME)
xbmcplugin.endOfDirectory( xbmcplugin.endOfDirectory(
handle=int(sys.argv[1]), handle=int(sys.argv[1]),