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 getSources(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, quality='HD', timeout=20): u = None progressDialog = control.progressDialog 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] else: sourceDict = [(i[0], i[1], getattr(i[1], 'tvshow', None)) for i in sourceDict] sourceDict = [(i[0], i[1]) for i in sourceDict if not i[2] == None] sourceDict = [(i[0], i[1], i[1].priority) for i in sourceDict] if quality == 'SD': sourceDict = [i for i in sourceDict if i[2] == 0] threads = [] if content == 'movie': title = self.getTitle(title) for i in sourceDict: threads.append(workers.Thread(self.getMovieSource, title, title, year, imdb, i[0], i[1])) else: tvshowtitle = self.getTitle(tvshowtitle) for i in sourceDict: threads.append(workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, tvshowtitle, 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') 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 progressDialog.update(100, control.lang(30726).encode('utf-8'), control.lang(30731).encode('utf-8')) items = self.sourcesFilter() filter = [i for i in items if i['source'].lower() in self.hostcapDict and i['debrid'] == ''] items = [i for i in items if not i in filter] filter = [i for i in items if i['source'].lower() in self.hostblockDict and i['debrid'] == ''] items = [i for i in items if not i in filter] items = [i for i in items if ('autoplay' in i and i['autoplay'] == True) or not 'autoplay' in i] for i in range(len(items)): try: if progressDialog.iscanceled(): break if xbmc.abortRequested == True: return sys.exit() url = self.sourcesResolve(items[i]) if u == None: u = url if not url == None: break except: pass try: progressDialog.close() except: pass return u
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