def is_anime(content, type, type_id): try: r = trakt.getGenre(content, type, type_id) return 'anime' in r or 'animation' in r except: return False
def getSources(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, timeout=30): progressDialog = control.progressDialog if control.setting( 'progress.dialog') == '0' else control.progressDialogBG progressDialog.create(control.addonInfo('name'), '') progressDialog.update(0) self.prepareSources() sourceDict = self.sourceDict content = 'movie' if tvshowtitle == None else 'episode' if content == 'movie': sourceDict = [(i[0], i[1], getattr(i[1], 'movie', None)) for i in sourceDict] genres = trakt.getGenre('movie', 'imdb', imdb) else: sourceDict = [(i[0], i[1], getattr(i[1], 'tvshow', None)) for i in sourceDict] genres = trakt.getGenre('show', 'tvdb', tvdb) sourceDict = [(i[0], i[1], i[2]) for i in sourceDict if not hasattr(i[1], 'genre_filter') or not i[1].genre_filter or any(x in i[1].genre_filter for x in genres)] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == None] language = self.getLanguage() sourceDict = [(i[0], i[1], i[1].language) for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if any(x in i[2] for x in language)] try: sourceDict = [(i[0], i[1], control.setting('provider.' + i[0])) for i in sourceDict] except: sourceDict = [(i[0], i[1], 'true') for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == 'false'] sourceDict = [(i[0], i[1], i[1].priority) for i in sourceDict] threads = [] if content == 'movie': title = self.getTitle(title) localtitle = self.getLocalTitle(title, imdb, tvdb, content) aliases = self.getAliasTitles(imdb, localtitle, content) for i in sourceDict: threads.append( workers.Thread(self.getMovieSource, title, localtitle, aliases, year, imdb, i[0], i[1])) else: tvshowtitle = self.getTitle(tvshowtitle) localtvshowtitle = self.getLocalTitle(tvshowtitle, imdb, tvdb, content) aliases = self.getAliasTitles(imdb, localtvshowtitle, content) for i in sourceDict: threads.append( workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, localtvshowtitle, aliases, premiered, i[0], i[1])) s = [i[0] + (i[1], ) for i in zip(sourceDict, threads)] s = [(i[3].getName(), i[0], i[2]) for i in s] mainsourceDict = [i[0] for i in s if i[2] == 0] sourcelabelDict = dict([(i[0], i[1].upper()) for i in s]) [i.start() for i in threads] string1 = control.lang(32404).encode('utf-8') string2 = control.lang(32405).encode('utf-8') string3 = control.lang(32406).encode('utf-8') try: timeout = int(control.setting('scrapers.timeout.1')) except: pass for i in range(0, (timeout * 2) + 60): try: if xbmc.abortRequested == True: return sys.exit() try: info = [ sourcelabelDict[x.getName()] for x in threads if x.is_alive() == True ] except: info = [] timerange = int(i * 0.5) try: if progressDialog.iscanceled(): break except: pass try: string4 = string1 % str(timerange) if len(info) > 5: string5 = string3 % str(len(info)) else: string5 = string3 % str(info).translate(None, "[]'") progressDialog.update( int((100 / float(len(threads))) * len([x for x in threads if x.is_alive() == False])), str(string4), str(string5)) except: pass is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break if timerange >= timeout: is_alive = [ x for x in threads if x.is_alive() == True and x.getName() in mainsourceDict ] if not is_alive: break time.sleep(0.5) except: pass try: progressDialog.close() except: pass self.sourcesFilter() return self.sources
def is_anime(content, type, type_id): try: r = trakt.getGenre(content, type, type_id) return 'anime' in r or 'animation' in r except: return False
def getSources(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, quality='HD', timeout=30): progressDialog = control.progressDialog if control.setting('progress.dialog') == '0' else control.progressDialogBG progressDialog.create(control.addonInfo('name'), '') progressDialog.update(0) self.prepareSources() sourceDict = self.sourceDict progressDialog.update(0, control.lang(32588).encode('utf-8')) content = 'movie' if tvshowtitle == None else 'episode' if content == 'movie': sourceDict = [(i[0], i[1], getattr(i[1], 'movie', None)) for i in sourceDict] genres = trakt.getGenre('movie', 'imdb', imdb) else: sourceDict = [(i[0], i[1], getattr(i[1], 'tvshow', None)) for i in sourceDict] genres = trakt.getGenre('show', 'tvdb', tvdb) progressDialog.update(0, control.lang(32589).encode('utf-8')) sourceDict = [(i[0], i[1], i[2]) for i in sourceDict if not hasattr(i[1], 'genre_filter') or not i[1].genre_filter or any(x in i[1].genre_filter for x in genres)] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == None] language = self.getLanguage() sourceDict = [(i[0], i[1], i[1].language) for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if any(x in i[2] for x in language)] try: sourceDict = [(i[0], i[1], control.setting('provider.' + i[0])) for i in sourceDict] except: sourceDict = [(i[0], i[1], 'true') for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == 'false'] sourceDict = [(i[0], i[1], i[1].priority) for i in sourceDict] threads = [] if content == 'movie': title = self.getTitle(title) localtitle = self.getLocalTitle(title, imdb, tvdb, content) aliases = self.getAliasTitles(imdb, localtitle, content) for i in sourceDict: threads.append(workers.Thread(self.getMovieSource, title, localtitle, aliases, year, imdb, i[0], i[1])) else: tvshowtitle = self.getTitle(tvshowtitle) localtvshowtitle = self.getLocalTitle(tvshowtitle, imdb, tvdb, content) aliases = self.getAliasTitles(imdb, localtvshowtitle, content) season, episode = thexem.get_scene_episode_number(tvdb, season, episode) for i in sourceDict: threads.append(workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, localtvshowtitle, aliases, premiered, i[0], i[1])) s = [i[0] + (i[1],) for i in zip(sourceDict, threads)] s = [(i[3].getName(), i[0], i[2]) for i in s] mainsourceDict = [i[0] for i in s if i[2] == 0] sourcelabelDict = dict([(i[0], i[1].upper()) for i in s]) [i.start() for i in threads] string1 = control.lang(32404).encode('utf-8') string2 = control.lang(32405).encode('utf-8') string3 = control.lang(32406).encode('utf-8') try: timeout = int(control.setting('scrapers.timeout.1')) except: pass for i in range(0, (timeout * 2) + 60): try: if xbmc.abortRequested == True: return sys.exit() try: info = [sourcelabelDict[x.getName()] for x in threads if x.is_alive() == True] except: info = [] timerange = int(i * 0.5) try: if progressDialog.iscanceled(): break except: pass try: string4 = string1 % str(timerange) if len(info) > 5: string5 = string3 % str(len(info)) else: string5 = string3 % str(info).translate(None, "[]'") progressDialog.update(int((100 / float(len(threads))) * len([x for x in threads if x.is_alive() == False])), str(string4), str(string5)) except: pass is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break if timerange >= timeout: is_alive = [x for x in threads if x.is_alive() == True and x.getName() in mainsourceDict] if not is_alive: break time.sleep(0.5) except: pass if control.addonInfo('id') == 'plugin.video.bennu': try: if progressDialog: progressDialog.update(100, control.lang(30726).encode('utf-8'), control.lang(30731).encode('utf-8')) items = self.sourcesFilter() if quality == 'RD': items = [i for i in items if i['debrid'] != ''] elif quality == 'SD': items = [i for i in items if i['quality'] == 'SD' and i['debrid'] == ''] elif quality == 'HD': items = [i for i in items if i['quality'] != 'SD'] if control.setting('bennu.dev.log') == 'true': log_utils.log('Sources Returned: %s' % str(items), log_utils.LOGNOTICE) try: progressDialog.close() except: pass if quality == 'AUTO': u = self.sourcesDirect(items) return u else: meta = '{"title": "%s", "year": "%s", "imdb": "%s"}' % (title, year, imdb) '''control.window.clearProperty("plugin.video.bennu.container.items") control.window.setProperty("plugin.video.bennu.container.items", json.dumps(items)) control.window.clearProperty("plugin.video.bennu.container.meta") control.window.setProperty("plugin.video.bennu.container.meta", meta)''' control.window.clearProperty(self.itemProperty) control.window.setProperty(self.itemProperty, json.dumps(items)) control.window.clearProperty(self.metaProperty) control.window.setProperty(self.metaProperty, meta) control.sleep(200) control.execute('Container.Update(%s?action=addItem&title=%s)' % (sys.argv[0], urllib.quote_plus(title))) return "DIR" except: try: progressDialog.close() except: pass return else: try: progressDialog.close() except: pass self.sourcesFilter() return self.sources
def is_anime(content, type, type_id): try: r = trakt.getGenre(content, type, type_id) return "anime" in r or "animation" in r except: return False
def getSources(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, quality='HD', timeout=30): progressDialog = control.progressDialog if control.setting( 'progress.dialog') == '0' else control.progressDialogBG progressDialog.create(control.addonInfo('name'), '') progressDialog.update(0) self.prepareSources() sourceDict = self.sourceDict progressDialog.update(0, control.lang(32600).encode('utf-8')) content = 'movie' if tvshowtitle is None else 'episode' if content == 'movie': sourceDict = [(i[0], i[1], getattr(i[1], 'movie', None)) for i in sourceDict] genres = trakt.getGenre('movie', 'imdb', imdb) else: sourceDict = [(i[0], i[1], getattr(i[1], 'tvshow', None)) for i in sourceDict] genres = trakt.getGenre('show', 'tvdb', tvdb) sourceDict = [(i[0], i[1], i[2]) for i in sourceDict if not hasattr(i[1], 'genre_filter') or not i[1].genre_filter or any(x in i[1].genre_filter for x in genres)] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] is None] language = self.getLanguage() sourceDict = [(i[0], i[1], i[1].language) for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if any(x in i[2] for x in language)] try: sourceDict = [(i[0], i[1], control.setting('provider.' + i[0])) for i in sourceDict] except: sourceDict = [(i[0], i[1], 'true') for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == 'false'] sourceDict = [(i[0], i[1], i[1].priority) for i in sourceDict] random.shuffle(sourceDict) sourceDict = sorted(sourceDict, key=lambda i: i[2]) threads = [] if content == 'movie': title = self.getTitle(title) localtitle = self.getLocalTitle(title, imdb, tvdb, content) aliases = self.getAliasTitles(imdb, localtitle, content) for i in sourceDict: threads.append(workers.Thread(self.getMovieSource, title, localtitle, aliases, year, imdb, i[0], i[1])) else: tvshowtitle = self.getTitle(tvshowtitle) localtvshowtitle = self.getLocalTitle(tvshowtitle, imdb, tvdb, content) aliases = self.getAliasTitles(imdb, localtvshowtitle, content) for i in sourceDict: threads.append(workers.Thread( self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, localtvshowtitle, aliases, premiered, i[0], i[1])) s = [i[0] + (i[1],) for i in zip(sourceDict, threads)] s = [(i[3].getName(), i[0], i[2]) for i in s] mainsourceDict = [i[0] for i in s if i[2] == 0] sourcelabelDict = dict([(i[0], i[1].upper()) for i in s]) [i.start() for i in threads] string1 = control.lang(32404).encode('utf-8') string2 = control.lang(32405).encode('utf-8') string3 = control.lang(32406).encode('utf-8') string4 = control.lang(32601).encode('utf-8') string5 = control.lang(32602).encode('utf-8') string6 = control.lang(32606).encode('utf-8') string7 = control.lang(32607).encode('utf-8') try: timeout = int(control.setting('scrapers.timeout.1')) except: pass quality = control.setting('hosts.quality') if quality == '': quality = '0' line1 = line2 = line3 = "" source_4k = d_source_4k = 0 source_1080 = d_source_1080 = 0 source_720 = d_source_720 = 0 source_sd = d_source_sd = 0 total = d_total = 0 total_format = '[COLOR %s][B]%s[/B][/COLOR]' pdiag_format = ' 4K: %s | 1080p: %s | 720p: %s | SD: %s | Total: %s'.split('|') pdiag_bg_format = '4K:%s|1080p:%s|720p:%s|SD:%s|T:%s'.split('|') for i in range(0, 4 * timeout): try: if xbmc.abortRequested is True: return sys.exit() try: if progressDialog.iscanceled(): break except: pass if len(self.sources) > 0: if quality in ['0']: source_4k = len([e for e in self.sources if e['quality'] == '4K']) source_1080 = len([e for e in self.sources if e['quality'] == '1080p']) source_720 = len([e for e in self.sources if e['quality'] == '720p']) source_sd = len([e for e in self.sources if e['quality'] == 'SD']) elif quality in ['1']: source_1080 = len([e for e in self.sources if e['quality'] == '1080p']) source_720 = len([e for e in self.sources if e['quality'] == '720p']) source_sd = len([e for e in self.sources if e['quality'] == 'SD']) elif quality in ['2']: source_720 = len([e for e in self.sources if e['quality'] == '720p']) source_sd = len([e for e in self.sources if e['quality'] == 'SD']) else: source_sd = len([e for e in self.sources if e['quality'] == 'SD']) total = source_4k + source_1080 + source_720 + source_sd source_4k_label = total_format % ('red', source_4k) if source_4k == 0 else total_format % ('lime', source_4k) source_1080_label = total_format % ('red', source_1080) if source_1080 == 0 else total_format % ('lime', source_1080) source_720_label = total_format % ('red', source_720) if source_720 == 0 else total_format % ('lime', source_720) source_sd_label = total_format % ('red', source_sd) if source_sd == 0 else total_format % ('lime', source_sd) source_total_label = total_format % ('red', total) if total == 0 else total_format % ('lime', total) if (i / 2) < timeout: try: mainleft = [sourcelabelDict[x.getName()] for x in threads if x.is_alive() is True and x.getName() in mainsourceDict] info = [sourcelabelDict[x.getName()] for x in threads if x.is_alive() is True] if i >= timeout and len(mainleft) == 0 and len(self.sources) >= 100 * len(info): break # improve responsiveness if quality in ['0']: if not progressDialog == control.progressDialogBG: line1 = ('%s:' + '|'.join(pdiag_format)) % (string7, source_4k_label, source_1080_label, source_720_label, source_sd_label, source_total_label) elif quality in ['1']: if not progressDialog == control.progressDialogBG: line1 = ('%s:' + '|'.join(pdiag_format[1:])) % (string7, source_1080_label, source_720_label, source_sd_label, source_total_label) elif quality in ['2']: if not progressDialog == control.progressDialogBG: line1 = ('%s:' + '|'.join(pdiag_format[2:])) % (string7, source_720_label, source_sd_label, source_total_label) else: if not progressDialog == control.progressDialogBG: line1 = ('%s:' + '|'.join(pdiag_format[3:])) % (string7, source_sd_label, source_total_label) if quality in ['0']: line1 = '|'.join(pdiag_format) % (source_4k_label, source_1080_label, source_720_label, source_sd_label, source_total_label) elif quality in ['1']: line1 = '|'.join(pdiag_format[1:]) % (source_1080_label, source_720_label, source_sd_label, source_total_label) elif quality in ['2']: line1 = '|'.join(pdiag_format[2:]) % (source_720_label, source_sd_label, source_total_label) else: line1 = '|'.join(pdiag_format[3:]) % (source_sd_label, source_total_label) if len(info) > 6: line1 = string3 % (str(len(info))) elif len(info) > 0: line1 = string3 % (', '.join(info)) else: break percent = int(100 * float(i) / (2 * timeout) + 0.5) progressDialog.update(max(1, percent), line1, line2) except Exception as e: log_utils.log('Exception Raised: %s' % str(e), log_utils.LOGERROR) else: try: mainleft = [sourcelabelDict[x.getName()] for x in threads if x.is_alive() is True and x.getName() in mainsourceDict] info = mainleft if len(info) > 6: line1 = 'Waiting for: %s' % (str(len(info))) elif len(info) > 0: line1 = 'Waiting for: %s' % (', '.join(info)) else: break percent = int(100 * float(i) / (2 * timeout) + 0.5) % 100 progressDialog.update(max(1, percent), line1, line2) except: break time.sleep(0.5) except: pass try: progressDialog.close() except: pass self.sourcesFilter() return self.sources