def worker(self): if not control.setting('metadata') == 'true': return self.imdb_info_link = 'https://www.omdbapi.com/?i=%s&plot=full&r=json' self.tvmaze_info_link = 'https://api.tvmaze.com/lookup/shows?thetvdb=%s' self.lang = 'en' self.meta = [] total = len(self.list) if total == 0: return for i in range(0, total): self.list[i].update({'metacache': False}) self.list = metacache.fetch(self.list, self.lang) multi = [i['imdb'] for i in self.list] multi = [x for y,x in enumerate(multi) if x not in multi[:y]] if len(multi) == 1: self.movie_info(0) ; self.tv_info(0) if self.meta: metacache.insert(self.meta) for i in range(0, total): self.list[i].update({'metacache': False}) self.list = metacache.fetch(self.list, self.lang) for r in range(0, total, 50): threads = [] for i in range(r, r+50): if i <= total: threads.append(workers.Thread(self.movie_info, i)) if i <= total: threads.append(workers.Thread(self.tv_info, i)) [i.start() for i in threads] [i.join() for i in threads] if self.meta: metacache.insert(self.meta)
def play_source(self, title, year, season, episode, imdb, tmdb, tvdb, url, meta, debridPackCall=False): try: from sys import argv # some functions like ActivateWindow() throw invalid handle less this is imported here. if not url: raise Exception self.media_type = 'movie' if season is None or episode is None else 'episode' self.title, self.year = title, str(year) if self.media_type == 'movie': self.name, self.season, self.episode = '%s (%s)' % (title, self.year), None, None elif self.media_type == 'episode': self.name, self.season, self.episode = '%s S%02dE%02d' % (title, int(season), int(episode)), '%01d' % int(season), '%01d' % int(episode) self.imdb, self.tmdb, self.tvdb = imdb or '', tmdb or '', tvdb or '' self.ids = {'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb} ## - compare meta received to database and use largest(eventually switch to a request to fetch missing db meta for item) self.imdb_user = control.setting('imdb.user').replace('ur', '') self.tmdb_key = control.setting('tmdb.api.key') if not self.tmdb_key: self.tmdb_key = '3320855e65a9758297fec4f7c9717698' self.tvdb_key = control.setting('tvdb.api.key') if self.media_type == 'episode': self.user = str(self.imdb_user) + str(self.tvdb_key) else: self.user = str(self.tmdb_key) self.lang = control.apiLanguage()['tvdb'] meta1 = dict((k, v) for k, v in iter(meta.items()) if v is not None and v != '') if meta else None meta2 = metacache.fetch([{'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb}], self.lang, self.user)[0] if meta2 != self.ids: meta2 = dict((k, v) for k, v in iter(meta2.items()) if v is not None and v != '') if meta1 is not None: try: if len(meta2) > len(meta1): meta2.update(meta1) meta = meta2 else: meta = meta1 except: log_utils.error() else: meta = meta2 if meta2 != self.ids else meta1 ################## self.poster = meta.get('poster') if meta else '' self.fanart = meta.get('fanart') if meta else '' self.meta = meta poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta(meta) self.offset = Bookmarks().get(name=self.name, imdb=imdb, tmdb=tmdb, tvdb=tvdb, season=season, episode=episode, year=self.year, runtime=meta.get('duration') if meta else 0) if self.offset == '-1': log_utils.log('User requested playback cancel', level=log_utils.LOGDEBUG) control.notification(message=32328) return control.cancelPlayback() item = control.item(path=url) item.setUniqueIDs(self.ids) if self.media_type == 'episode': item.setArt({'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart}) else: item.setArt({'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart}) if 'castandart' in meta: item.setCast(meta.get('castandart', '')) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.setProperty('IsPlayable', 'true') if debridPackCall: control.player.play(url, item) # seems this is only way browseDebrid pack files will play and have meta marked as watched else: control.resolve(int(argv[1]), True, item) homeWindow.setProperty('script.trakt.ids', jsdumps(self.ids)) self.keepAlive() homeWindow.clearProperty('script.trakt.ids') except: log_utils.error() return control.cancelPlayback()
def tmdb_list(self, url): try: result = get_request(url % API_key) items = result['results'] except: return self.list = [] ; sortList = [] try: page = int(result['page']) total = int(result['total_pages']) if page >= total: raise Exception() if 'page=' not in url: raise Exception() next = '%s&page=%s' % (url.split('&page=', 1)[0], page+1) except: next = '' for item in items: try: values = {} values['next'] = next values['tmdb'] = str(item.get('id', '')) if item.get('id') else '' sortList.append(values['tmdb']) values['imdb'] = '' values['tvdb'] = '' values['metacache'] = False self.list.append(values) except: log_utils.error() def items_list(i): if self.list[i]['metacache']: return try: values = {} tmdb = self.list[i].get('tmdb', '') # movie_meta = self.get_movie_meta(tmdb) movie_meta = cache.get(self.get_movie_meta, 96, tmdb) values.update(movie_meta) imdb = values['imdb'] if not self.disable_fanarttv: extended_art = cache.get(fanarttv.get_movie_art, 168, imdb, tmdb) if extended_art: values.update(extended_art) values = dict((k,v) for k, v in control.iteritems(values) 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': '', 'lang': self.lang, 'user': self.user, 'item': values} self.meta.append(meta) except: log_utils.error() self.list = metacache.fetch(self.list, self.lang, self.user) threads = [] for i in range(0, len(self.list)): threads.append(workers.Thread(items_list, i)) [i.start() for i in threads] [i.join() for i in threads] if self.meta: self.meta = [i for i in self.meta if i.get('tmdb')] # without this "self.list=" below removes missing tmdb but here still writes these cases to metacache? metacache.insert(self.meta) sorted_list = [] self.list = [i for i in self.list if i.get('tmdb')] for i in sortList: sorted_list += [item for item in self.list if item['tmdb'] == i] # resort to match TMDb list because threading will loose order. return sorted_list
def tmdb_collections_list(self, url): if not url: return try: result = get_request(url) if '/3/' in url: items = result['items'] else: items = result['results'] except: return self.list = [] try: page = int(result['page']) total = int(result['total_pages']) if page >= total: raise Exception() if 'page=' not in url: raise Exception() next = '%s&page=%s' % (url.split('&page=', 1)[0], page+1) except: next = '' for item in items: try: values = {} values['next'] = next media_type = item.get('media_type', '') if media_type == 'movie': continue values['tmdb'] = str(item.get('id', '')) if item.get('id') else '' values['metacache'] = False self.list.append(values) except: log_utils.error() def items_list(i): if self.list[i]['metacache']: return try: values = {} tmdb = self.list[i].get('tmdb', '') # showSeasons_meta =self.get_showSeasons_meta(tmdb) showSeasons_meta = cache.get(self.get_showSeasons_meta, 96, tmdb) values.update(showSeasons_meta) imdb = values['imdb'] tvdb = values['tvdb'] 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 control.iteritems(values) 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: log_utils.error() self.list = metacache.fetch(self.list, self.lang, self.user) threads = [] for i in range(0, len(self.list)): threads.append(workers.Thread(items_list, i)) [i.start() for i in threads] [i.join() for i in threads] if self.meta: self.meta = [i for i in self.meta if i.get('tmdb')] # without this "self.list=" below removes missing tmdb but here still writes these cases to metacache? metacache.insert(self.meta) self.list = [i for i in self.list if i.get('tmdb')] return self.list
def worker(self, level=1): try: if not self.list: return self.meta = [] total = len(self.list) for i in range(0, total): self.list[i].update({'metacache': False}) self.list = metacache.fetch(self.list, self.lang, self.user) for r in range(0, total, 40): threads = [] for i in range(r, r + 40): if i < total: threads.append(workers.Thread(self.super_info, i)) [i.start() for i in threads] [i.join() for i in threads] if self.meta: self.meta = [i for i in self.meta if i.get('tmdb')] # without this "self.list=" below removes missing tmdb but here still writes these cases to metacache? metacache.insert(self.meta) self.list = [i for i in self.list if i.get('tmdb')] except: log_utils.error()
def play_source(self, title, year, season, episode, imdb, tmdb, tvdb, url, meta, select=None): try: if not url: raise Exception self.media_type = 'movie' if season is None or episode is None else 'episode' self.title = title self.year = str(year) if self.media_type == 'movie': self.name = '%s (%s)' % (title, self.year) self.season = None self.episode = None elif self.media_type == 'episode': self.name = '%s S%02dE%02d' % (title, int(season), int(episode)) self.season = '%01d' % int(season) self.episode = '%01d' % int(episode) self.DBID = None self.imdb = imdb if imdb is not None else '' self.tmdb = tmdb if tmdb is not None else '' self.tvdb = tvdb if tvdb is not None else '' self.ids = { 'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb } ## - compare meta received to database and use largest(eventually switch to a request to fetch missing db meta for item) self.imdb_user = control.setting('imdb.user').replace('ur', '') self.tmdb_key = control.setting('tmdb.api.key') if not self.tmdb_key: self.tmdb_key = '3320855e65a9758297fec4f7c9717698' self.tvdb_key = control.setting('tvdb.api.key') if self.media_type == 'episode': self.user = str(self.imdb_user) + str(self.tvdb_key) else: self.user = str(self.tmdb_key) self.lang = control.apiLanguage()['tvdb'] meta1 = meta meta2 = metacache.fetch([{ 'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb }], self.lang, self.user)[0] if meta2 != self.ids: meta2 = dict((k, v) for k, v in control.iteritems(meta2) if v is not None and v != '') if meta1 is not None: try: if len(meta2) > len(meta1): meta2.update(meta1) meta = meta2 else: meta = meta1 except: log_utils.error() else: meta = meta2 if meta2 != self.ids else meta1 ################## self.meta = meta poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta( meta) runtime = meta.get('duration') if meta else 0 self.offset = Bookmarks().get(name=self.name, imdb=imdb, tmdb=tmdb, tvdb=tvdb, season=season, episode=episode, year=self.year, runtime=runtime) item = control.item(path=url) item.setUniqueIDs(self.ids) if control.setting('disable.player.art') == 'true': for k in ('clearart', 'clearlogo', 'discart'): meta.pop(k, None) if self.media_type == 'episode': if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setArt({ 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'poster': poster, 'fanart': fanart }) else: item.setArt({ 'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart }) if 'castandart' in meta: item.setCast(meta.get('castandart', '')) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) if 'plugin' not in control.infoLabel( 'Container.PluginName') or select != '1': control.busy() control.resolve(int(argv[1]), True, item) elif select == '1': control.busy() control.player.play(url, item) control.homeWindow.setProperty('script.trakt.ids', jsdumps(self.ids)) self.keepAlive() control.homeWindow.clearProperty('script.trakt.ids') except: log_utils.error() return control.cancelPlayback()
def tmdb_collections_list(self, url): if not url: return try: result = get_request(url) if '404:NOT FOUND' in result: return result if '/collection/' in url: items = result['parts'] elif '/3/' in url: items = result['items'] else: items = result['results'] except: return self.list = [] try: page = int(result['page']) total = int(result['total_pages']) if page >= total: raise Exception() if 'page=' not in url: raise Exception() next = '%s&page=%s' % (url.split('&page=', 1)[0], page+1) except: next = '' for item in items: try: values = {} values['next'] = next media_type = item.get('media_type', '') if media_type == 'movie': continue values['tmdb'] = str(item.get('id', '')) if item.get('id') else '' values['metacache'] = False self.list.append(values) except: from resources.lib.modules import log_utils log_utils.error() def items_list(i): if self.list[i]['metacache']: return try: values = {} tmdb = self.list[i].get('tmdb', '') showSeasons_meta = cache.get(self.get_showSeasons_meta, 96, tmdb) values.update(showSeasons_meta) imdb = values['imdb'] tvdb = values['tvdb'] if self.enable_fanarttv: extended_art = fanarttv_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() self.list = metacache.fetch(self.list, self.lang, self.user) threads = [] for i in range(0, len(self.list)): threads.append(Thread(target=items_list, args=(i,))) [i.start() for i in threads] [i.join() for i in threads] if self.meta: self.meta = [i for i in self.meta if i.get('tmdb')] metacache.insert(self.meta) self.list = [i for i in self.list if i.get('tmdb')] return self.list
def tmdb_list(self, url): try: result = get_request(url % API_key) if '404:NOT FOUND' in result: return result items = result['results'] except: return self.list = [] ; sortList = [] try: page = int(result['page']) total = int(result['total_pages']) if page >= total: raise Exception() if 'page=' not in url: raise Exception() next = '%s&page=%s' % (url.split('&page=', 1)[0], page+1) except: next = '' for item in items: try: values = {} values['next'] = next values['tmdb'] = str(item.get('id', '')) if item.get('id') else '' sortList.append(values['tmdb']) values['imdb'] = '' values['tvdb'] = '' values['metacache'] = False self.list.append(values) except: from resources.lib.modules import log_utils log_utils.error() def items_list(i): if self.list[i]['metacache']: return try: values = {} tmdb = self.list[i].get('tmdb', '') movie_meta = cache.get(self.get_movie_meta, 96, tmdb) values.update(movie_meta) imdb = values['imdb'] if self.enable_fanarttv: extended_art = fanarttv_cache.get(fanarttv.get_movie_art, 168, imdb, tmdb) 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': '', 'lang': self.lang, 'user': self.user, 'item': values} self.meta.append(meta) except: from resources.lib.modules import log_utils log_utils.error() self.list = metacache.fetch(self.list, self.lang, self.user) threads = [] for i in range(0, len(self.list)): threads.append(Thread(target=items_list, args=(i,))) [i.start() for i in threads] [i.join() for i in threads] if self.meta: self.meta = [i for i in self.meta if i.get('tmdb')] metacache.insert(self.meta) sorted_list = [] self.list = [i for i in self.list if i.get('tmdb')] for i in sortList: sorted_list += [item for item in self.list if item['tmdb'] == i] # resort to match TMDb list because threading will lose order. return sorted_list