Code:
def _fetch_tvshows(self, request):
if not xbmc.abortRequested:
season_folders = __addon__.getSetting("randomitems_seasonfolders")
json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetEpisodes", "params": { "properties": ["title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime"], "limits": {"end": %d},' %self.LIMIT
if request == 'RecentEpisode' and self.RECENTITEMS_UNPLAYED:
json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}}}' %json_string)
elif request == 'RecentEpisode':
json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}}}' %json_string)
elif request == 'RandomEpisode' and self.RANDOMITEMS_UNPLAYED:
json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" }, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}}}' %json_string)
else:
json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" }}}' %json_string)
json_query = unicode(json_query, 'utf-8', errors='ignore')
json_query = simplejson.loads(json_query)
if json_query.has_key('result') and json_query['result'].has_key('episodes'):
self._clear_properties(request)
count = 0
for item in json_query['result']['episodes']:
count += 1
'''
# This part is commented out because it takes 1.5second extra on my system to request these which doubles the total time.
# Hence the ugly path hack that will require users to have season folders.
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShowDetails", "params": {"properties": ["file", "studio"], "tvshowid":%s}, "id": 1}' %item['tvshowid'])
json_query2 = unicode(json_query2, 'utf-8', errors='ignore')
json_query2 = simplejson.loads(json_query2)
path = json_query2['result']['tvshowdetails']['file']
studio = json_query2['result']['tvshowdetails']['studio'][0]
'''
if season_folders == 'true':
path = os.path.split(media_path(item['file']))[0]
else:
path = media_path(item['file'])
episode = ("%.2d" % float(item['episode']))
season = "%.2d" % float(item['season'])
episodeno = "s%se%s" %(season,episode)
#seasonthumb = ''
rating = str(round(float(item['rating']),1))
if (item['resume']['position'] and item['resume']['total']) > 0:
resume = "true"
played = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
else:
resume = "false"
played = '0%'
if item['playcount'] >= 1:
watched = "true"
else:
watched = "false"
if not self.PLOT_ENABLE and watched == "false":
plot = __localize__(32014)
else:
plot = item['plot']
art = item['art']
path = media_path(item['file'])
play = 'XBMC.RunScript(' + __addonid__ + ',episodeid=' + str(item.get('episodeid')) + ')'
streaminfo = media_streamdetails(item['file'].encode('utf-8').lower(),
item['streamdetails'])
self.WINDOW.setProperty("%s.%d.DBID" % (request, count), str(item.get('episodeid')))
self.WINDOW.setProperty("%s.%d.Title" % (request, count), item['title'])
self.WINDOW.setProperty("%s.%d.Episode" % (request, count), episode)
self.WINDOW.setProperty("%s.%d.EpisodeNo" % (request, count), episodeno)
self.WINDOW.setProperty("%s.%d.Season" % (request, count), season)
self.WINDOW.setProperty("%s.%d.Plot" % (request, count), plot)
self.WINDOW.setProperty("%s.%d.TVshowTitle" % (request, count), item['showtitle'])
self.WINDOW.setProperty("%s.%d.Rating" % (request, count), rating)
self.WINDOW.setProperty("%s.%d.Runtime" % (request, count), str(int((item['runtime'] / 60) + 0.5)))
self.WINDOW.setProperty("%s.%d.Premiered" % (request, count), item['firstaired'])
self.WINDOW.setProperty("%s.%d.Art(thumb)" % (request, count), art.get('thumb',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.fanart)" % (request, count), art.get('tvshow.fanart',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.poster)" % (request, count), art.get('tvshow.poster',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.banner)" % (request, count), art.get('tvshow.banner',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.clearlogo)"% (request, count), art.get('tvshow.clearlogo',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.clearart)" % (request, count), art.get('tvshow.clearart',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.landscape)"% (request, count), art.get('tvshow.landscape',''))
self.WINDOW.setProperty("%s.%d.Art(tvshow.characterart)"% (request, count), art.get('tvshow.characterart',''))
self.WINDOW.setProperty("%s.%d.Resume" % (request, count), resume)
self.WINDOW.setProperty("%s.%d.PercentPlayed" % (request, count), played)
self.WINDOW.setProperty("%s.%d.Watched" % (request, count), watched)
self.WINDOW.setProperty("%s.%d.File" % (request, count), item['file'])
self.WINDOW.setProperty("%s.%d.Path" % (request, count), path)
self.WINDOW.setProperty("%s.%d.Play" % (request, count), play)
self.WINDOW.setProperty("%s.%d.VideoCodec" % (request, count), streaminfo['videocodec'])
self.WINDOW.setProperty("%s.%d.VideoResolution" % (request, count), streaminfo['videoresolution'])
self.WINDOW.setProperty("%s.%d.VideoAspect" % (request, count), streaminfo['videoaspect'])
self.WINDOW.setProperty("%s.%d.AudioCodec" % (request, count), streaminfo['audiocodec'])
self.WINDOW.setProperty("%s.%d.AudioChannels" % (request, count), str(streaminfo['audiochannels']))
del json_query