def get(self): channels = [('01', 'Sky Premiere', '1409'), ('02', 'Sky Premiere +1', '1823'), ('03', 'Sky Showcase', '1814'), ('04', 'Sky Greats', '1815'), ('05', 'Sky Disney', '1838'), ('06', 'Sky Family', '1808'), ('07', 'Sky Action', '1001'), ('08', 'Sky Comedy', '1002'), ('09', 'Sky Crime', '1818'), ('10', 'Sky Drama', '1816'), ('11', 'Sky Sci Fi', '1807'), ('12', 'Sky Select', '1811'), ('13', 'Film4', '1627'), ('14', 'TCM', '5605')] 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] try: self.list = sorted(self.list, key=lambda k: k['num']) except: pass self.channelDirectory(self.list) return self.list
def getSources(self, name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date): sourceDict = [] for package, name, is_pkg in pkgutil.walk_packages(__path__): sourceDict.append((name, is_pkg)) sourceDict = [i[0] for i in sourceDict if i[1] == False] content = 'movie' if tvshowtitle == None else 'episode' if content == 'movie': sourceDict = [i for i in sourceDict if i.endswith(('_mv', '_mv_tv'))] try: sourceDict = [(i, control.setting(re.sub('_mv_tv$|_mv$|_tv$', '', i))) for i in sourceDict] except: sourceDict = [(i, 'true') for i in sourceDict] else: sourceDict = [i for i in sourceDict if i.endswith(('_tv', '_mv_tv'))] try: sourceDict = [(i, control.setting(re.sub('_mv_tv$|_mv$|_tv$', '', i) + '_tv')) for i in sourceDict] except: sourceDict = [(i, 'true') for i in sourceDict] global global_sources global_sources = [] threads = [] control.makeFile(control.dataPath) self.sourceFile = control.sourcescacheFile sourceDict = [i[0] for i in sourceDict if i[1] == 'true'] if content == 'movie': title = cleantitle.normalize(title) for source in sourceDict: threads.append(workers.Thread(self.getMovieSource, title, year, imdb, re.sub('_mv_tv$|_mv$|_tv$', '', source), __import__(source, globals(), locals(), [], -1).source())) else: tvshowtitle = cleantitle.normalize(tvshowtitle) season, episode = alterepisode.alterepisode().get(imdb, tmdb, tvdb, tvrage, season, episode, alter, title, date) for source in sourceDict: threads.append(workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, date, re.sub('_mv_tv$|_mv$|_tv$', '', source), __import__(source, globals(), locals(), [], -1).source())) try: timeout = int(control.setting('sources_timeout_15')) except: timeout = 10 [i.start() for i in threads] #[i.join() for i in threads] ; self.sources = global_sources ; return self.sources for i in range(0, timeout * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(0.5) for i in range(0, 5 * 2): is_alive = len([i for i in threads if i.is_alive() == True]) if is_alive < 10: break time.sleep(0.5) self.sources = global_sources return self.sources
def getSources(self, name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date, proxy_options, provider_options, key, session): #try: sourceDict = [] self.getSourcesAlive = True if provider_options !=None: myProviders = [] for prov in provider_options: myProviders += [i for i in self.providersCaller if i['url'].lower() == prov['url'].lower() and str(prov['enabled'])=='True'] else: myProviders = self.providersCaller content = 'movie' if tvshowtitle == None else 'show' self.threads[key] = [] if content == 'movie': log(err='Searching Movie: %s' % title) title = cleantitle.normalize(title) for source in myProviders: try: source_name = 'Unknow source (import error)' source_name = source['name'] log(err='Searching Movie: %s (%s) in Provider %s' % (title,year,source_name)) thread_i = workers.Thread(self.getMovieSource, title, year, imdb, proxy_options, key, re.sub('_mv_tv$|_mv$|_tv$', '', source['name']), source['call']) self.threads[key].append(thread_i) thread_i.start() except Exception as e: log(type='ERROR', err='getSources %s - %s' % (source_name,e)) else: log(err='Searching Show: %s' % tvshowtitle) try: tvshowtitle = cleantitle.normalize(tvshowtitle) except: pass try: season, episode = alterepisode.alterepisode().get(imdb, tmdb, tvdb, tvrage, season, episode, alter, title, date) except: pass for source in myProviders: try: source_name = 'Unknow source (import error)' source_name = source['name'] log(err='Searching Show: %s S%sE%s in Provider %s' % (tvshowtitle,season,episode,source_name)) thread_i = workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, date, proxy_options, key, re.sub('_mv_tv$|_mv$|_tv$', '', source_name), source['call']) self.threads[key].append(thread_i) thread_i.start() except Exception as e: log(type='ERROR', err='getSources %s - %s' % (source_name,e)) #sourceLabel = [re.sub('_mv_tv$|_mv$|_tv$', '', i) for i in sourceDict] #sourceLabel = [re.sub('v\d+$', '', i).upper() for i in sourceLabel] #time.sleep(0.5) self.getSourcesAlive = False return self.sources
def checkSources(self, name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date): sourceDict = [] for package, name, is_pkg in pkgutil.walk_packages(__path__): sourceDict.append((name, is_pkg)) sourceDict = [i[0] for i in sourceDict if i[1] == False] content = 'movie' if tvshowtitle == None else 'episode' if content == 'movie': sourceDict = [i for i in sourceDict if i.endswith(('_mv', '_mv_tv'))] try: sourceDict = [(i, control.setting(re.sub('_mv_tv$|_mv$|_tv$', '', i))) for i in sourceDict] except: sourceDict = [(i, 'true') for i in sourceDict] else: sourceDict = [i for i in sourceDict if i.endswith(('_tv', '_mv_tv'))] try: sourceDict = [(i, control.setting(re.sub('_mv_tv$|_mv$|_tv$', '', i) + '_tv')) for i in sourceDict] except: sourceDict = [(i, 'true') for i in sourceDict] threads = [] control.makeFile(control.dataPath) self.sourceFile = control.sourcescacheFile sourceDict = [i[0] for i in sourceDict if i[1] == 'true'] if content == 'movie': title = cleantitle.normalize(title) for source in sourceDict: threads.append(workers.Thread(self.getMovieSource, title, year, imdb, re.sub('_mv_tv$|_mv$|_tv$', '', source), __import__(source, globals(), locals(), [], -1).source())) else: tvshowtitle = cleantitle.normalize(tvshowtitle) season, episode = alterepisode.alterepisode().get(imdb, tmdb, tvdb, tvrage, season, episode, alter, title, date) for source in sourceDict: #control.log("SOURCE S2 %s" % source) threads.append(workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, date, re.sub('_mv_tv$|_mv$|_tv$', '', source), __import__(source, globals(), locals(), [], -1).source())) try: timeout = int(control.setting('sources_timeout_40')) except: timeout = 40 [i.start() for i in threads] for i in range(0, timeout * 2): try: if xbmc.abortRequested == True: return sys.exit() if len(self.sources) >= 10: break is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(0.5) except: pass if len(self.sources) >= 5: return True else: return False
def getSources(self, name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date, proxy_options, provider_options, key): #try: sourceDict = [] self.getSourcesAlive = True if provider_options !=None: myProviders = [] for prov in provider_options: myProviders += [i for i in self.providersCaller if i['url'].lower() == prov['url'].lower() and str(prov['enabled'])=='True'] else: myProviders = self.providersCaller content = 'movie' if tvshowtitle == None else 'episode' self.threads[key] = [] if content == 'movie': print 'Searching Movie' title = cleantitle.normalize(title) for source in myProviders: try: thread_i = workers.Thread(self.getMovieSource, title, year, imdb, proxy_options, key, re.sub('_mv_tv$|_mv$|_tv$', '', source['name']), source['call']) self.threads[key].append(thread_i) thread_i.start() except Exception as e: print ('Source getSources %s ERROR %s' % (source,e)) control.log('Source getSources %s ERROR %s' % (source,e)) pass else: print 'Searching Episode' try: tvshowtitle = cleantitle.normalize(tvshowtitle) except: pass try: season, episode = alterepisode.alterepisode().get(imdb, tmdb, tvdb, tvrage, season, episode, alter, title, date) except: pass for source in myProviders: try: thread_i = workers.Thread(self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, date, proxy_options, key, re.sub('_mv_tv$|_mv$|_tv$', '', source['name']), source['call']) self.threads[key].append(thread_i) thread_i.start() except Exception as e: print ('Source getSources %s ERROR %s' % (source, e)) control.log('Source getSources %s ERROR %s' % (source, e)) pass #sourceLabel = [re.sub('_mv_tv$|_mv$|_tv$', '', i) for i in sourceDict] #sourceLabel = [re.sub('v\d+$', '', i).upper() for i in sourceLabel] #time.sleep(0.5) self.getSourcesAlive = False return self.sources
def get_sources(self, url, hosthdDict, hostDict, locDict): try: self.sources =[] mylinks = [] hostDict = hostDict.sort() for i in hostDict: control.log("WA HO %s" % i) if url == None: return self.sources url = url.replace('/json/', '/') result = '' result, headers, content, cookie = client.request(urlparse.urljoin(self.base_link, url), output='extended') #result, headers, content, cookie = client.request(url, limit='0', output='extended') self.headers['Referer'] = urlparse.urljoin(self.base_link, url) self.headers['Cookie'] = cookie result = result.replace('\n','') result = result.decode('iso-8859-1').encode('utf-8') result = client.parseDOM(result, 'div', attrs = {'id': 'lang_1'})[0] links = re.compile('href=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>].+?title=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>]').findall(result) links = [x for y,x in enumerate(links) if x not in links[:y]] for i in links: try: host = i[1] host = host.split('.', 1)[0] host = host.strip().lower() #if not host in hostDict: raise Exception() host = client.replaceHTMLCodes(host) host = host.encode('utf-8') url = i[0] url = client.replaceHTMLCodes(url) try: url = urlparse.parse_qs(urlparse.urlparse(url).query)['u'][0] except: pass if not url.startswith('http'): url = urlparse.urljoin(self.base_link, url) if not '/cale/' in url: raise Exception() url = url.encode('utf-8') url = url.replace('/json/', '/') url = urlparse.urlparse(url).path mylinks.append([url, 'SD']) except: pass threads = [] for i in mylinks: threads.append(workers.Thread(self.check, i, hostDict)) [i.start() for i in threads] for i in range(0, 10 * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(1) return self.sources except: return self.sources
def sourcesDialog(self): try: sources = [{'label': '00 | [B]%s[/B]' % control.lang(30509).encode('utf-8').upper()}] + self.sources labels = [i['label'] for i in sources] select = control.selectDialog(labels) if select == 0: return self.sourcesDirect() if select == -1: return 'close://' items = [self.sources[select-1]] next = [y for x,y in enumerate(self.sources) if x >= select] prev = [y for x,y in enumerate(self.sources) if x < select][::-1] source, quality = items[0]['source'], items[0]['quality'] items = [i for i in items+next+prev if i['quality'] == quality and i['source'] == source][:10] items += [i for i in next+prev if i['quality'] == quality and not i['source'] == source][:10] import xbmc dialog = control.progressDialog dialog.create(control.addonInfo('name'), '') dialog.update(0) block = None for i in range(len(items)): try: dialog.update(int((100 / float(len(items))) * i), str(items[i]['label'])) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]['url'], items[i]['provider']) w.start() for x in range(0, 15 * 2): if dialog.iscanceled(): return dialog.close() if xbmc.abortRequested == True: return sys.exit() 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: dialog.close() except: pass self.selectedSource = items[i]['label'] return self.url except: pass try: dialog.close() except: pass except: return
def get_sources(self, url, hosthdDict, hostDict, locDict): try: self.sources = [] mylinks = [] result = client2.http_get(url) mytitle = re.compile('<title>(.*?)</title>', re.DOTALL).findall(result)[0] if any(word in mytitle.lower() for word in [ 'camrip', 'tsrip', 'hdcam', 'hdts', 'dvdcam', 'dvdts', 'cam', 'ts' ]): quality = 'CAM' elif '1080p' in mytitle: quality = '1080p' elif '720p' in mytitle: quality = 'HD' else: quality = 'SD' links = client.parseDOM(result, 'a', attrs={'rel': 'nofollow'}) links = [i for i in links if i.startswith('http')] for a in links: mylinks.append([a, quality]) threads = [] for i in mylinks: threads.append(workers.Thread(self.check, i)) [i.start() for i in threads] for i in range(0, 10 * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(1) return self.sources except: return self.sources
def get_sources(self, url, hosthdDict, hostDict, locDict): try: self.sources =[] mylinks = [] if url == None: return self.sources url = url.replace('/json/', '/') result = '' links = [self.link_1, self.link_2, self.link_3] for base_link in links: result = client.source(urlparse.urljoin(base_link, url), headers=self.headers) if 'lang_1' in str(result): break result = result.replace('\n','') result = result.decode('iso-8859-1').encode('utf-8') result = client.parseDOM(result, 'div', attrs = {'id': 'lang_1'})[0] links = re.compile('href=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>].+?title=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>]').findall(result) links = [x for y,x in enumerate(links) if x not in links[:y]] for i in links: try: host = i[1] host = host.split('.', 1)[0] host = host.strip().lower() if not host in hostDict: raise Exception() host = client.replaceHTMLCodes(host) host = host.encode('utf-8') url = i[0] url = client.replaceHTMLCodes(url) try: url = urlparse.parse_qs(urlparse.urlparse(url).query)['u'][0] except: pass if not url.startswith('http'): url = urlparse.urljoin(self.base_link, url) if not '/cale/' in url: raise Exception() url = url.encode('utf-8') url = url.replace('/json/', '/') url = urlparse.urlparse(url).path #sources.append({'source': host, 'quality': 'SD', 'provider': 'Watchseries', 'url': url}) mylinks.append([url, 'SD']) except: pass threads = [] for i in mylinks: threads.append(workers.Thread(self.check, i)) [i.start() for i in threads] for i in range(0, 10 * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(1) return self.sources except: return self.sources
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 __init__(self): resolvers.init() proxies.init() self.sources = [] self.sourcesDictionary() self.threads = {} self.providers = [] self.providersCaller = [] self.getSourcesAlive = False self.isProvThreadRunning = True workers.Thread(self.initProviders())
def sourcesDialog(self): try: sources = [{ 'label': '00 | [B]%s[/B]' % control.lang(30509).encode('utf-8').upper() }] + self.sources labels = [i['label'] for i in sources] select = control.selectDialog(labels) if select == 0: return self.sourcesDirect() if select == -1: return 'close://' items = [self.sources[select - 1]] next = [y for x, y in enumerate(self.sources) if x >= select] prev = [y for x, y in enumerate(self.sources) if x < select][::-1] source, quality = items[0]['source'], items[0]['quality'] items = [ i for i in items + next + prev if i['quality'] == quality and i['source'] == source ][:15] items += [ i for i in next + prev if i['quality'] == quality and not i['source'] == source ][:35] block = None for i in items: try: if i['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, i['url'], i['provider']) w.start() time.sleep(20) if w.is_alive() == True: block = i['source'] if self.url == None: raise Exception() self.selectedSource = i['label'] return self.url except: pass except: return
def get_sources(self, url, hosthdDict, hostDict, locDict): try: self.sources = [] if url == None: return self.sources url = url.replace('\'', '') url = re.sub(r'[^a-zA-Z0-9\s]+', ' ', url).lower().strip() url = re.sub('\s\s+', ' ', url) url = url.replace(' ', '-') query = urlparse.urljoin(self.base_link, url) result = client.source(query) if result == None: raise Exception() fmt = re.compile('url *: *[\'|\"](.+?)[\'|\"]').findall(result) fmt = fmt[0] if len(fmt) > 0 else '' fmt = re.sub('(.+)(\d{4}|s\d*e\d*)-', '', fmt.lower()) fmt = re.split('-', fmt.replace('/', '')) if any(x in [ 'dvdscr', 'r5', 'r6', 'camrip', 'tsrip', 'hdcam', 'hdts', 'dvdcam', 'dvdts', 'cam', 'ts' ] for x in fmt): raise Exception() elif '1080p' in fmt: quality = '1080p' elif '720p' in fmt: quality = 'HD' else: raise Exception() hostdirhdDict = sources.sources().hostdirhdDict links = client.parseDOM(result, 'a', attrs={'rel': 'nofollow'}) links = [i for i in links if i.startswith('http')] links = [(i, quality, hostdirhdDict) for i in links] threads = [] for i in links: threads.append(workers.Thread(self.check, i)) [i.start() for i in threads] for i in range(0, 10 * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(0.5) return self.sources except: return self.sources
def __init__(self): log(type='INFO', method='init', err=' -- Initializing Start --', name='sources') resolvers.init() proxies.init() self.sources = [] self.sourcesDictionary() self.threads = {} self.threadSlots = {} self.providers = [] self.providersCaller = [] self.providersTimer = {} self.getSourcesAlive = False self.isProvThreadRunning = True workers.Thread(self.initProviders())
def get_sources(self, url): logger.debug('%s SOURCES URL %s' % (self.__class__, url)) try: if url == None: return self.sources url = '%s%s' % (self.base_link, url) try: result = client.source(url) except: result = '' result = result.decode('iso-8859-1').encode('utf-8') result = client.parseDOM(result, "table", attrs={"class": "table table-bordered"})[0] result = client.parseDOM(result, "tbody")[0] result = client.parseDOM(result, "tr") hypermode = False if control.setting( 'hypermode') == 'false' else True threads = [] for item in result: if hypermode: threads.append(workers.Thread(self.get_source, item)) else: self.get_source(item) if hypermode: [i.start() for i in threads] stillWorking = True while stillWorking: stillWorking = False stillWorking = [ True for x in threads if x.is_alive() == True ] logger.debug('%s SOURCES [%s]' % (__name__, self.sources)) return self.sources except: return self.sources
def worker(self): 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.info_lang) for r in range(0, total, 25): threads = [] for i in range(r, r+25): if i <= total: threads.append(workers.Thread(self.super_info, i)) [i.start() for i in threads] [i.join() for i in threads] self.list = [i for i in self.list if not i['imdb'] == '0'] self.list = [i for i in self.list if not i['tvdb'] == '0'] if len(self.meta) > 0: metacache.insert(self.meta)
def worker(self): self.meta = [] total = len(self.list) for i in range(0, total): self.list[i].update({'metacache': False}) self.list = metacache.fetchImdb(self.list) self.list = metacache.fetch(self.list, self.info_lang) itemsPerPage = 25 for r in range(0, total, itemsPerPage): threads = [] for i in range(r, r+itemsPerPage): if i <= total: threads.append(workers.Thread(self.super_info, i)) [i.start() for i in threads] [i.join() for i in threads] metacache.insertImdb(self.list) #self.list = [i for i in self.list if not (i['imdb'] == '0' and i['tmdb'] == '0')] if len(self.meta) > 0: metacache.insert(self.meta)
def initAndSleepThread(self): thread_i = workers.Thread(self.InitSleepThread) thread_i.start()
def searchDirectory(query=None): if (query == None or query == ''): keyboard = control.keyboard('', control.lang(30702).encode('utf-8')) keyboard.doModal() if not (keyboard.isConfirmed()): return query = keyboard.getText() if (query == None or query == ''): return def search(): return [query] result = cache.get(search, 600000000, table='rel_srch') def search(): return [ x for y, x in enumerate((result + [query])) if x not in (result + [query])[:y] ] result = cache.get(search, 0, table='rel_srch') global global_search global_search = [] def worker(url): global_search.append(str(client.request(url))) servers = client.request(phLink) servers = str(servers).replace('\n', '') servers = re.findall('</name><link>(.+?)</link>', servers) servers = [urlparse.urlparse(i).netloc for i in servers] servers = [phSearch % i for i in servers if not 'mecca' in i] threads = [] for server in servers: threads.append(workers.Thread(worker, server)) [i.start() for i in threads] [i.join() for i in threads] urls = global_search global_search = [] urls = [str(i).replace('\n', '') for i in urls] urls = [re.findall('<link>(.+?)</link>', i)[:30] for i in urls] urls = sum(urls, []) threads = [] for url in urls: threads.append(workers.Thread(worker, url)) [i.start() for i in threads] [i.join() for i in threads] links = global_search global_search = [] for link in links: try: link = str(link).replace('\r', '').replace('\n', '').replace( '\t', '').replace(' ', '') try: fanart = re.findall('<fanart>(.+?)</fanart>', link)[0] except: fanart = '0' try: vip = re.findall('<poster>(.+?)</poster>', link)[0] except: vip = '' if vip == 'Team Phoenix': vip = '' try: content = re.findall('<meta>(.+?)</meta>', link)[0] except: content = '0' try: tvshow = re.findall('<tvshow>(.+?)</tvshow>', link)[0] except: tvshow = '0' if content in ['seasons', 'episodes'] and tvshow == '0': content = '0' dirs = re.compile('<dir>(.+?)</dir>').findall(link) for dir in dirs: try: data = {} name = re.findall('<name>(.+?)</name>', dir)[0] name = cleantitle(name) if not query.lower() in name.lower(): raise Exception() url = re.findall('<link>(.+?)</link>', dir)[0] try: image = re.findall('<thumbnail>(.+?)</thumbnail>', dir)[0] except: image = '0' try: fanart2 = re.findall('<fanart>(.+?)</fanart>', dir)[0] except: fanart2 = fanart if content == 'tvshows': try: title = cleantitle(name).encode('utf-8') data = {'title': title, 'tvshowtitle': title} except: pass if re.search('[a-zA-Z]', vip): name += ' [COLOR orange]%s[/COLOR]' % vip addDirectoryItem(name, url, 'ndmode', image, image, fanart2, '0', content, data) except: pass items = re.compile('<item>(.+?)</item>').findall(link) for item in items: try: data = {} name = re.findall('<title>(.+?)</title>', item)[0] name = cleantitle(name) if not query.lower() in name.lower(): raise Exception() url = re.findall('<link>(.+?)</link>', item)[0] try: image = re.findall('<thumbnail>(.+?)</thumbnail>', item)[0] except: image = '0' try: fanart2 = re.findall('<fanart>(.+?)</fanart>', item)[0] except: fanart2 = fanart if content == 'movies': try: title = cleantitle(name).encode('utf-8') data = {'title': title} title, year = re.compile( '(.+?)[(](\d{4})[)]').findall(name)[0] title = cleantitle(title).encode('utf-8') data = {'title': title, 'year': year} except: pass if re.search('[a-zA-Z]', vip): name += ' [COLOR orange]%s[/COLOR]' % vip if 'sublink' in url: addDirectoryItem(name, url, 'subDirectory', image, image, fanart2, '0', content, data, isFolder=True) else: addDirectoryItem(name, url, 'resolveUrl', image, image, fanart2, '0', content, data, isFolder=False) except: pass except: pass control.directory(int(sys.argv[1]), cacheToDisc=True)
def getSources(self, name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date): sourceDict = [] for package, name, is_pkg in pkgutil.walk_packages(__path__): sourceDict.append((name, is_pkg)) sourceDict = [i[0] for i in sourceDict if i[1] == False] content = 'movie' if tvshowtitle == None else 'episode' if content == 'movie': sourceDict = [ i for i in sourceDict if i.endswith(('_mv', '_mv_tv')) ] try: sourceDict = [ (i, control.setting(re.sub('_mv_tv$|_mv$|_tv$', '', i))) for i in sourceDict ] except: sourceDict = [(i, 'true') for i in sourceDict] else: sourceDict = [ i for i in sourceDict if i.endswith(('_tv', '_mv_tv')) ] try: sourceDict = [(i, control.setting( re.sub('_mv_tv$|_mv$|_tv$', '', i) + '_tv')) for i in sourceDict] except: sourceDict = [(i, 'true') for i in sourceDict] threads = [] control.makeFile(control.dataPath) self.sourceFile = control.sourcescacheFile sourceDict = [i[0] for i in sourceDict if i[1] == 'true'] if content == 'movie': title = cleantitle.normalize(title) for source in sourceDict: threads.append( workers.Thread( self.getMovieSource, title, year, imdb, re.sub('_mv_tv$|_mv$|_tv$', '', source), __import__(source, globals(), locals(), [], -1).source())) else: tvshowtitle = cleantitle.normalize(tvshowtitle) season, episode = alterepisode.alterepisode().get( imdb, tmdb, tvdb, tvrage, season, episode, alter, title, date) for source in sourceDict: threads.append( workers.Thread( self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, date, re.sub('_mv_tv$|_mv$|_tv$', '', source), __import__(source, globals(), locals(), [], -1).source())) try: timeout = int(control.setting('sources_timeout_40')) except: timeout = 40 [i.start() for i in threads] control.idle() sourceLabel = [re.sub('_mv_tv$|_mv$|_tv$', '', i) for i in sourceDict] sourceLabel = [re.sub('v\d+$', '', i).upper() for i in sourceLabel] self.progressDialog = control.progressDialog self.progressDialog.create(control.addonInfo('name'), '') self.progressDialog.update(0) string1 = control.lang(30512).encode('utf-8') string2 = control.lang(30513).encode('utf-8') string3 = control.lang(30514).encode('utf-8') for i in range(0, timeout * 2): try: if xbmc.abortRequested == True: return sys.exit() try: info = [ sourceLabel[int(re.sub('[^0-9]', '', str(x.getName()))) - 1] for x in threads if x.is_alive() == True ] except: info = [] if len(info) > 5: info = len(info) self.progressDialog.update( int((100 / float(len(threads))) * len([x for x in threads if x.is_alive() == False])), str('%s: %s %s' % (string1, int(i * 0.5), string2)), str('%s: %s' % (string3, str(info).translate(None, "[]'")))) if self.progressDialog.iscanceled(): break is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(0.5) except: pass self.progressDialog.close() return self.sources
def sourcesDialog(self): try: sources = [{ 'label': '00 | [B]%s[/B]' % control.lang(30509).encode('utf-8').upper() }] + self.sources labels = [i['label'] for i in sources] select = control.selectDialog(labels) if select == 0: return self.sourcesDirect() if select == -1: return 'close://' items = [self.sources[select - 1]] next = [y for x, y in enumerate(self.sources) if x >= select] prev = [y for x, y in enumerate(self.sources) if x < select][::-1] source, quality = items[0]['source'], items[0]['quality'] items = [ i for i in items + next + prev if i['quality'] == quality and i['source'] == source ][:10] items += [ i for i in next + prev if i['quality'] == quality and not i['source'] == source ][:10] self.progressDialog = control.progressDialog self.progressDialog.create(control.addonInfo('name'), '') self.progressDialog.update(0) block = None for i in range(len(items)): try: if self.progressDialog.iscanceled(): break self.progressDialog.update( int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]['url'], items[i]['provider']) w.start() m = '' for x in range(3600): if self.progressDialog.iscanceled(): return self.progressDialog.close() if xbmc.abortRequested == True: return sys.exit() 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 time.sleep(1) for x in range(30): if m == '': break if self.progressDialog.iscanceled(): return self.progressDialog.close() if xbmc.abortRequested == True: return sys.exit() if w.is_alive() == False: break time.sleep(1) if w.is_alive() == True: block = items[i]['source'] if self.url == None: raise Exception() self.selectedSource = items[i]['label'] self.progressDialog.close() return self.url except: pass try: self.progressDialog.close() except: pass except: try: self.progressDialog.close() except: pass
def getSources(self, name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date, proxy_options, provider_options, key, session): try: sourceDict = [] self.getSourcesAlive = True if provider_options != None: myProviders = [] for prov in provider_options: myProviders += [ i for i in self.providersCaller if i['url'].lower() == prov['url'].lower() and str(prov['enabled']) == 'True' ] else: myProviders = self.providersCaller content = 'movie' if tvshowtitle == None else 'show' self.threads[key] = [] self.threadSlots[key] = [] pos = 0 if content == 'movie': log(err='Initializing Search for Movie: %s (%s)' % (title, year)) title = cleantitle.normalize(title) for source in myProviders: try: source_name = 'Unknow source (import error)' source_name = source['name'] if content in source['types']: log(err= 'Queuing Search for Movie: %s (%s) in Provider %s' % (title, year, source_name)) thread_i = workers.Thread(self.getMovieSource, title, year, imdb, proxy_options, key, source_name, source['call']) self.threads[key].append(thread_i) self.threadSlots[key].append({ 'thread': thread_i, 'status': 'idle', 'pos': pos, 'source': source_name }) pos += 1 else: log(err= 'Content Movie: %s (%s) not supported in Provider %s' % (title, year, source_name)) except Exception as e: log(type='ERROR-CRITICAL', err='getSources %s - %s' % (source_name, e)) else: log(err='Initializing Search for Show: %s' % tvshowtitle) try: tvshowtitle = cleantitle.normalize(tvshowtitle) except: pass try: season, episode = alterepisode.alterepisode().get( imdb, tmdb, tvdb, tvrage, season, episode, alter, title, date) except: pass for source in myProviders: try: source_name = 'Unknow source (import error)' source_name = source['name'] if content in source['types']: log(err= 'Queuing Search for Show: %s S%sE%s in Provider %s' % (tvshowtitle, season, episode, source_name)) thread_i = workers.Thread( self.getEpisodeSource, title, year, imdb, tvdb, season, episode, tvshowtitle, date, proxy_options, key, source_name, source['call']) self.threads[key].append(thread_i) self.threadSlots[key].append({ 'thread': thread_i, 'status': 'idle', 'pos': pos, 'source': source_name }) pos += 1 else: log(err= 'Content Show: %s S%sE%s not supported in Provider %s' % (tvshowtitle, season, episode, source_name)) except Exception as e: log(type='ERROR-CRITICAL', err='getSources %s - %s' % (source_name, e)) thread_ex = workers.Thread(self.executeThreads, key) thread_ex.start() self.executeThreadsStatus(key, thread_ex) self.getSourcesAlive = False return self.sources except Exception as e: log(type='ERROR-CRITICAL', err='getSources - %s' % e) return self.sources
def get_sources(self, url, hosthdDict, hostDict, locDict): return try: self.sources = [] mylinks = [] if url == None: return self.sources result = '' links = [self.link_1, self.link_2, self.link_3] for base_link in links: result = client.source(urlparse.urljoin(base_link, url), headers=self.headers) #control.log('### %s' % result) if 'original-title' in str(result): break links = client.parseDOM(result, 'tr', attrs={'id': 'pt.+?'}) for i in links: #control.log('### %s' % i) try: lang = re.compile( '<img src=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>]').findall( i)[1] if not 'English' in lang: raise Exception() host = re.compile( '<img src=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>]').findall( i)[0] host = host.split('/')[-1] host = host.split('.')[-3] host = host.strip().lower() host = client.replaceHTMLCodes(host) host = host.encode('utf-8') if '>Cam<' in i or '>TS<' in i: quality = 'CAM' elif '>HD<' in i and host in hosthdDict: quality = 'HD' else: quality = 'SD' #if quality == 'HD' and not host in hosthdDict: raise Exception() #if quality == 'SD' and not host in hostDict: raise Exception() if '>3D<' in i: info = '3D' else: info = '' #control.log('### host:%s q:%s' % (host,quality)) url = re.compile( 'href=[\'|\"|\s|\<]*(.+?)[\'|\"|\s|\>]').findall(i)[0] url = client.replaceHTMLCodes(url) try: url = urlparse.parse_qs( urlparse.urlparse(url).query)['u'][0] except: pass if url.startswith('http'): url = urlparse.urlparse(url).path if not url.startswith('http'): url = urlparse.urljoin(self.base_link, url) url = url.encode('utf-8') #control.log('######## IWATCH LINK url:%s host:%s q:%s' % (url,host,quality)) mylinks.append({ 'source': host, 'quality': quality, 'url': url }) except: pass threads = [] for i in mylinks: threads.append(workers.Thread(self.check, i)) [i.start() for i in threads] for i in range(0, 10 * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(1) return self.sources except: return self.sources
def playItem(self, content, name, imdb, tvdb, source): try: next = [] prev = [] for i in range(1, 1000000): try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) u = json.loads( dict(urlparse.parse_qsl(u.replace('?', '')))['source'])[0] next.append(u) except: break for i in range(-1000000, 0)[::-1]: try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) u = json.loads( dict(urlparse.parse_qsl(u.replace('?', '')))['source'])[0] prev.append(u) except: break items = json.loads(source) source, quality = items[0]['source'], items[0]['quality'] items = [ i for i in items + next + prev if i['quality'] == quality and i['source'] == source ][:15] items += [ i for i in next + prev if i['quality'] == quality and not i['source'] == source ][:35] block = None for i in items: try: if i['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, i['url'], i['provider']) w.start() time.sleep(20) if w.is_alive() == True: block = i['source'] if self.url == None: raise Exception() if control.setting('playback_info') == 'true': control.infoDialog(i['label'], heading=name) from resources.lib.libraries.player import player player().run(content, name, self.url, imdb, tvdb) return self.url except: pass raise Exception() except: control.infoDialog(control.lang(30501).encode('utf-8')) pass
def doInit(self): resolvers.init() proxies.init() self.sourcesDictionary() workers.Thread(self.initProviders())
def get_sources(self, url, hosthdDict, hostDict, locDict): try: self.sources = [] if url == None: return self.sources query = url.replace('\'', '').replace('.', ' ') query = re.sub('\s+', ' ', query) query = self.base_link + self.search_link % urllib.quote_plus( query) result = client.source(query) result = client.parseDOM(result, 'table', attrs={'class': 'posts_table'}) title, hdlr = re.compile('(.+?) (S\d*E\d*)$').findall(url)[0] title = cleantitle.tv(title) hdlr = [hdlr] links = [] for i in result: try: name = client.parseDOM(i, 'a')[-1] name = client.replaceHTMLCodes(name) url = client.parseDOM(i, 'a', ret='href')[-1] url = client.replaceHTMLCodes(url) url = url.encode('utf-8') t = re.sub( '(\.|\(|\[|\s)(\d{4}|S\d*E\d*|3D)(\.|\)|\]|\s)(.+)', '', name) t = cleantitle.tv(t) if not t == title: raise Exception() y = re.compile('[\.|\(|\[|\s](S\d*E\d*)[\.|\)|\]|\s]' ).findall(name)[-1] if not any(x == y for x in hdlr): raise Exception() fmt = re.sub('(.+)(\.|\(|\[|\s)(S\d*E\d*)(\.|\)|\]|\s)', '', name) fmt = re.split('\.|\(|\)|\[|\]|\s|\-', fmt) fmt = [x.lower() for x in fmt] if not '720p' in fmt: raise Exception() info = '' size = client.parseDOM(i, 'td') size = [x for x in size if x.endswith((' MB', ' GB'))] if len(size) > 0: size = size[-1] if size.endswith(' GB'): div = 1 else: div = 1024 size = float(re.sub('[^0-9|/.|/,]', '', size)) / div info += '%.2f GB' % size links.append({'url': url, 'info': info}) except: pass threads = [] for i in links[::-1][:2]: threads.append(workers.Thread(self.check, i)) [i.start() for i in threads] for i in range(0, 30 * 2): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(0.5) return self.sources except: return self.sources
def playItem(self, content, name, year, imdb, tvdb, source): try: control.resolve(int(sys.argv[1]), True, control.item(path='')) control.execute('Dialog.Close(okdialog)') next = [] prev = [] total = [] meta = None for i in range(1, 10000): 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('?', ''))) if 'meta' in u: meta = u['meta'] u = json.loads(u['source'])[0] next.append(u) except: break for i in range(-10000, 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('?', ''))) if 'meta' in u: meta = u['meta'] u = json.loads(u['source'])[0] prev.append(u) except: break items = json.loads(source) source, quality = items[0]['source'], items[0]['quality'] items = [ i for i in items + next + prev if i['quality'] == quality and i['source'] == source ][:10] items += [ i for i in next + prev if i['quality'] == quality and not i['source'] == source ][:10] self.progressDialog = control.progressDialog self.progressDialog.create(control.addonInfo('name'), '') self.progressDialog.update(0) block = None for i in range(len(items)): try: self.progressDialog.update( int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]['url'], items[i]['provider']) w.start() m = '' for x in range(3600): if self.progressDialog.iscanceled(): return self.progressDialog.close() if xbmc.abortRequested == True: return sys.exit() 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 time.sleep(1) for x in range(30): if m == '': break if self.progressDialog.iscanceled(): return self.progressDialog.close() if xbmc.abortRequested == True: return sys.exit() if w.is_alive() == False: break time.sleep(1) if w.is_alive() == True: block = items[i]['source'] if self.url == None: raise Exception() try: self.progressDialog.close() except: pass control.sleep(200) if control.setting('playback_info') == 'true': control.infoDialog(items[i]['label'], heading=name) from resources.lib.libraries.player import player player().run(content, name, self.url, year, imdb, tvdb, meta) return self.url except: pass try: self.progressDialog.close() except: pass raise Exception() except: control.infoDialog(control.lang(30501).encode('utf-8')) pass
def get_sources(self, url, hosthdDict, hostDict, locDict): try: self.sources = [] sources = [] mylinks = [] mysources = [] if url == None: return sources data = os.path.join(control.dataPath, 'oneclick1.db') download = True try: download = abs( datetime.datetime.fromtimestamp(os.path.getmtime(data)) - (datetime.datetime.now())) > datetime.timedelta(days=7) except: pass if download == True: result = client.request(base64.b64decode(self.data_link)) print(len(result)) control.log(">>>>>>>>>>>>>>> ONEC Downloading") zip = zipfile.ZipFile(StringIO.StringIO(result)) zip.extractall(control.dataPath) zip.close() dbcon = database.connect(data) dbcur = dbcon.cursor() control.log(">>>>>>>>>>>>>>> ONEC content ") content = re.compile('(.+?)\sS\d*E\d*$').findall(url) control.log(">>>>>>>>>>>>>>> ONEC aaa content %s" % len(content)) if len(content) == 0: title, year = re.compile('(.+?) (\d{4})$').findall(url)[0] title = cleantitle.movie(title) dbcur.execute("SELECT * FROM movies WHERE title like '%" + title + "%' and title like '%" + year + "%'") result = dbcur.fetchall() for i in result: print(i[0]) mysources.append(i[0]) else: control.log(">>>>>>>>>>>>>>> ONEC %ELSE ") tvshowtitle, season, episode = re.compile( '(.+?)\sS(\d*)E(\d*)$').findall(url)[0] tvshowtitle = cleantitle.movie(tvshowtitle) myses = 's%se%s' % (season, episode) control.log(">>>>>>>>>>>>>>> ONEC %s season |%s|" % (tvshowtitle, myses)) mysql = "SELECT * FROM movies WHERE title like '%" + tvshowtitle + "%' and title like '%" + myses + "%'" #mysql = "SELECT * FROM movies WHERE title like '%" + tvshowtitle + "%'" control.log(">>>>>>>>>>>>>>> ONEC SQL |%s|" % (mysql)) dbcur.execute(mysql) result = dbcur.fetchall() for i in result: mysources.append(i[0]) control.log(">>>>>>>>>>>>>>> ONEC result %s" % (i[0])) mylinks = [] for myurl in mysources: result = client.request(myurl, mobile=True) mytitle = re.compile('<title>(.*?)</title>', re.DOTALL).findall(result)[0] if any(word in mytitle.lower() for word in [ 'camrip', 'tsrip', 'hdcam', 'hdts', 'dvdcam', 'dvdts', 'cam', 'ts' ]): quality = 'CAM' elif '1080' in mytitle: quality = '1080p' elif '720p' in mytitle: quality = 'HD' else: quality = 'SD' links = client.parseDOM(result, 'a', attrs={'rel': 'nofollow'}) links = [i for i in links if i.startswith('http')] for a in links: control.log(">>>>>>>>>>>>>>> ONE CHECK %s" % (a)) mylinks.append([a, quality]) threads = [] for i in mylinks: threads.append(workers.Thread(self.check, i)) [i.start() for i in threads] for i in range(0, 10 * 4): is_alive = [x.is_alive() for x in threads] if all(x == False for x in is_alive): break time.sleep(2) return self.sources except: return self.sources
def playItem(self, content, name, imdb, tvdb, source): try: next = [] prev = [] total = [] for i in range(1, 10000): try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = json.loads( dict(urlparse.parse_qsl(u.replace('?', '')))['source'])[0] next.append(u) except: break for i in range(-10000, 0)[::-1]: try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = json.loads( dict(urlparse.parse_qsl(u.replace('?', '')))['source'])[0] prev.append(u) except: break items = json.loads(source) source, quality = items[0]['source'], items[0]['quality'] items = [ i for i in items + next + prev if i['quality'] == quality and i['source'] == source ][:10] items += [ i for i in next + prev if i['quality'] == quality and not i['source'] == source ][:10] import xbmc dialog = control.progressDialog dialog.create(control.addonInfo('name'), '') dialog.update(0) block = None for i in range(len(items)): try: dialog.update(int((100 / float(len(items))) * i), str(items[i]['label'])) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]['url'], items[i]['provider']) w.start() for x in range(0, 15 * 2): if dialog.iscanceled(): return dialog.close() if xbmc.abortRequested == True: return sys.exit() 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: dialog.close() except: pass if control.setting('playback_info') == 'true': control.infoDialog(items[i]['label'], heading=name) from resources.lib.libraries.player import player player().run(content, name, self.url, imdb, tvdb) return self.url except: pass try: dialog.close() except: pass raise Exception() except: control.infoDialog(control.lang(30501).encode('utf-8')) pass
def resolve(self, url): try: m3u8 = [ '#EXTM3U', '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",DEFAULT=YES,AUTOSELECT=YES,NAME="Stream 1",URI="{audio_stream}"', '', '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=0,NAME="{stream_name}",AUDIO="audio"', '{video_stream}' ] query = urlparse.parse_qs(url) query = dict([(key, query[key][0]) if query[key] else (key, '') for key in query]) auth = 'http://streamtorrent.tv/api/torrent/%s/%s.m3u8?json=true' % ( query['vid_id'], query['stream_id']) r = client.request(auth) r = json.loads(r) try: url = r['url'] except: url = None if not url == None: def dialog(url): try: self.disableScraper = control.yesnoDialog( 'To watch this video visit from any device', '[COLOR skyblue]%s[/COLOR]' % url, '', 'Torba', 'Cancel', 'Settings') except: pass workers.Thread(dialog, url).start() control.sleep(3000) for i in range(100): try: if not control.condVisibility( 'Window.IsActive(yesnoDialog)'): break r = client.request(auth) r = json.loads(r) try: url = r['url'] except: url = None if url == None: break workers.Thread(dialog, url).start() control.sleep(3000) except: pass if self.disableScraper: control.openSettings(query='2.0') return '' control.execute('Dialog.Close(yesnoDialog)') if not url == None: return stream_name = '%sp' % (query['height']) video_stream = r[stream_name] if not 'audio' in r: return video_stream audio_stream = r['audio'] content = ('\n'.join(m3u8)).format( **{ 'audio_stream': audio_stream, 'stream_name': stream_name, 'video_stream': video_stream }) path = os.path.join(control.dataPath, 'torbase.m3u8') control.makeFile(control.dataPath) control.deleteFile(path) file = control.openFile(path, 'w') file.write(content) file.close() return path except: return