def worker(self, level=1): self.meta = [] total = len(self.list) self.fanart_tv_headers = {'api-key': 'NDZkZmMyN2M1MmE0YTc3MjY3NWQ4ZTMyYjdiY2E2OGU='.decode('base64')} if not self.fanart_tv_user == '': self.fanart_tv_headers.update({'client-key': self.fanart_tv_user}) 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: metacache.insert(self.meta) self.list = [i for i in self.list if not i['tvdb'] == '0'] if self.fanart_tv_user == '': for i in self.list: i.update({'clearlogo': '0', 'clearart': '0'})
def get(self, netloc, ua, timeout): threads = [] for i in range(0, 15): threads.append(workers.Thread(self.get_cookie, netloc, ua, timeout)) [i.start() for i in threads] for i in range(0, 30): if not self.cookie == None: return self.cookie time.sleep(1)
def get(self): channels = [ ('01', 'Sky Premiere', '4021'), ('02', 'Sky Premiere +1', '1823'), ('03', 'Sky Showcase', '4033'), ('04', 'Sky Greats', '1815'), ('05', 'Sky Disney', '4013'), ('06', 'Sky Family', '4018'), ('07', 'Sky Action', '4014'), ('08', 'Sky Comedy', '4019'), ('09', 'Sky Crime', '4062'), ('10', 'Sky Drama', '4016'), ('11', 'Sky Sci Fi', '4017'), ('12', 'Sky Select', '4020'), ('13', 'Film4', '4044'), ('14', 'Film4 +1', '1629'), ('15', 'TCM', '3811'), ('16', 'TCM +1', '5275') ] threads = [] for i in channels: threads.append(workers.Thread(self.sky_list, i[0], i[1], i[2])) [i.start() for i in threads] [i.join() for i in threads] threads = [] for i in range(0, len(self.items)): threads.append(workers.Thread(self.items_list, self.items[i])) [i.start() for i in threads] [i.join() for i in threads] self.list = metacache.local(self.list, self.tm_img_link, 'poster2', 'fanart') try: self.list = sorted(self.list, key=lambda k: k['num']) except: pass self.channelDirectory(self.list) return self.list
def tvmaze_list(self, url): try: result = client.request(url) result = client.parseDOM(result, 'section', attrs = {'id': 'this-seasons-shows'}) items = client.parseDOM(result, 'li') items = [client.parseDOM(i, 'a', ret='href') for i in items] items = [i[0] for i in items if len(i) > 0] items = [re.findall('/(\d+)/', i) for i in items] items = [i[0] for i in items if len(i) > 0] items = items[:50] except: return def items_list(i): try: url = self.tvmaze_info_link % i item = client.request(url) item = json.loads(item) title = item['name'] title = re.sub('\s(|[(])(UK|US|AU|\d{4})(|[)])$', '', title) title = client.replaceHTMLCodes(title) title = title.encode('utf-8') year = item['premiered'] year = re.findall('(\d{4})', year)[0] year = year.encode('utf-8') if int(year) > int((self.datetime).strftime('%Y')): raise Exception() imdb = item['externals']['imdb'] if imdb == None or imdb == '': imdb = '0' else: imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) imdb = imdb.encode('utf-8') tvdb = item['externals']['thetvdb'] tvdb = re.sub('[^0-9]', '', str(tvdb)) tvdb = tvdb.encode('utf-8') if tvdb == None or tvdb == '': raise Exception() try: poster = item['image']['original'] except: poster = '0' if poster == None or poster == '': poster = '0' poster = poster.encode('utf-8') premiered = item['premiered'] try: premiered = re.findall('(\d{4}-\d{2}-\d{2})', premiered)[0] except: premiered = '0' premiered = premiered.encode('utf-8') try: studio = item['network']['name'] except: studio = '0' if studio == None: studio = '0' studio = studio.encode('utf-8') try: genre = item['genres'] except: genre = '0' genre = [i.title() for i in genre] if genre == []: genre = '0' genre = ' / '.join(genre) genre = genre.encode('utf-8') try: duration = item['runtime'] except: duration = '0' if duration == None: duration = '0' duration = str(duration) duration = duration.encode('utf-8') try: rating = item['rating']['average'] except: rating = '0' if rating == None or rating == '0.0': rating = '0' rating = str(rating) rating = rating.encode('utf-8') try: plot = item['summary'] except: plot = '0' if plot == None: plot = '0' plot = re.sub('<.+?>|</.+?>|\n', '', plot) plot = client.replaceHTMLCodes(plot) plot = plot.encode('utf-8') try: content = item['type'].lower() except: content = '0' if content == None or content == '': content = '0' content = content.encode('utf-8') self.list.append({'title': title, 'originaltitle': title, 'year': year, 'premiered': premiered, 'studio': studio, 'genre': genre, 'duration': duration, 'rating': rating, 'plot': plot, 'imdb': imdb, 'tvdb': tvdb, 'poster': poster, 'content': content}) except: pass try: threads = [] for i in items: threads.append(workers.Thread(items_list, i)) [i.start() for i in threads] [i.join() for i in threads] filter = [i for i in self.list if i['content'] == 'scripted'] filter += [i for i in self.list if not i['content'] == 'scripted'] self.list = filter return self.list except: return
def video_list(self, cid, url, pagination): try: result = client.request(url) result = json.loads(result) items = result['items'] except: pass for i in range(1, 5): try: if pagination == True: raise Exception() if not 'nextPageToken' in result: raise Exception() page = url + '&pageToken=' + result['nextPageToken'] result = client.request(page) result = json.loads(result) items += result['items'] except: pass try: if pagination == False: raise Exception() next = cid + '&pageToken=' + result['nextPageToken'] except: next = '' for item in items: try: title = item['snippet']['title'] title = title.encode('utf-8') try: url = item['snippet']['resourceId']['videoId'] except: url = item['id']['videoId'] url = url.encode('utf-8') image = item['snippet']['thumbnails']['high']['url'] if '/default.jpg' in image: raise Exception() image = image.encode('utf-8') append = {'title': title, 'url': url, 'image': image} if not next == '': append['next'] = next self.list.append(append) except: pass try: u = [ range(0, len(self.list))[i:i + 50] for i in range(len(range(0, len(self.list))))[::50] ] u = [','.join([self.list[x]['url'] for x in i]) for i in u] u = [self.content_link % i + self.key_link for i in u] threads = [] for i in range(0, len(u)): threads.append(workers.Thread(self.thread, u[i], i)) self.data.append('') [i.start() for i in threads] [i.join() for i in threads] items = [] for i in self.data: items += json.loads(i)['items'] except: pass for item in range(0, len(self.list)): try: vid = self.list[item]['url'] self.list[item]['url'] = self.play_link % vid d = [(i['id'], i['contentDetails']) for i in items] d = [i for i in d if i[0] == vid] d = d[0][1]['duration'] duration = 0 try: duration += 60 * 60 * int(re.findall('(\d*)H', d)[0]) except: pass try: duration += 60 * int(re.findall('(\d*)M', d)[0]) except: pass try: duration += int(re.findall('(\d*)S', d)[0]) except: pass duration = str(duration) self.list[item]['duration'] = duration except: pass return self.list
def getSources(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, presetDict=[], timeout=30): progressDialog = control.progressDialog progressDialog.create(control.addonInfo('name'), '') progressDialog.update(0, 'Warming Up Scrapers...') content = 'movie' if tvshowtitle is None else 'episode' try: timeout = int(control.setting('scrapers.timeout.1')) except: pass allow_debrid = control.setting("allow_debrid") == "true" if control.setting('cachesources') == 'true': control.makeFile(control.dataPath) self.sourceFile = control.providercacheFile if content == 'movie': title = self.getTitle(title) scraper = nanscrapers.scrape_movie links_scraper = scraper(title, year, imdb, timeout=timeout, enable_debrid=allow_debrid) else: tvshowtitle = self.getTitle(tvshowtitle) scraper = nanscrapers.scrape_episode links_scraper = scraper(tvshowtitle, year, premiered, season, episode, imdb, tvdb, timeout=timeout, enable_debrid=allow_debrid) thread = workers.Thread(self.get_nan_sources, links_scraper, progressDialog) thread.start() for i in range(0, timeout * 2): try: if xbmc.abortRequested: return sys.exit() try: if progressDialog.iscanceled(): break except: pass if not thread.is_alive(): break time.sleep(0.5) except: pass try: progressDialog.close() except: pass self.sourcesFilter() return self.sources
def playItem(self, title, source): try: meta = control.window.getProperty(self.metaProperty) meta = json.loads(meta) year = meta['year'] if 'year' in meta else None season = meta['season'] if 'season' in meta else None episode = meta['episode'] if 'episode' in meta else None imdb = meta['imdb'] if 'imdb' in meta else None tvdb = meta['tvdb'] if 'tvdb' in meta else None next = [] prev = [] total = [] for i in range(1, 1000): try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = dict(urlparse.parse_qsl(u.replace('?', ''))) u = json.loads(u['source'])[0] next.append(u) except: break for i in range(-1000, 0)[::-1]: try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = dict(urlparse.parse_qsl(u.replace('?', ''))) u = json.loads(u['source'])[0] prev.append(u) except: break items = json.loads(source) items = [i for i in items + next + prev][:40] header = control.addonInfo('name') header2 = header.upper() progressDialog = control.progressDialog progressDialog.create(header, '') progressDialog.update(0) block = None for i in range(len(items)): try: try: if progressDialog.iscanceled(): break progressDialog.update( int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update( int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]) w.start() m = '' for x in range(3600): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass k = control.condVisibility( 'Window.IsActive(virtualkeyboard)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break k = control.condVisibility( 'Window.IsActive(yesnoDialog)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break time.sleep(0.5) for x in range(30): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass if m == '': break if w.is_alive() == False: break time.sleep(0.5) if w.is_alive() == True: block = items[i]['source'] if self.url == None: raise Exception() try: progressDialog.close() except: pass control.sleep(200) control.execute('Dialog.Close(virtualkeyboard)') control.execute('Dialog.Close(yesnoDialog)') from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, self.url, meta) return self.url except: pass try: progressDialog.close() except: pass self.errorForSources() except: pass
def play_dialog(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, meta, select): try: url = None items = self.getSource_dialog(title, year, imdb, tvdb, season, episode, tvshowtitle, premiered) title = tvshowtitle if not tvshowtitle == None else title header = control.addonInfo('name') header2 = header.upper() try: meta = json.loads(meta) except: meta = '' progressDialog = control.progressDialog progressDialog.create(header, '') progressDialog.update(0) filter = [] for i in range(len(items)): try: try: label = '[B]%s[/B] | %s | [B][I]%s [/I][/B]' % ( items[i]['scraper'], items[i]['source'], items[i]['quality']) if progressDialog.iscanceled(): break progressDialog.update( int((100 / float(len(items))) * i), label.upper(), '') except: progressDialog.update( int((100 / float(len(items))) * i), str(header2), label.upper()) w = workers.Thread(self.sourcesResolve, items[i]) w.start() m = '' for x in range(3600): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass k = control.condVisibility( 'Window.IsActive(virtualkeyboard)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break k = control.condVisibility( 'Window.IsActive(yesnoDialog)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break time.sleep(0.5) for x in range(30): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass if m == '': break if w.is_alive() == False: break time.sleep(0.5) if w.is_alive() == True: block = items[i] if self.url == None: raise Exception() try: progressDialog.close() except: pass control.sleep(200) control.execute('Dialog.Close(virtualkeyboard)') control.execute('Dialog.Close(yesnoDialog)') from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, self.url, meta) return self.url except: pass try: progressDialog.close() except: pass self.errorForSources() except: pass
def sourcesDialog(self, items): try: labels = [i['label'] for i in items] select = control.selectDialog(labels) if select == -1: return 'close://' next = [y for x, y in enumerate(items) if x >= select] prev = [y for x, y in enumerate(items) if x < select][::-1] items = [items[select]] items = [i for i in items + next + prev][:40] header = control.addonInfo('name') header2 = header.upper() progressDialog = control.progressDialog if control.setting( 'progress.dialog') == '0' else control.progressDialogBG progressDialog.create(header, '') progressDialog.update(0) block = None for i in range(len(items)): try: if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]) w.start() try: if progressDialog.iscanceled(): break progressDialog.update( int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update( int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) m = '' for x in range(3600): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass k = control.condVisibility( 'Window.IsActive(virtualkeyboard)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break k = control.condVisibility( 'Window.IsActive(yesnoDialog)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break time.sleep(0.5) for x in range(30): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass if m == '': break if w.is_alive() == False: break time.sleep(0.5) if w.is_alive() == True: block = items[i]['source'] if self.url == None: raise Exception() self.selectedSource = items[i]['label'] try: progressDialog.close() except: pass control.execute('Dialog.Close(virtualkeyboard)') control.execute('Dialog.Close(yesnoDialog)') return self.url except: pass try: progressDialog.close() except: pass except: try: progressDialog.close() except: pass
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') string6 = '[B][COLOR skyblue]Cypher now decoding streams[/COLOR][/B]' 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(string6), 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