def _seasonCount(self, tvshowtitle, year, imdb, tvdb): if imdb == '0': try: imdb = trakt.SearchTVShow(quote_plus(tvshowtitle), year, full=False)[0] imdb = imdb.get('show', '0') imdb = imdb.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub(r'[^0-9]', '', str(imdb)) if not imdb: imdb = '0' except: log_utils.error() imdb = '0' ###--Check TVDb by IMDB_ID for missing if tvdb == '0' and imdb != '0': try: tvdb = tvdb_v1.getSeries_ByIMDB(tvshowtitle, year, imdb) or '0' except: tvdb = '0' ########################## ###--Check TVDb by seriesname if tvdb == '0': try: ids = tvdb_v1.getSeries_ByName(tvshowtitle, year) if ids: tvdb = ids.get(tvdb, '0') or '0' except: tvdb = '0' log_utils.error() ########################## if tvdb == '0': return None try: result = tvdb_v1.getZip(tvdb) dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile(r'[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]).encode('utf-8') result = tvdb_v1.getZip(tvdb) result = result.split('<Episode>') return self.seasonCountParse(items=result) except: log_utils.error() return None
def super_info(self, i): try: if self.list[i]['metacache'] == True: raise Exception() imdb = self.list[i]['imdb'] if 'imdb' in self.list[i] else '0' tvdb = self.list[i]['tvdb'] if 'tvdb' in self.list[i] else '0' if imdb == '0': try: imdb = trakt.SearchTVShow(urllib.quote_plus(self.list[i]['title']), self.list[i]['year'], full=False)[0] imdb = imdb.get('show', '0') imdb = imdb.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) if not imdb: imdb = '0' except: imdb = '0' if tvdb == '0' and not imdb == '0': url = self.tvdb_by_imdb % imdb result = client.request(url, timeout='10') try: tvdb = client.parseDOM(result, 'seriesid')[0] except: tvdb = '0' try: name = client.parseDOM(result, 'SeriesName')[0] except: name = '0' dupe = re.findall('[***]Duplicate (\d*)[***]', name) if dupe: tvdb = str(dupe[0]) if tvdb == '': tvdb = '0' if tvdb == '0': url = self.tvdb_by_query % (urllib.quote_plus(self.list[i]['title'])) years = [str(self.list[i]['year']), str(int(self.list[i]['year'])+1), str(int(self.list[i]['year'])-1)] tvdb = client.request(url, timeout='10') tvdb = re.sub(r'[^\x00-\x7F]+', '', tvdb) tvdb = client.replaceHTMLCodes(tvdb) tvdb = client.parseDOM(tvdb, 'Series') tvdb = [(x, client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired')) for x in tvdb] tvdb = [(x, x[1][0], x[2][0]) for x in tvdb if len(x[1]) > 0 and len(x[2]) > 0] tvdb = [x for x in tvdb if cleantitle.get(self.list[i]['title']) == cleantitle.get(x[1])] tvdb = [x[0][0] for x in tvdb if any(y in x[2] for y in years)][0] tvdb = client.parseDOM(tvdb, 'seriesid')[0] if tvdb == '': tvdb = '0' url = self.tvdb_info_link % tvdb item = client.request(url, timeout='10') if item == None: raise Exception() if imdb == '0': try: imdb = client.parseDOM(item, 'IMDB_ID')[0] except: pass if imdb == '': imdb = '0' imdb = imdb.encode('utf-8') try: title = client.parseDOM(item, 'SeriesName')[0] except: title = '' if title == '': title = '0' title = client.replaceHTMLCodes(title) title = title.encode('utf-8') try: year = client.parseDOM(item, 'FirstAired')[0] except: year = '' try: year = re.compile('(\d{4})').findall(year)[0] except: year = '' if year == '': year = '0' year = year.encode('utf-8') try: premiered = client.parseDOM(item, 'FirstAired')[0] except: premiered = '0' if premiered == '': premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') try: studio = client.parseDOM(item, 'Network')[0] except: studio = '' if studio == '': studio = '0' studio = client.replaceHTMLCodes(studio) studio = studio.encode('utf-8') try: genre = client.parseDOM(item, 'Genre')[0] except: genre = '' genre = [x for x in genre.split('|') if not x == ''] genre = ' / '.join(genre) if genre == '': genre = '0' genre = client.replaceHTMLCodes(genre) genre = genre.encode('utf-8') try: duration = client.parseDOM(item, 'Runtime')[0] except: duration = '' if duration == '': duration = '0' duration = client.replaceHTMLCodes(duration) duration = duration.encode('utf-8') try: rating = client.parseDOM(item, 'Rating')[0] except: rating = '' if 'rating' in self.list[i] and not self.list[i]['rating'] == '0': rating = self.list[i]['rating'] if rating == '': rating = '0' rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') try: votes = client.parseDOM(item, 'RatingCount')[0] except: votes = '' if 'votes' in self.list[i] and not self.list[i]['votes'] == '0': votes = self.list[i]['votes'] if votes == '': votes = '0' votes = client.replaceHTMLCodes(votes) votes = votes.encode('utf-8') try: mpaa = client.parseDOM(item, 'ContentRating')[0] except: mpaa = '' if mpaa == '': mpaa = '0' mpaa = client.replaceHTMLCodes(mpaa) mpaa = mpaa.encode('utf-8') try: cast = client.parseDOM(item, 'Actors')[0] except: cast = '' cast = [x for x in cast.split('|') if not x == ''] try: cast = [(x.encode('utf-8'), '') for x in cast] except: cast = [] if cast == []: cast = '0' try: plot = client.parseDOM(item, 'Overview')[0] except: plot = '' if plot == '': plot = '0' plot = client.replaceHTMLCodes(plot) plot = plot.encode('utf-8') try: poster = client.parseDOM(item, 'poster')[0] except: poster = '' if not poster == '': poster = self.tvdb_image + poster else: poster = '0' if 'poster' in self.list[i] and poster == '0': poster = self.list[i]['poster'] poster = client.replaceHTMLCodes(poster) poster = poster.encode('utf-8') try: banner = client.parseDOM(item, 'banner')[0] except: banner = '' if not banner == '': banner = self.tvdb_image + banner else: banner = '0' banner = client.replaceHTMLCodes(banner) banner = banner.encode('utf-8') try: fanart = client.parseDOM(item, 'fanart')[0] except: fanart = '' if not fanart == '': fanart = self.tvdb_image + fanart else: fanart = '0' fanart = client.replaceHTMLCodes(fanart) fanart = fanart.encode('utf-8') try: artmeta = True if self.fanart_tv_user == '': raise Exception() art = client.request(self.fanart_tv_art_link % tvdb, headers=self.fanart_tv_headers, timeout='10', error=True) try: art = json.loads(art) except: artmeta = False except: pass try: poster2 = art['tvposter'] poster2 = [x for x in poster2 if x.get('lang') == 'en'][::-1] + [x for x in poster2 if x.get('lang') == '00'][::-1] poster2 = poster2[0]['url'].encode('utf-8') except: poster2 = '0' try: fanart2 = art['showbackground'] fanart2 = [x for x in fanart2 if x.get('lang') == 'en'][::-1] + [x for x in fanart2 if x.get('lang') == '00'][::-1] fanart2 = fanart2[0]['url'].encode('utf-8') except: fanart2 = '0' try: banner2 = art['tvbanner'] banner2 = [x for x in banner2 if x.get('lang') == 'en'][::-1] + [x for x in banner2 if x.get('lang') == '00'][::-1] banner2 = banner2[0]['url'].encode('utf-8') except: banner2 = '0' try: if 'hdtvlogo' in art: clearlogo = art['hdtvlogo'] else: clearlogo = art['clearlogo'] clearlogo = [x for x in clearlogo if x.get('lang') == 'en'][::-1] + [x for x in clearlogo if x.get('lang') == '00'][::-1] clearlogo = clearlogo[0]['url'].encode('utf-8') except: clearlogo = '0' try: if 'hdclearart' in art: clearart = art['hdclearart'] else: clearart = art['clearart'] clearart = [x for x in clearart if x.get('lang') == 'en'][::-1] + [x for x in clearart if x.get('lang') == '00'][::-1] clearart = clearart[0]['url'].encode('utf-8') except: clearart = '0' item = {'title': title, 'year': year, 'imdb': imdb, 'tvdb': tvdb, 'poster': poster, 'poster2': poster2, 'banner': banner, 'banner2': banner2, 'fanart': fanart, 'fanart2': fanart2, 'clearlogo': clearlogo, 'clearart': clearart, 'premiered': premiered, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'cast': cast, 'plot': plot} item = dict((k,v) for k, v in item.iteritems() if not v == '0') self.list[i].update(item) if artmeta == False: raise Exception() meta = {'imdb': imdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.user, 'item': item} self.meta.append(meta) except: pass
def super_info(self, i): try: if self.list[i]['metacache']: return imdb = self.list[i].get('imdb', '') ; tmdb = self.list[i].get('tmdb', '') ; tvdb = self.list[i].get('tvdb', '') #### -- Missing id's lookup -- #### trakt_ids = None if (not tmdb or not tvdb) and imdb: trakt_ids = trakt.IdLookup('imdb', imdb, 'show') if (not tmdb or not imdb) and tvdb: trakt_ids = trakt.IdLookup('tvdb', tvdb, 'show') if trakt_ids: if not imdb: imdb = str(trakt_ids.get('imdb', '')) if trakt_ids.get('imdb') else '' if not tmdb: tmdb = str(trakt_ids.get('tmdb', '')) if trakt_ids.get('tmdb') else '' if not tvdb: tvdb = str(trakt_ids.get('tvdb', '')) if trakt_ids.get('tvdb') else '' if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id', '')) if result.get('id') else '' except: tmdb = '' if not imdb or not tmdb or not tvdb: try: results = trakt.SearchTVShow(quote_plus(self.list[i]['title']), self.list[i]['year'], full=False) if results[0]['show']['title'].lower() != self.list[i]['title'].lower() or int(results[0]['show']['year']) != int(self.list[i]['year']): return # Trakt has "THEM" and "Them" twice for same show, use .lower() ids = results[0].get('show', {}).get('ids', {}) if not imdb: imdb = str(ids.get('imdb', '')) if ids.get('imdb') else '' if not tmdb: tmdb = str(ids.get('tmdb', '')) if ids.get('tmdb') else '' if not tvdb: tvdb = str(ids.get('tvdb', '')) if ids.get('tvdb') else '' except: pass ################################# if not tmdb: if control.setting('debug.level') != '1': return from resources.lib.modules import log_utils log_utils.log('tvshowtitle: (%s) missing tmdb_id' % self.list[i]['title'], __name__, log_utils.LOGDEBUG) # log TMDb shows that they do not have showSeasons = cache.get(tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) if not showSeasons: return values = {} values.update(showSeasons) if not tvdb: tvdb = values.get('tvdb', '') if not values.get('imdb'): values['imdb'] = imdb if not values.get('tmdb'): values['tmdb'] = tmdb if not values.get('tvdb'): values['tvdb'] = tvdb if self.lang != 'en': try: # if self.lang == 'en' or self.lang not in values.get('available_translations', [self.lang]): raise Exception() trans_item = trakt.getTVShowTranslation(imdb, lang=self.lang, full=True) if trans_item: if trans_item.get('title'): values['tvshowtitle'] = trans_item.get('title') values['title'] = trans_item.get('title') if trans_item.get('overview'): values['plot'] =trans_item.get('overview') except: from resources.lib.modules import log_utils log_utils.error() if not self.disable_fanarttv: extended_art = cache.get(fanarttv.get_tvshow_art, 168, tvdb) if extended_art: values.update(extended_art) values = dict((k, v) for k, v in iter(values.items()) if v is not None and v != '') # remove empty keys so .update() doesn't over-write good meta with empty values. self.list[i].update(values) meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.user, 'item': values} self.meta.append(meta) except: from resources.lib.modules import log_utils log_utils.error()
def _seasonCount(self, tvshowtitle, year, imdb, tvdb): try: if imdb == '0': try: imdb = trakt.SearchTVShow(urllib.quote_plus(tvshowtitle), year, full=False)[0] imdb = imdb.get('show', '0') imdb = imdb.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) if not imdb: imdb = '0' except: imdb = '0' if tvdb == '0' and not imdb == '0': url = self.tvdb_by_imdb % imdb result = client.request(url, timeout='10') try: tvdb = client.parseDOM(result, 'seriesid')[0] except: tvdb = '0' try: name = client.parseDOM(result, 'SeriesName')[0] except: name = '0' dupe = re.compile('[***]Duplicate (\d*)[***]').findall(name) if len(dupe) > 0: tvdb = str(dupe[0]) if tvdb == '': tvdb = '0' if tvdb == '0': url = self.tvdb_by_query % (urllib.quote_plus(tvshowtitle)) years = [str(year), str(int(year) + 1), str(int(year) - 1)] tvdb = client.request(url, timeout='10') tvdb = re.sub(r'[^\x00-\x7F]+', '', tvdb) tvdb = client.replaceHTMLCodes(tvdb) tvdb = client.parseDOM(tvdb, 'Series') tvdb = [(x, client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired')) for x in tvdb] tvdb = [(x, x[1][0], x[2][0]) for x in tvdb if len(x[1]) > 0 and len(x[2]) > 0] tvdb = [ x for x in tvdb if cleantitle.get(tvshowtitle) == cleantitle.get(x[1]) ] tvdb = [ x[0][0] for x in tvdb if any(y in x[2] for y in years) ][0] tvdb = client.parseDOM(tvdb, 'seriesid')[0] if tvdb == '': tvdb = '0' except: return None try: if tvdb == '0': return None url = self.tvdb_info_link % (tvdb, 'en') data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result = zip.read('%s.xml' % 'en') zip.close() dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile('[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]).encode('utf-8') url = self.tvdb_info_link % (tvdb, 'en') data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result = zip.read('%s.xml' % 'en') zip.close() result = result.split('<Episode>') return self.seasonCountParse(items=result) except: return None
def tvdb_list(self, tvshowtitle, year, imdb, tvdb, lang, limit=''): try: if imdb == '0': try: trakt_ids = trakt.SearchTVShow( urllib.quote_plus(tvshowtitle), year, full=False)[0] trakt_ids = trakt_ids.get('show', '0') imdb = trakt_ids.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) if not imdb: imdb = '0' except: imdb = '0' # if tmdb == '0': # try: # tmdb = trakt_ids.get('ids', {}).get('tmdb', '0') # tmdb = re.sub('[^0-9]', '', str(tmdb)) # if not tmdb: # tmdb = '0' # except: # tmdb = '0' if tvdb == '0' and not imdb == '0': url = self.tvdb_by_imdb % imdb result = client.request(url, timeout='10') try: tvdb = client.parseDOM(result, 'seriesid')[0] except: tvdb = '0' try: name = client.parseDOM(result, 'SeriesName')[0] except: name = '0' dupe = re.compile('[***]Duplicate (\d*)[***]').findall(name) if len(dupe) > 0: tvdb = str(dupe[0]) if tvdb == '': tvdb = '0' if tvdb == '0': url = self.tvdb_by_query % (urllib.quote_plus(tvshowtitle)) years = [str(year), str(int(year) + 1), str(int(year) - 1)] tvdb = client.request(url, timeout='10') tvdb = re.sub(r'[^\x00-\x7F]+', '', tvdb) tvdb = client.replaceHTMLCodes(tvdb) tvdb = client.parseDOM(tvdb, 'Series') tvdb = [(x, client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired')) for x in tvdb] tvdb = [(x, x[1][0], x[2][0]) for x in tvdb if len(x[1]) > 0 and len(x[2]) > 0] tvdb = [ x for x in tvdb if cleantitle.get(tvshowtitle) == cleantitle.get(x[1]) ] tvdb = [ x[0][0] for x in tvdb if any(y in x[2] for y in years) ][0] tvdb = client.parseDOM(tvdb, 'seriesid')[0] if tvdb == '': tvdb = '0' except: return try: if tvdb == '0': return url = self.tvdb_info_link % (tvdb, 'en') data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result = zip.read('%s.xml' % 'en') artwork = zip.read('banners.xml') zip.close() dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile('[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]).encode('utf-8') url = self.tvdb_info_link % (tvdb, 'en') data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result = zip.read('%s.xml' % 'en') artwork = zip.read('banners.xml') zip.close() if not lang == 'en': url = self.tvdb_info_link % (tvdb, lang) data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result2 = zip.read('%s.xml' % lang) zip.close() else: result2 = result artwork = artwork.split('<Banner>') artwork = [ i for i in artwork if '<Language>en</Language>' in i and '<BannerType>season</BannerType>' in i ] artwork = [ i for i in artwork if not 'seasonswide' in re.findall( '<BannerPath>(.+?)</BannerPath>', i)[0] ] result = result.split('<Episode>') result2 = result2.split('<Episode>') item = result[0] item2 = result2[0] episodes = [i for i in result if '<EpisodeNumber>' in i] if control.setting('tv.specials') == 'true': episodes = [i for i in episodes] else: episodes = [ i for i in episodes if not '<SeasonNumber>0</SeasonNumber>' in i ] episodes = [ i for i in episodes if not '<EpisodeNumber>0</EpisodeNumber>' in i ] seasons = [ i for i in episodes if '<EpisodeNumber>1</EpisodeNumber>' in i ] counts = self.seasonCountParse(seasons=seasons, episodes=episodes) locals = [i for i in result2 if '<EpisodeNumber>' in i] result = '' result2 = '' if limit == '': episodes = [] elif limit == '-1': seasons = [] else: episodes = [ i for i in episodes if '<SeasonNumber>%01d</SeasonNumber>' % int(limit) in i ] seasons = [] try: poster = client.parseDOM(item, 'poster')[0] except: poster = '' if not poster == '': poster = self.tvdb_image + poster else: poster = '0' poster = client.replaceHTMLCodes(poster) poster = poster.encode('utf-8') try: banner = client.parseDOM(item, 'banner')[0] except: banner = '' if not banner == '': banner = self.tvdb_image + banner else: banner = '0' banner = client.replaceHTMLCodes(banner) banner = banner.encode('utf-8') try: fanart = client.parseDOM(item, 'fanart')[0] except: fanart = '' if not fanart == '': fanart = self.tvdb_image + fanart else: fanart = '0' fanart = client.replaceHTMLCodes(fanart) fanart = fanart.encode('utf-8') if not poster == '0': pass elif not fanart == '0': poster = fanart elif not banner == '0': poster = banner if not banner == '0': pass elif not fanart == '0': banner = fanart elif not poster == '0': banner = poster try: status = client.parseDOM(item, 'Status')[0] except: status = '' if status == '': status = 'Ended' status = client.replaceHTMLCodes(status) status = status.encode('utf-8') try: studio = client.parseDOM(item, 'Network')[0] except: studio = '' if studio == '': studio = '0' studio = client.replaceHTMLCodes(studio) studio = studio.encode('utf-8') try: genre = client.parseDOM(item, 'Genre')[0] except: genre = '' genre = [x for x in genre.split('|') if not x == ''] genre = ' / '.join(genre) if genre == '': genre = '0' genre = client.replaceHTMLCodes(genre) genre = genre.encode('utf-8') try: duration = client.parseDOM(item, 'Runtime')[0] except: duration = '' if duration == '': duration = '0' duration = client.replaceHTMLCodes(duration) duration = duration.encode('utf-8') try: rating = client.parseDOM(item, 'Rating')[0] rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') except: rating = '0' try: votes = client.parseDOM(item, 'RatingCount')[0] votes = client.replaceHTMLCodes(votes) votes = votes.encode('utf-8') except: votes = '0' try: mpaa = client.parseDOM(item, 'ContentRating')[0] mpaa = client.replaceHTMLCodes(mpaa) mpaa = mpaa.encode('utf-8') except: mpaa = '0' try: cast = client.parseDOM(item, 'Actors')[0] cast = [x for x in cast.split('|') if not x == ''] cast = [(x.encode('utf-8'), '') for x in cast] except: cast = [] try: label = client.parseDOM(item2, 'SeriesName')[0] except: label = '0' label = client.replaceHTMLCodes(label) label = label.encode('utf-8') try: plot = client.parseDOM(item2, 'Overview')[0] except: plot = '' if plot == '': plot = '0' plot = client.replaceHTMLCodes(plot) plot = plot.encode('utf-8') unaired = '' except: pass for item in seasons: try: premiered = client.parseDOM(item, 'FirstAired')[0] if premiered == '' or '-00' in premiered: premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') # Show Unaired items. if status == 'Ended': pass elif premiered == '0': raise Exception() elif int(re.sub('[^0-9]', '', str(premiered))) > int( re.sub('[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': raise Exception() season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) season = season.encode('utf-8') thumb = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: thumb = client.parseDOM(thumb[0], 'BannerPath')[0] except: thumb = '' if not thumb == '': thumb = self.tvdb_image + thumb else: thumb = '0' thumb = client.replaceHTMLCodes(thumb) thumb = thumb.encode('utf-8') if thumb == '0': thumb = poster try: seasoncount = counts[season] except: seasoncount = None self.list.append({ 'season': season, 'seasoncount': seasoncount, 'tvshowtitle': tvshowtitle, 'label': label, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'cast': cast, 'plot': plot, 'imdb': imdb, 'tmdb': '0', 'tvdb': tvdb, 'tvshowid': imdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'unaired': unaired }) except: pass for item in episodes: try: premiered = client.parseDOM(item, 'FirstAired')[0] if premiered == '' or '-00' in premiered: premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') # Show future items if status == 'Ended': pass elif premiered == '0': raise Exception() elif int(re.sub('[^0-9]', '', str(premiered))) > int( re.sub('[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': raise Exception() season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) season = season.encode('utf-8') episode = client.parseDOM(item, 'EpisodeNumber')[0] episode = re.sub('[^0-9]', '', '%01d' % int(episode)) episode = episode.encode('utf-8') ### episode IDS try: episodeIDS = trakt.getEpisodeSummary(imdb, season, episode, full=False) episodeIDS = episodeIDS.get('ids', {}) except: episodeIDS = {} ##------------------ title = client.parseDOM(item, 'EpisodeName')[0] if title == '': title = '0' title = client.replaceHTMLCodes(title) title = title.encode('utf-8') try: thumb = client.parseDOM(item, 'filename')[0] except: thumb = '' if not thumb == '': thumb = self.tvdb_image + thumb else: thumb = '0' thumb = client.replaceHTMLCodes(thumb) thumb = thumb.encode('utf-8') if not thumb == '0': pass elif not fanart == '0': thumb = fanart.replace(self.tvdb_image, self.tvdb_poster) elif not poster == '0': thumb = poster try: rating = client.parseDOM(item, 'Rating')[0] except: rating = '' if rating == '': rating = '0' rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') try: director = client.parseDOM(item, 'Director')[0] except: director = '' director = [x for x in director.split('|') if not x == ''] director = ' / '.join(director) if director == '': director = '0' director = client.replaceHTMLCodes(director) director = director.encode('utf-8') try: writer = client.parseDOM(item, 'Writer')[0] except: writer = '' writer = [x for x in writer.split('|') if not x == ''] writer = ' / '.join(writer) if writer == '': writer = '0' writer = client.replaceHTMLCodes(writer) writer = writer.encode('utf-8') try: local = client.parseDOM(item, 'id')[0] local = [ x for x in locals if '<id>%s</id>' % str(local) in x ][0] except: local = item label = client.parseDOM(local, 'EpisodeName')[0] if label == '': label = '0' label = client.replaceHTMLCodes(label) label = label.encode('utf-8') try: episodeplot = client.parseDOM(local, 'Overview')[0] except: episodeplot = '' if episodeplot == '': episodeplot = '0' if episodeplot == '0': episodeplot = plot episodeplot = client.replaceHTMLCodes(episodeplot) try: episodeplot = episodeplot.encode('utf-8') except: pass try: seasoncount = counts[season] except: seasoncount = None self.list.append({ 'title': title, 'label': label, 'seasoncount': seasoncount, 'season': season, 'episode': episode, 'tvshowtitle': tvshowtitle, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'director': director, 'writer': writer, 'cast': cast, 'plot': episodeplot, 'imdb': imdb, 'tmdb': '0', 'tvdb': tvdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'unaired': unaired, 'episodeIDS': episodeIDS }) except: pass return self.list
def _seasonCount(self, tvshowtitle, year, imdb, tvdb): if imdb == '0': try: imdb = trakt.SearchTVShow(quote_plus(tvshowtitle), year, full=False)[0] imdb = imdb.get('show', '0') imdb = imdb.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub(r'[^0-9]', '', str(imdb)) if not imdb: imdb = '0' except: log_utils.error() imdb = '0' ###--Check TVDb by IMDB_ID for missing ID's if tvdb == '0' and imdb != '0': try: url = self.tvdb_by_imdb % imdb # result = client.request(url, timeout='10') result = requests.get(url, timeout=10).content result = re.sub(r'[^\x00-\x7F]+', '', result) result = client.replaceHTMLCodes(result) result = client.parseDOM(result, 'Series') result = [(client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired'), client.parseDOM(x, 'seriesid'), client.parseDOM(x, 'AliasNames')) for x in result] years = [str(year), str(int(year) + 1), str(int(year) - 1)] item = [(x[0], x[1], x[2], x[3]) for x in result if cleantitle.get(tvshowtitle) == cleantitle.get( str(x[0][0])) and any(y in str(x[1][0]) for y in years)] if item == []: item = [(x[0], x[1], x[2], x[3]) for x in result if cleantitle.get(tvshowtitle) == cleantitle.get( str(x[3][0]))] if item == []: item = [(x[0], x[1], x[2], x[3]) for x in result if cleantitle.get(tvshowtitle) == cleantitle.get( str(x[0][0]))] if item == []: raise Exception() tvdb = item[0][2] tvdb = tvdb[0] or '0' except: log_utils.error() ########################## ###--Check TVDb by seriesname if tvdb == '0': try: years = [str(year), str(int(year) + 1), str(int(year) - 1)] url = self.tvdb_by_query % (quote_plus(tvshowtitle)) # tvdb = client.request(url, timeout='10') tvdb = requests.get(url, timeout=10).content tvdb = re.sub(r'[^\x00-\x7F]+', '', tvdb) tvdb = client.replaceHTMLCodes(tvdb) tvdb = client.parseDOM(tvdb, 'Series') tvdb = [(x, client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired')) for x in tvdb] tvdb = [(x, x[1][0], x[2][0]) for x in tvdb if len(x[1]) > 0 and len(x[2]) > 0] tvdb = [ x for x in tvdb if cleantitle.get(tvshowtitle) == cleantitle.get(x[1]) ] tvdb = [ x[0][0] for x in tvdb if any(y in x[2] for y in years) ][0] tvdb = client.parseDOM(tvdb, 'seriesid')[0] if tvdb == '': tvdb = '0' except: log_utils.error() return None ########################## if tvdb == '0': return None try: url = self.tvdb_info_link % (tvdb, 'en') # data = urlopen(url, timeout=30).read() data = requests.get(url, timeout=30).content zip = zipfile.ZipFile(StringIO(data)) result = zip.read('%s.xml' % 'en') zip.close() dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile(r'[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]).encode('utf-8') url = self.tvdb_info_link % (tvdb, 'en') # data = urlopen(url, timeout=30).read() data = requests.get(url, timeout=30).content zip = zipfile.ZipFile(StringIO(data)) result = zip.read('%s.xml' % 'en') zip.close() result = result.split('<Episode>') return self.seasonCountParse(items=result) except: log_utils.error() return None
def tvdb_list(self, tvshowtitle, year, imdb, tmdb, tvdb, lang, limit=''): if (tvdb == '0' or tmdb == '0') and imdb != '0': try: trakt_ids = trakt.IdLookup('imdb', imdb, 'show') if trakt_ids: if tvdb == '0': tvdb = str(trakt_ids.get('tvdb', '0')) if not tvdb or tvdb == 'None': tvdb = '0' if tmdb == '0': tmdb = str(trakt_ids.get('tmdb', '0')) if not tmdb or tmdb == 'None': tmdb = '0' except: log_utils.error() if imdb == '0' or tmdb == '0' or tvdb == '0': try: trakt_ids = trakt.SearchTVShow(quote_plus(tvshowtitle), year, full=False) if not trakt_ids: raise Exception() trakt_ids = trakt_ids[0].get('show', '0') if imdb == '0': imdb = trakt_ids.get('ids', {}).get('imdb', '0') if not imdb or imdb == 'None': imdb = '0' if not imdb.startswith('tt'): imdb = '0' if tmdb == '0': tmdb = str(trakt_ids.get('ids', {}).get('tmdb', '0')) if not tmdb or tmdb == 'None': tmdb = '0' if tvdb == '0': tvdb = str(trakt_ids.get('ids', {}).get('tvdb', '0')) if not tvdb or tvdb == 'None': tvdb = '0' except: log_utils.error() ###--Check TVDb by IMDB_ID for missing ID's if tvdb == '0' and imdb != '0': try: url = self.tvdb_by_imdb % imdb # result = client.request(url, timeout='10') result = requests.get(url, timeout=10).content result = re.sub(r'[^\x00-\x7F]+', '', result) result = client.replaceHTMLCodes(result) result = client.parseDOM(result, 'Series') result = [(client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired'), client.parseDOM(x, 'seriesid'), client.parseDOM(x, 'AliasNames')) for x in result] years = [str(year), str(int(year) + 1), str(int(year) - 1)] item = [(x[0], x[1], x[2], x[3]) for x in result if cleantitle.get(tvshowtitle) == cleantitle.get( str(x[0][0])) and any(y in str(x[1][0]) for y in years)] if item == []: item = [(x[0], x[1], x[2], x[3]) for x in result if cleantitle.get(tvshowtitle) == cleantitle.get( str(x[3][0]))] if item == []: item = [(x[0], x[1], x[2], x[3]) for x in result if cleantitle.get(tvshowtitle) == cleantitle.get( str(x[0][0]))] if item == []: raise Exception() tvdb = item[0][2] tvdb = tvdb[0] or '0' except: log_utils.error() ########################## ###--Check TVDb by seriesname if tvdb == '0': try: years = [str(year), str(int(year) + 1), str(int(year) - 1)] url = self.tvdb_by_query % (quote_plus(tvshowtitle)) # tvdb = client.request(url, timeout='10') tvdb = requests.get(url, timeout=10).content tvdb = re.sub(r'[^\x00-\x7F]+', '', tvdb) tvdb = client.replaceHTMLCodes(tvdb) tvdb = client.parseDOM(tvdb, 'Series') tvdb = [(x, client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired')) for x in tvdb] tvdb = [(x, x[1][0], x[2][0]) for x in tvdb if len(x[1]) > 0 and len(x[2]) > 0] tvdb = [ x for x in tvdb if cleantitle.get(tvshowtitle) == cleantitle.get(x[1]) ] tvdb = [ x[0][0] for x in tvdb if any(y in x[2] for y in years) ][0] tvdb = client.parseDOM(tvdb, 'seriesid')[0] if tvdb == '': tvdb = '0' except: log_utils.error() ############################# if tvdb == '0': return None try: url = self.tvdb_info_link % (tvdb, 'en') # data = urlopen(url, timeout=30).read() data = requests.get( url, timeout=30 ).content # sometimes one api key pulls empty xml while another does not zip = zipfile.ZipFile(StringIO(data)) result = zip.read('en.xml') artwork = zip.read('banners.xml') actors = zip.read('actors.xml') zip.close() dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile(r'[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]).encode('utf-8') url = self.tvdb_info_link % (tvdb, 'en') # data = urlopen(url, timeout=30).read() data = requests.get(url, timeout=30).content zip = zipfile.ZipFile(StringIO(data)) result = zip.read('en.xml') artwork = zip.read('banners.xml') actors = zip.read('actors.xml') zip.close() if lang != 'en': url = self.tvdb_info_link % (tvdb, lang) # data = urlopen(url, timeout=30).read() data = requests.get(url, timeout=30).content zip = zipfile.ZipFile(StringIO(data)) result2 = zip.read('%s.xml' % lang) zip.close() else: result2 = result artwork = artwork.split('<Banner>') artwork = [ i for i in artwork if '<Language>en</Language>' in i and '<BannerType>season</BannerType>' in i ] artwork = [ i for i in artwork if not 'seasonswide' in re.findall( r'<BannerPath>(.+?)</BannerPath>', i)[0] ] result = result.split('<Episode>') result2 = result2.split('<Episode>') item = result[0] item2 = result2[0] episodes = [i for i in result if '<EpisodeNumber>' in i] if control.setting('tv.specials') == 'true': episodes = [i for i in episodes] else: episodes = [ i for i in episodes if not '<SeasonNumber>0</SeasonNumber>' in i ] episodes = [ i for i in episodes if not '<EpisodeNumber>0</EpisodeNumber>' in i ] # season still airing check for pack scraping premiered_eps = [ i for i in episodes if not '<FirstAired></FirstAired>' in i ] unaired_eps = [ i for i in premiered_eps if int( re.sub(r'[^0-9]', '', str(client.parseDOM( i, 'FirstAired')))) > int( re.sub(r'[^0-9]', '', str(self.today_date))) ] if unaired_eps: still_airing = client.parseDOM(unaired_eps, 'SeasonNumber')[0] else: still_airing = None seasons = [ i for i in episodes if '<EpisodeNumber>1</EpisodeNumber>' in i ] counts = self.seasonCountParse(seasons=seasons, episodes=episodes) locals = [i for i in result2 if '<EpisodeNumber>' in i] result = '' result2 = '' if limit == '': episodes = [] elif limit == '-1': seasons = [] else: episodes = [ i for i in episodes if '<SeasonNumber>%01d</SeasonNumber>' % int(limit) in i ] seasons = [] try: poster = client.parseDOM(item, 'poster')[0] except: poster = '' if poster != '': poster = '%s%s' % (self.tvdb_image, poster) else: poster = '0' poster = client.replaceHTMLCodes(poster) poster = poster.encode('utf-8') try: banner = client.parseDOM(item, 'banner')[0] except: banner = '' if banner != '': banner = '%s%s' % (self.tvdb_image, banner) else: banner = '0' banner = client.replaceHTMLCodes(banner) banner = banner.encode('utf-8') try: fanart = client.parseDOM(item, 'fanart')[0] except: fanart = '' if fanart != '': fanart = '%s%s' % (self.tvdb_image, fanart) else: fanart = '0' fanart = client.replaceHTMLCodes(fanart) fanart = fanart.encode('utf-8') if poster != '0': pass elif fanart != '0': poster = fanart elif banner != '0': poster = banner if banner != '0': pass elif fanart != '0': banner = fanart elif poster != '0': banner = poster try: status = client.parseDOM(item, 'Status')[0] except: status = '' if status == '': status = 'Ended' status = client.replaceHTMLCodes(status) status = status.encode('utf-8') try: studio = client.parseDOM(item, 'Network')[0] except: studio = '' if studio == '': studio = '0' studio = client.replaceHTMLCodes(studio) studio = studio.encode('utf-8') try: genre = client.parseDOM(item, 'Genre')[0] except: genre = '' genre = [x for x in genre.split('|') if x != ''] genre = ' / '.join(genre) if genre == '': genre = '0' genre = client.replaceHTMLCodes(genre) genre = genre.encode('utf-8') try: duration = client.parseDOM(item, 'Runtime')[0] except: duration = '' if duration == '': duration = '0' duration = client.replaceHTMLCodes(duration) duration = duration.encode('utf-8') try: rating = client.parseDOM(item, 'Rating')[0] rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') except: rating = '0' try: votes = client.parseDOM(item, 'RatingCount')[0] votes = client.replaceHTMLCodes(votes) votes = votes.encode('utf-8') except: votes = '0' try: mpaa = client.parseDOM(item, 'ContentRating')[0] mpaa = client.replaceHTMLCodes(mpaa) mpaa = mpaa.encode('utf-8') except: mpaa = '0' import xml.etree.ElementTree as ET tree = ET.ElementTree(ET.fromstring(actors)) root = tree.getroot() castandart = [] for actor in root.iter('Actor'): person = [name.text for name in actor] image = person[1] name = person[2] try: name = client.replaceHTMLCodes(person[2]) except: pass role = person[3] try: role = client.replaceHTMLCodes(person[3]) except: pass try: try: castandart.append({ 'name': name.encode('utf-8'), 'role': role.encode('utf-8'), 'thumbnail': ((self.tvdb_image + image) if image is not None else '0') }) except: castandart.append({ 'name': name, 'role': role, 'thumbnail': ((self.tvdb_image + image) if image is not None else '0') }) except: castandart = [] if len(castandart) == 150: break try: label = client.parseDOM(item2, 'SeriesName')[0] except: label = '0' label = client.replaceHTMLCodes(label) label = label.encode('utf-8') try: # plot = client.parseDOM(item2, 'Overview')[0] plot = client.parseDOM(item2, 'Overview')[0].encode( 'ascii', errors='ignore').decode('ascii', errors='ignore') except: plot = '' if plot == '': plot = '0' plot = client.replaceHTMLCodes(plot) plot = plot.encode('utf-8') except: log_utils.error() for item in seasons: try: premiered = client.parseDOM(item, 'FirstAired')[0] if premiered == '' or '-00' in premiered: premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') # Show Unaired items. unaired = '' if status.lower() == 'ended': pass elif premiered == '0': unaired = 'true' if self.showunaired != 'true': continue pass elif int(re.sub(r'[^0-9]', '', str(premiered))) > int( re.sub(r'[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': continue season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) season = season.encode('utf-8') thumb = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: thumb = client.parseDOM(thumb[0], 'BannerPath')[0] except: thumb = '' if thumb != '': thumb = '%s%s' % (self.tvdb_image, thumb) else: thumb = '0' thumb = client.replaceHTMLCodes(thumb) thumb = thumb.encode('utf-8') if thumb == '0': thumb = poster try: seasoncount = counts[season] except: seasoncount = None try: total_seasons = len([i for i in counts if i != '0']) except: total_seasons = None self.list.append({ 'season': season, 'tvshowtitle': tvshowtitle, 'label': label, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'castandart': castandart, 'plot': plot, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'tvshowid': imdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'unaired': unaired, 'seasoncount': seasoncount, 'total_seasons': total_seasons }) self.list = sorted(self.list, key=lambda k: int(k['season']) ) # fix for TVDb new sort by ID except: log_utils.error() for item in episodes: try: title = client.parseDOM(item, 'EpisodeName')[0] title = client.replaceHTMLCodes(title) try: title = title.encode('utf-8') except: pass premiered = client.parseDOM(item, 'FirstAired')[0] if premiered == '' or '-00' in premiered: premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') # Show Unaired items. unaired = '' if status.lower() == 'ended': pass elif premiered == '0': unaired = 'true' if self.showunaired != 'true': continue pass elif int(re.sub(r'[^0-9]', '', str(premiered))) > int( re.sub(r'[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': continue season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) season = season.encode('utf-8') episode = client.parseDOM(item, 'EpisodeNumber')[0] episode = re.sub(r'[^0-9]', '', '%01d' % int(episode)) episode = episode.encode('utf-8') if still_airing: if int(still_airing) == int(season): is_airing = True else: is_airing = False else: is_airing = False # ### episode IDS episodeIDS = {} if control.setting('enable.upnext') == 'true': episodeIDS = trakt.getEpisodeSummary( imdb, season, episode, full=False) or {} if episodeIDS != {}: episodeIDS = episodeIDS.get('ids', {}) ##------------------ try: thumb = client.parseDOM(item, 'filename')[0] except: thumb = '' if thumb != '': thumb = '%s%s' % (self.tvdb_image, thumb) else: thumb = '0' thumb = client.replaceHTMLCodes(thumb) thumb = thumb.encode('utf-8') if thumb != '0': pass elif fanart != '0': thumb = fanart.replace(self.tvdb_image, self.tvdb_poster) elif poster != '0': thumb = poster season_poster = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: season_poster = client.parseDOM(season_poster[0], 'BannerPath')[0] except: season_poster = '' if season_poster != '': season_poster = '%s%s' % (self.tvdb_image, season_poster) else: season_poster = '0' season_poster = client.replaceHTMLCodes(season_poster) season_poster = season_poster.encode('utf-8') if season_poster == '0': season_poster = poster try: rating = client.parseDOM(item, 'Rating')[0] except: rating = '' if rating == '': rating = '0' rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') try: director = client.parseDOM(item, 'Director')[0] except: director = '' director = [x for x in director.split('|') if x != ''] director = ' / '.join(director) if director == '': director = '0' director = client.replaceHTMLCodes(director) director = director.encode('utf-8') try: writer = client.parseDOM(item, 'Writer')[0] except: writer = '' writer = [x for x in writer.split('|') if x != ''] writer = ' / '.join(writer) if writer == '': writer = '0' writer = client.replaceHTMLCodes(writer) writer = writer.encode('utf-8') try: local = client.parseDOM(item, 'id')[0] local = [ x for x in locals if '<id>%s</id>' % str(local) in x ][0] except: local = item label = client.parseDOM(local, 'EpisodeName')[0] if label == '': label = '0' label = client.replaceHTMLCodes(label) label = label.encode('utf-8') try: episodeplot = client.parseDOM(local, 'Overview')[0] except: episodeplot = '' if episodeplot == '': episodeplot = '0' if episodeplot == '0': episodeplot = plot episodeplot = client.replaceHTMLCodes(episodeplot) try: episodeplot = episodeplot.encode('utf-8') except: pass try: seasoncount = counts[season] except: seasoncount = None try: total_seasons = len([i for i in counts if i != '0']) except: total_seasons = None self.list.append({ 'title': title, 'label': label, 'season': season, 'episode': episode, 'tvshowtitle': tvshowtitle, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'director': director, 'writer': writer, 'castandart': castandart, 'plot': episodeplot, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'season_poster': season_poster, 'unaired': unaired, 'seasoncount': seasoncount, 'counts': counts, 'total_seasons': total_seasons, 'is_airing': is_airing, 'episodeIDS': episodeIDS }) self.list = sorted(self.list, key=lambda k: (int(k['season']), int(k['episode']) )) # fix for TVDb new sort by ID # meta = {} # meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.tvdb_key, 'item': item} # self.list.append(item) # metacache.insert(self.meta) except: log_utils.error() return self.list
def tvdb_list(self, tvshowtitle, year, imdb, tmdb, tvdb, lang, limit=''): if (tvdb == '0' or tmdb == '0') and imdb != '0': try: trakt_ids = trakt.IdLookup('imdb', imdb, 'show') if trakt_ids: if tvdb == '0': tvdb = str(trakt_ids.get('tvdb', '0')) if not tvdb or tvdb == 'None': tvdb = '0' if tmdb == '0': tmdb = str(trakt_ids.get('tmdb', '0')) if not tmdb or tmdb == 'None': tmdb = '0' except: log_utils.error() if imdb == '0' or tmdb == '0' or tvdb == '0': try: trakt_ids = trakt.SearchTVShow(quote_plus(tvshowtitle), year, full=False) if not trakt_ids: raise Exception() trakt_ids = trakt_ids[0].get('show', '0') if imdb == '0': imdb = trakt_ids.get('ids', {}).get('imdb', '0') if not imdb or imdb == 'None': imdb = '0' if not imdb.startswith('tt'): imdb = '0' if tmdb == '0': tmdb = str(trakt_ids.get('ids', {}).get('tmdb', '0')) if not tmdb or tmdb == 'None': tmdb = '0' if tvdb == '0': tvdb = str(trakt_ids.get('ids', {}).get('tvdb', '0')) if not tvdb or tvdb == 'None': tvdb = '0' except: log_utils.error() if tvdb == '0' and imdb != '0': # Check TVDb by IMDB_ID for missing tvdb_id try: tvdb = cache.get(tvdb_v1.getSeries_ByIMDB, 96, tvshowtitle, year, imdb) except: tvdb = '0' if tvdb == '0': # Check TVDb by seriesname for missing tvdb_id try: ids = cache.get(tvdb_v1.getSeries_ByName, 96, tvshowtitle, year) if ids: tvdb = ids.get(tvdb, '0') or '0' except: tvdb = '0' log_utils.error() if tvdb == '0': return None try: result, artwork, actors = cache.get(tvdb_v1.getZip, 96, tvdb, True, True) dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile(r'[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]) result, artwork, actors = cache.get(tvdb_v1.getZip, 96, tvdb, True, True) artwork = artwork.split('<Banner>') artwork = [ i for i in artwork if '<Language>en</Language>' in i and '<BannerType>season</BannerType>' in i ] artwork = [ i for i in artwork if not 'seasonswide' in re.findall( r'<BannerPath>(.+?)</BannerPath>', i)[0] ] result = result.split('<Episode>') item = result[0] episodes = [i for i in result if '<EpisodeNumber>' in i] if control.setting('tv.specials') == 'true': episodes = [i for i in episodes] else: episodes = [ i for i in episodes if not '<SeasonNumber>0</SeasonNumber>' in i ] episodes = [ i for i in episodes if not '<EpisodeNumber>0</EpisodeNumber>' in i ] # season still airing check for pack scraping premiered_eps = [ i for i in episodes if not '<FirstAired></FirstAired>' in i ] unaired_eps = [ i for i in premiered_eps if int( re.sub(r'[^0-9]', '', str(client.parseDOM( i, 'FirstAired')))) > int( re.sub(r'[^0-9]', '', str(self.today_date))) ] if unaired_eps: still_airing = client.parseDOM(unaired_eps, 'SeasonNumber')[0] else: still_airing = None seasons = [ i for i in episodes if '<EpisodeNumber>1</EpisodeNumber>' in i ] counts = self.seasonCountParse(seasons=seasons, episodes=episodes) # locals = [i for i in result if '<EpisodeNumber>' in i] if limit == '': episodes = [] elif limit == '-1': seasons = [] else: episodes = [ i for i in episodes if '<SeasonNumber>%01d</SeasonNumber>' % int(limit) in i ] seasons = [] poster = client.replaceHTMLCodes( client.parseDOM(item, 'poster')[0]) if poster != '': poster = '%s%s' % (self.tvdb_image, poster) fanart = client.replaceHTMLCodes( client.parseDOM(item, 'fanart')[0]) if fanart != '': fanart = '%s%s' % (self.tvdb_image, fanart) banner = client.replaceHTMLCodes( client.parseDOM(item, 'banner')[0]) if banner != '': banner = '%s%s' % (self.tvdb_image, banner) if poster != '': pass elif fanart != '': poster = fanart elif banner != '': poster = banner if banner != '': pass elif fanart != '': banner = fanart elif poster != '': banner = poster status = client.replaceHTMLCodes( client.parseDOM(item, 'Status')[0]) or 'Ended' studio = client.replaceHTMLCodes( client.parseDOM(item, 'Network')[0]) or '' genre = client.replaceHTMLCodes(client.parseDOM(item, 'Genre')[0]) genre = ' / '.join([x for x in genre.split('|') if x != '']) duration = client.replaceHTMLCodes( client.parseDOM(item, 'Runtime')[0]) rating = client.replaceHTMLCodes( client.parseDOM(item, 'Rating')[0]) votes = client.replaceHTMLCodes( client.parseDOM(item, 'RatingCount')[0]) mpaa = client.replaceHTMLCodes( client.parseDOM(item, 'ContentRating')[0]) castandart = tvdb_v1.parseActors(actors) label = client.replaceHTMLCodes( client.parseDOM(item, 'SeriesName')[0]) plot = client.replaceHTMLCodes( client.parseDOM(item, 'Overview')[0]) plot = py_tools.ensure_str(plot) except: log_utils.error() for item in seasons: try: premiered = client.replaceHTMLCodes( client.parseDOM(item, 'FirstAired')[0]) or '0' # Show Unaired items. unaired = '' if status.lower() == 'ended': pass elif premiered == '0': unaired = 'true' if self.showunaired != 'true': continue pass elif int(re.sub(r'[^0-9]', '', str(premiered))) > int( re.sub(r'[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': continue season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) thumb = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: thumb = client.replaceHTMLCodes( client.parseDOM(thumb[0], 'BannerPath')[0]) except: thumb = '' if thumb != '': thumb = '%s%s' % (self.tvdb_image, thumb) else: thumb = poster try: seasoncount = counts[season] except: seasoncount = None try: total_seasons = len([i for i in counts if i != '0']) except: total_seasons = None self.list.append({ 'season': season, 'tvshowtitle': tvshowtitle, 'label': label, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'castandart': castandart, 'plot': plot, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'tvshowid': imdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'unaired': unaired, 'seasoncount': seasoncount, 'total_seasons': total_seasons }) self.list = sorted(self.list, key=lambda k: int(k['season']) ) # fix for TVDb new sort by ID except: log_utils.error() for item in episodes: try: title = client.replaceHTMLCodes( client.parseDOM(item, 'EpisodeName')[0]) title = py_tools.ensure_str(title) premiered = client.replaceHTMLCodes( client.parseDOM(item, 'FirstAired')[0]) or '0' # Show Unaired items. unaired = '' if status.lower() == 'ended': pass elif premiered == '0': unaired = 'true' if self.showunaired != 'true': continue pass elif int(re.sub(r'[^0-9]', '', str(premiered))) > int( re.sub(r'[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': continue season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) episode = client.parseDOM(item, 'EpisodeNumber')[0] episode = re.sub(r'[^0-9]', '', '%01d' % int(episode)) if still_airing: if int(still_airing) == int(season): is_airing = True else: is_airing = False else: is_airing = False # ### episode IDS episodeIDS = {} if control.setting('enable.upnext') == 'true': episodeIDS = trakt.getEpisodeSummary( imdb, season, episode, full=False) or {} if episodeIDS != {}: episodeIDS = episodeIDS.get('ids', {}) ##------------------ thumb = client.replaceHTMLCodes( client.parseDOM(item, 'filename')[0]) if thumb != '': thumb = '%s%s' % (self.tvdb_image, thumb) season_poster = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: season_poster = client.replaceHTMLCodes( client.parseDOM(season_poster[0], 'BannerPath')[0]) except: season_poster = '' if season_poster != '': season_poster = '%s%s' % (self.tvdb_image, season_poster) else: season_poster = poster if thumb != '': pass elif fanart != '': thumb = fanart.replace(self.tvdb_image, self.tvdb_poster) elif season_poster != '': thumb = season_poster rating = client.replaceHTMLCodes( client.parseDOM(item, 'Rating')[0]) director = client.replaceHTMLCodes( client.parseDOM(item, 'Director')[0]) director = ' / '.join([ x for x in director.split('|') if x != '' ]) # check if this needs ensure_str() writer = client.replaceHTMLCodes( client.parseDOM(item, 'Writer')[0]) writer = ' / '.join([x for x in writer.split('|') if x != '' ]) # check if this needs ensure_str() label = client.replaceHTMLCodes( client.parseDOM(item, 'EpisodeName')[0]) episodeplot = client.replaceHTMLCodes( client.parseDOM(item, 'Overview')[0]) or plot episodeplot = py_tools.ensure_str(episodeplot) try: seasoncount = counts[season] except: seasoncount = None try: total_seasons = len([i for i in counts if i != '0']) except: total_seasons = None self.list.append({ 'title': title, 'label': label, 'season': season, 'episode': episode, 'tvshowtitle': tvshowtitle, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'director': director, 'writer': writer, 'castandart': castandart, 'plot': episodeplot, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'season_poster': season_poster, 'unaired': unaired, 'seasoncount': seasoncount, 'counts': counts, 'total_seasons': total_seasons, 'is_airing': is_airing, 'episodeIDS': episodeIDS }) self.list = sorted(self.list, key=lambda k: (int(k['season']), int(k['episode']) )) # fix for TVDb new sort by ID # meta = {} # meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.tvdb_key, 'item': item} # self.list.append(item) # metacache.insert(self.meta) except: log_utils.error() return self.list
def tvdb_list(self, tvshowtitle, year, imdb, tvdb, lang, limit=''): tmdb = '0' try: # if imdb == '0' or tmdb == '0' or tvdb == '0': if imdb == '0' or tvdb == '0': try: # trakt_ids = trakt.SearchTVShow(urllib.quote_plus(tvshowtitle), year, full=False)[0] trakt_ids = trakt.SearchTVShow(tvshowtitle, year, full=False)[0] trakt_ids = trakt_ids.get('show', '0') if imdb == '0': imdb = trakt_ids.get('ids', {}).get('imdb', '0') if imdb == '' or imdb is None or imdb == 'None': imdb = '0' if tmdb == '0': tmdb = str(trakt_ids.get('ids', {}).get('tmdb', 0)) if tmdb == '' or tmdb is None or tmdb == 'None': tmdb = '0' if tvdb == '0': tvdb = str(trakt_ids.get('ids', {}).get('tvdb', 0)) if tvdb == '' or tvdb is None or tvdb == 'None': tvdb = '0' except: pass if tvdb == '0' and imdb != '0': url = self.tvdb_by_imdb % imdb result = client.request(url, timeout='10') try: tvdb = client.parseDOM(result, 'seriesid')[0] except: tvdb = '0' try: name = client.parseDOM(result, 'SeriesName')[0] except: name = '0' dupe = re.compile('[***]Duplicate (\d*)[***]').findall(name) if len(dupe) > 0: tvdb = str(dupe[0]) if tvdb == '': tvdb = '0' if tvdb == '0': url = self.tvdb_by_query % (urllib.quote_plus(tvshowtitle)) years = [str(year), str(int(year) + 1), str(int(year) - 1)] tvdb = client.request(url, timeout='10') tvdb = re.sub(r'[^\x00-\x7F]+', '', tvdb) tvdb = client.replaceHTMLCodes(tvdb) tvdb = client.parseDOM(tvdb, 'Series') tvdb = [(x, client.parseDOM(x, 'SeriesName'), client.parseDOM(x, 'FirstAired')) for x in tvdb] tvdb = [(x, x[1][0], x[2][0]) for x in tvdb if len(x[1]) > 0 and len(x[2]) > 0] tvdb = [ x for x in tvdb if cleantitle.get(tvshowtitle) == cleantitle.get(x[1]) ] tvdb = [ x[0][0] for x in tvdb if any(y in x[2] for y in years) ][0] tvdb = client.parseDOM(tvdb, 'seriesid')[0] if tvdb == '': tvdb = '0' except: return try: if tvdb == '0': return url = self.tvdb_info_link % (tvdb, 'en') data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result = zip.read('en.xml') artwork = zip.read('banners.xml') actors = zip.read('actors.xml') zip.close() dupe = client.parseDOM(result, 'SeriesName')[0] dupe = re.compile('[***]Duplicate (\d*)[***]').findall(dupe) if len(dupe) > 0: tvdb = str(dupe[0]).encode('utf-8') url = self.tvdb_info_link % (tvdb, 'en') data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result = zip.read('en.xml') artwork = zip.read('banners.xml') actors = zip.read('actors.xml') zip.close() if lang != 'en': url = self.tvdb_info_link % (tvdb, lang) data = urllib2.urlopen(url, timeout=30).read() zip = zipfile.ZipFile(StringIO.StringIO(data)) result2 = zip.read('%s.xml' % lang) zip.close() else: result2 = result artwork = artwork.split('<Banner>') artwork = [ i for i in artwork if '<Language>en</Language>' in i and '<BannerType>season</BannerType>' in i ] artwork = [ i for i in artwork if not 'seasonswide' in re.findall( '<BannerPath>(.+?)</BannerPath>', i)[0] ] result = result.split('<Episode>') result2 = result2.split('<Episode>') item = result[0] item2 = result2[0] episodes = [i for i in result if '<EpisodeNumber>' in i] if control.setting('tv.specials') == 'true': episodes = [i for i in episodes] else: episodes = [ i for i in episodes if not '<SeasonNumber>0</SeasonNumber>' in i ] episodes = [ i for i in episodes if not '<EpisodeNumber>0</EpisodeNumber>' in i ] seasons = [ i for i in episodes if '<EpisodeNumber>1</EpisodeNumber>' in i ] counts = self.seasonCountParse(seasons=seasons, episodes=episodes) locals = [i for i in result2 if '<EpisodeNumber>' in i] result = '' result2 = '' if limit == '': episodes = [] elif limit == '-1': seasons = [] else: episodes = [ i for i in episodes if '<SeasonNumber>%01d</SeasonNumber>' % int(limit) in i ] seasons = [] try: poster = client.parseDOM(item, 'poster')[0] except: poster = '' if poster != '': poster = self.tvdb_image + poster else: poster = '0' poster = client.replaceHTMLCodes(poster) poster = poster.encode('utf-8') try: banner = client.parseDOM(item, 'banner')[0] except: banner = '' if banner != '': banner = self.tvdb_image + banner else: banner = '0' banner = client.replaceHTMLCodes(banner) banner = banner.encode('utf-8') try: fanart = client.parseDOM(item, 'fanart')[0] except: fanart = '' if fanart != '': fanart = self.tvdb_image + fanart else: fanart = '0' fanart = client.replaceHTMLCodes(fanart) fanart = fanart.encode('utf-8') if poster != '0': pass elif fanart != '0': poster = fanart elif banner != '0': poster = banner if banner != '0': pass elif fanart != '0': banner = fanart elif poster != '0': banner = poster try: status = client.parseDOM(item, 'Status')[0] except: status = '' if status == '': status = 'Ended' status = client.replaceHTMLCodes(status) status = status.encode('utf-8') try: studio = client.parseDOM(item, 'Network')[0] except: studio = '' if studio == '': studio = '0' studio = client.replaceHTMLCodes(studio) studio = studio.encode('utf-8') try: genre = client.parseDOM(item, 'Genre')[0] except: genre = '' genre = [x for x in genre.split('|') if x != ''] genre = ' / '.join(genre) if genre == '': genre = '0' genre = client.replaceHTMLCodes(genre) genre = genre.encode('utf-8') try: duration = client.parseDOM(item, 'Runtime')[0] except: duration = '' if duration == '': duration = '0' duration = client.replaceHTMLCodes(duration) duration = duration.encode('utf-8') try: rating = client.parseDOM(item, 'Rating')[0] rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') except: rating = '0' try: votes = client.parseDOM(item, 'RatingCount')[0] votes = client.replaceHTMLCodes(votes) votes = votes.encode('utf-8') except: votes = '0' try: mpaa = client.parseDOM(item, 'ContentRating')[0] mpaa = client.replaceHTMLCodes(mpaa) mpaa = mpaa.encode('utf-8') except: mpaa = '0' import xml.etree.ElementTree as ET tree = ET.ElementTree(ET.fromstring(actors)) root = tree.getroot() castandart = [] for actor in root.iter('Actor'): person = [name.text for name in actor] image = person[1] name = person[2] try: name = client.replaceHTMLCodes(person[2]) except: pass role = person[3] try: role = client.replaceHTMLCodes(person[3]) except: pass try: try: castandart.append({ 'name': name.encode('utf-8'), 'role': role.encode('utf-8'), 'thumbnail': ((self.tvdb_image + image) if image is not None else '0') }) except: castandart.append({ 'name': name, 'role': role, 'thumbnail': ((self.tvdb_image + image) if image is not None else '0') }) except: castandart = [] if len(castandart) == 200: break try: label = client.parseDOM(item2, 'SeriesName')[0] except: label = '0' label = client.replaceHTMLCodes(label) label = label.encode('utf-8') try: plot = client.parseDOM(item2, 'Overview')[0] except: plot = '' if plot == '': plot = '0' plot = client.replaceHTMLCodes(plot) plot = plot.encode('utf-8') unaired = '' except: import traceback traceback.print_exc() pass for item in seasons: try: premiered = client.parseDOM(item, 'FirstAired')[0] if premiered == '' or '-00' in premiered: premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') # Show Unaired items. if status.lower() == 'ended': pass elif premiered == '0': continue elif int(re.sub('[^0-9]', '', str(premiered))) > int( re.sub('[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': continue # # Show Unaired items. # if status.lower() == 'ended': # pass # elif premiered == '0': # unaired = 'true' # pass # elif premiered != '0': # if int(re.sub('[^0-9]', '', str(premiered))) > int(re.sub('[^0-9]', '', str(self.today_date))): # unaired = 'true' # if self.showunaired != 'true': # continue season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) season = season.encode('utf-8') thumb = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: thumb = client.parseDOM(thumb[0], 'BannerPath')[0] except: thumb = '' if thumb != '': thumb = self.tvdb_image + thumb else: thumb = '0' thumb = client.replaceHTMLCodes(thumb) thumb = thumb.encode('utf-8') if thumb == '0': thumb = poster try: seasoncount = counts[season] except: seasoncount = None self.list.append({ 'season': season, 'seasoncount': seasoncount, 'tvshowtitle': tvshowtitle, 'label': label, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'castandart': castandart, 'plot': plot, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'tvshowid': imdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'unaired': unaired }) except: import traceback traceback.print_exc() pass for item in episodes: try: premiered = client.parseDOM(item, 'FirstAired')[0] if premiered == '' or '-00' in premiered: premiered = '0' premiered = client.replaceHTMLCodes(premiered) premiered = premiered.encode('utf-8') # Show Unaired items. if status.lower() == 'ended': pass elif premiered == '0': continue elif int(re.sub('[^0-9]', '', str(premiered))) > int( re.sub('[^0-9]', '', str(self.today_date))): unaired = 'true' if self.showunaired != 'true': continue # # Show Unaired items. # if status.lower() == 'ended': # pass # elif premiered == '0': # unaired = 'true' # pass # elif premiered != '0': # if int(re.sub('[^0-9]', '', str(premiered))) > int(re.sub('[^0-9]', '', str(self.today_date))): # unaired = 'true' # if self.showunaired != 'true': # continue season = client.parseDOM(item, 'SeasonNumber')[0] season = '%01d' % int(season) season = season.encode('utf-8') episode = client.parseDOM(item, 'EpisodeNumber')[0] episode = re.sub('[^0-9]', '', '%01d' % int(episode)) episode = episode.encode('utf-8') # ### episode IDS episodeIDS = {} if control.setting('enable.upnext') == 'true': episodeIDS = trakt.getEpisodeSummary( imdb, season, episode, full=False) or {} if episodeIDS != {}: episodeIDS = episodeIDS.get('ids', {}) ##------------------ title = client.parseDOM(item, 'EpisodeName')[0] title = client.replaceHTMLCodes(title) title = title.encode('utf-8') try: thumb = client.parseDOM(item, 'filename')[0] except: thumb = '' if thumb != '': thumb = self.tvdb_image + thumb else: thumb = '0' thumb = client.replaceHTMLCodes(thumb) thumb = thumb.encode('utf-8') if thumb != '0': pass elif fanart != '0': thumb = fanart.replace(self.tvdb_image, self.tvdb_poster) elif poster != '0': thumb = poster season_poster = [ i for i in artwork if client.parseDOM(i, 'Season')[0] == season ] try: season_poster = client.parseDOM(season_poster[0], 'BannerPath')[0] except: season_poster = '' if season_poster != '': season_poster = self.tvdb_image + season_poster else: season_poster = '0' season_poster = client.replaceHTMLCodes(season_poster) season_poster = season_poster.encode('utf-8') if season_poster == '0': season_poster = poster # log_utils.log('season_poster = %s for tvshowtitle = %s' % (season_poster, tvshowtitle), __name__, log_utils.LOGDEBUG) try: rating = client.parseDOM(item, 'Rating')[0] except: rating = '' if rating == '': rating = '0' rating = client.replaceHTMLCodes(rating) rating = rating.encode('utf-8') try: director = client.parseDOM(item, 'Director')[0] except: director = '' director = [x for x in director.split('|') if x != ''] director = ' / '.join(director) if director == '': director = '0' director = client.replaceHTMLCodes(director) director = director.encode('utf-8') try: writer = client.parseDOM(item, 'Writer')[0] except: writer = '' writer = [x for x in writer.split('|') if x != ''] writer = ' / '.join(writer) if writer == '': writer = '0' writer = client.replaceHTMLCodes(writer) writer = writer.encode('utf-8') try: local = client.parseDOM(item, 'id')[0] local = [ x for x in locals if '<id>%s</id>' % str(local) in x ][0] except: local = item label = client.parseDOM(local, 'EpisodeName')[0] if label == '': label = '0' label = client.replaceHTMLCodes(label) label = label.encode('utf-8') try: episodeplot = client.parseDOM(local, 'Overview')[0] except: episodeplot = '' if episodeplot == '': episodeplot = '0' if episodeplot == '0': episodeplot = plot episodeplot = client.replaceHTMLCodes(episodeplot) try: episodeplot = episodeplot.encode('utf-8') except: pass try: seasoncount = counts[season] except: seasoncount = None self.list.append({ 'title': title, 'label': label, 'seasoncount': seasoncount, 'season': season, 'episode': episode, 'tvshowtitle': tvshowtitle, 'year': year, 'premiered': premiered, 'status': status, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'votes': votes, 'mpaa': mpaa, 'director': director, 'writer': writer, 'castandart': castandart, 'plot': episodeplot, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'poster': poster, 'banner': banner, 'fanart': fanart, 'thumb': thumb, 'season_poster': season_poster, 'unaired': unaired, 'episodeIDS': episodeIDS }) # meta = {} # meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.tvdb_key, 'item': item} # self.list.append(item) # metacache.insert(self.meta) except: import traceback traceback.print_exc() pass return self.list
def items_list(tvmaze_id): # if i['metacache']: return # not possible with only a tvmaze_id try: values = {} values['next'] = next values['tvmaze'] = tvmaze_id url = self.tvmaze_info_link % tvmaze_id item = get_request(url) values['content'] = item.get('type', '').lower() values['mediatype'] = 'tvshow' values['title'] = item.get('name') values['originaltitle'] = values['title'] values['tvshowtitle'] = values['title'] values['premiered'] = str(item.get( 'premiered', '')) if item.get('premiered') else '' try: values['year'] = values['premiered'][:4] except: values['year'] = '' ids = item.get('externals') imdb = str(ids.get('imdb', '')) if ids.get('imdb') else '' tvdb = str(ids.get('thetvdb', '')) if ids.get('thetvdb') else '' tmdb = '' # TVMaze does not have tmdb_id in api studio = item.get('network', {}) or item.get('webChannel', {}) values['studio'] = studio.get('name', '') values['genre'] = [] for i in item['genres']: values['genre'].append(i.title()) if values['genre'] == []: values['genre'] = 'NA' values['duration'] = int(item.get( 'runtime', '')) * 60 if item.get('runtime') else '' values['rating'] = str(item.get('rating').get( 'average', '')) if item.get('rating').get('average') else '' values['plot'] = client.cleanHTML(item['summary']) values['status'] = item.get('status', '') values['castandart'] = [] for person in item['_embedded']['cast']: try: values['castandart'].append({ 'name': person['person']['name'], 'role': person['character']['name'], 'thumbnail': (person['person']['image']['medium'] if person['person']['image']['medium'] else '') }) except: pass if len(values['castandart']) == 150: break image = item.get('image', {}) or '' values['poster'] = image.get('original', '') if image else '' values['fanart'] = '' values['banner'] = '' values['mpaa'] = '' values['votes'] = '' try: values['airday'] = item['schedule']['days'][0] except: values['airday'] = '' values['airtime'] = item['schedule']['time'] or '' try: values['airzone'] = item['network']['country']['timezone'] except: values['airzone'] = '' values['metacache'] = False #### -- Missing id's lookup -- #### if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id', '')) if result.get('id') else '' except: tmdb = '' if not imdb or not tmdb or not tvdb: try: trakt_ids = trakt.SearchTVShow(quote_plus( values['tvshowtitle']), values['year'], full=False) if not trakt_ids: raise Exception ids = trakt_ids[0].get('show', {}).get('ids', {}) if not imdb: imdb = str(ids.get('imdb', '')) if ids.get('imdb') else '' if not tmdb: tmdb = str(ids.get('tmdb', '')) if ids.get('tmdb') else '' if not tvdb: tvdb = str(ids.get('tvdb', '')) if ids.get('tvdb') else '' except: log_utils.error() ################################# if not tmdb: return log_utils.log( 'tvshowtitle: (%s) missing tmdb_id: ids={imdb: %s, tmdb: %s, tvdb: %s}' % (values['tvshowtitle'], imdb, tmdb, tvdb), __name__, log_utils.LOGDEBUG ) # log TMDb shows that they do not have # self.list = metacache.fetch(self.list, self.lang, self.user) # if self.list['metacache'] is True: raise Exception() showSeasons = cache.get( tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) if not showSeasons: return showSeasons = dict( (k, v) for k, v in iter(showSeasons.items()) if v is not None and v != '' ) # removes empty keys so .update() doesn't over-write good meta values.update(showSeasons) if not values.get('imdb'): values['imdb'] = imdb if not values.get('tmdb'): values['tmdb'] = tmdb if not values.get('tvdb'): values['tvdb'] = tvdb for k in ('seasons', ): values.pop( k, None ) # pop() keys from showSeasons that are not needed anymore if self.enable_fanarttv: extended_art = fanarttv_cache.get(fanarttv.get_tvshow_art, 168, tvdb) if extended_art: values.update(extended_art) meta = { 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.user, 'item': values } # DO NOT move this after "values = dict()" below or it becomes the same object and "del meta['item']['next']" removes it from both values = dict((k, v) for k, v in iter(values.items()) if v is not None and v != '') self.list.append(values) if 'next' in meta.get('item'): del meta['item']['next'] # next can not exist in metacache self.meta.append(meta) self.meta = [ i for i in self.meta if i.get('tmdb') ] # without this ui removed missing tmdb but it still writes these cases to metacache? metacache.insert(self.meta) except: log_utils.error()
def download(name, image, url): if url == None: return from resources.lib.modules import control from resources.lib.modules import trakt try: headers = dict(urlparse.parse_qsl(url.rsplit('|', 1)[1])) except: headers = dict('') url = url.split('|')[0] content = re.compile('(.+?)\sS(\d*)E\d*$').findall(name) if control.setting('Download.auf.Deutsch') != 'false': if len(content) == 0: title = name[:-7] transyear = name.replace("(", "").replace(")", "") year = transyear[-4:] imdb = trakt.SearchMovie(title, year, full=False)[0] imdb = imdb.get('movie', '0') imdb = imdb.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) lang = 'de' germantitle = trakt.getMovieTranslation(imdb, lang) transname = germantitle.translate( None, '\/:*?"<>|').strip('.') + ' ' + '(' + str(year) + ')' else: title = name[:-7] transyear = name.replace("(", "").replace(")", "") year = transyear[-4:] imdb = trakt.SearchTVShow(title, year, full=False)[0] imdb = imdb.get('show', '0') imdb = imdb.get('ids', {}).get('imdb', '0') imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) lang = 'de' germantitle = trakt.getTVShowTranslation(imdb, lang) #transname = germantitle.translate(None, '\/:*?"<>|').strip('.') ### Warum nicht möglich? transname = name.translate(None, '\/:*?"<>|').strip('.') transtvshowtitle = content[0][0].translate(None, '\/:*?"<>|').strip('.') else: if len(content) == 0: transname = name.translate(None, '\/:*?"<>|').strip('.') else: transname = name.translate(None, '\/:*?"<>|').strip('.') transtvshowtitle = content[0][0].translate(None, '\/:*?"<>|').strip('.') levels = ['../../../..', '../../..', '../..', '..'] if len(content) == 0: dest = control.setting('movie.download.path') dest = control.transPath(dest) for level in levels: try: control.makeFile(os.path.abspath(os.path.join(dest, level))) except: pass control.makeFile(dest) dest = os.path.join(dest, transname) control.makeFile(dest) else: dest = control.setting('tv.download.path') dest = control.transPath(dest) for level in levels: try: control.makeFile(os.path.abspath(os.path.join(dest, level))) except: pass control.makeFile(dest) dest = os.path.join(dest, transtvshowtitle) control.makeFile(dest) dest = os.path.join(dest, 'Season %01d' % int(content[0][1])) control.makeFile(dest) ext = os.path.splitext(urlparse.urlparse(url).path)[1][1:] if not ext in ['mp4', 'mkv', 'flv', 'avi', 'mpg']: ext = 'mp4' dest = os.path.join(dest, transname + '.' + ext) sysheaders = urllib.quote_plus(json.dumps(headers)) sysurl = urllib.quote_plus(url) systitle = urllib.quote_plus(name) sysimage = urllib.quote_plus(image) sysdest = urllib.quote_plus(dest) script = inspect.getfile(inspect.currentframe()) cmd = 'RunScript(%s, %s, %s, %s, %s, %s)' % ( script, sysurl, sysdest, systitle, sysimage, sysheaders) xbmc.executebuiltin(cmd)