def buildEpisode(args, opts): query = args[0] from MythTV.tmdb3 import Series, Season, Episode from MythTV import VideoMetadata from lxml import etree from MythTV.tmdb3 import searchSeries if query.isnumeric(): inetref = query else: results = searchSeries(query) series = results[0] inetref = str(series.id) series = Series(inetref) season_number = series.number_of_seasons episode_number = None subtitle = None if len(args) == 2: subtitle = args[1] elif len(args) == 3: season_number = int(args[1]) episode_number = int(args[2]) episode = None # process seasons backwards because it is more likely # that you have a recent one than an old one while season_number > 0: season = Season(inetref, str(season_number)) if episode_number: episode = season.episodes[episode_number] break for ep_num, ep in season.episodes.items(): if ep.name == subtitle: episode = ep episode_number = int(ep_num) break if episode: break season_number = season_number - 1 if not episode_number and not episode: sys.stdout.write('ERROR: Episode not found: ' + str(args)) return 9 # reload episode with full details episode = Episode(inetref, season_number, episode_number) tree = etree.XML(u'<metadata></metadata>') mapping = [['subtitle', 'name'], ['description', 'overview'], ['season', 'season_number'], ['episode', 'episode_number'], ['releasedate', 'air_date']] m = VideoMetadata() m.title = series.name for i, j in mapping: if getattr(episode, j): setattr(m, i, getattr(episode, j)) # These need to be strings not ints m.inetref = inetref m.collectionref = inetref for cast in episode.cast: d = { 'name': cast.name, 'character': cast.character, 'department': 'Actors', 'job': 'Actor', 'url': 'http://www.themoviedb.org/people/{0}'.format(cast.id) } if cast.profile: d['thumb'] = cast.profile.geturl() m.people.append(d) for crew in episode.crew: d = { 'name': crew.name, 'job': crew.job, 'department': crew.department, 'url': 'http://www.themoviedb.org/people/{0}'.format(crew.id) } if crew.profile: d['thumb'] = crew.profile.geturl() m.people.append(d) for guest in episode.guest_stars: d = { 'name': guest.name, 'job': "Guest Star", 'url': 'http://www.themoviedb.org/people/{0}'.format(guest.id) } if guest.profile: d['thumb'] = guest.profile.geturl() m.people.append(d) if episode.still: b = episode.still m.images.append({ 'type': 'screenshot', 'url': b.geturl(), 'thumb': b.geturl(b.sizes()[0]) }) if season.poster: p = season.poster m.images.append({ 'type': 'coverart', 'url': p.geturl(), 'thumb': p.geturl(p.sizes()[0]) }) m.language = series.original_language if series.backdrop: b = series.backdrop m.images.append({ 'type': 'fanart', 'url': b.geturl(), 'thumb': b.geturl(b.sizes()[0]) }) for genre in series.genres: m.categories.append(genre.name) tree.append(m.toXML()) return etree.tostring(tree, encoding='UTF-8', pretty_print=True, xml_declaration=True)
def buildTVList(query, opts): from MythTV.tmdb3 import searchSeries from MythTV import VideoMetadata from lxml import etree from datetime import date resultsx = searchSeries(query) results = iter(resultsx) # searchSeries(query)) mapping = [['language', 'original_language'], ['title', 'name'], ['inetref', 'id'], ['collectionref', 'id'], ['description', 'overview'], ['releasedate', 'first_air_date']] tree = etree.XML(u'<metadata></metadata>') count = 0 while True: try: res = next(results) except StopIteration: # end of results break except IndexError: # unexpected end of results # we still want to return whatever we have so far break if res is None: # faulty data, skip it and continue continue m = VideoMetadata() for i, j in mapping: if getattr(res, j): setattr(m, i, getattr(res, j)) # These need to be strings not ints m.inetref = str(res.id) m.collectionref = str(res.id) if res.backdrop: b = res.backdrop m.images.append({ 'type': 'fanart', 'url': b.geturl(), 'thumb': b.geturl(b.sizes()[0]) }) if res.poster: p = res.poster m.images.append({ 'type': 'coverart', 'url': p.geturl(), 'thumb': p.geturl(p.sizes()[0]) }) tree.append(m.toXML()) count += 1 if count >= 60: # page limiter, dont want to overload the server break return etree.tostring(tree, encoding='UTF-8', pretty_print=True, xml_declaration=True)