def root(self): self.addDirectoryItem(30860, 'movieLangNavigator', 'movies.png', 'DefaultMovies.png') self.addDirectoryItem(30861, 'desiTVNavigator', 'tv-vod.png', 'DefaultMovies.png') self.addDirectoryItem(90116, 'tools', 'settings.png', 'DefaultMovies.png') self.addDirectoryItem(90117, 'clearCache', 'clearcache.png', 'DefaultMovies.png') self.addDirectoryItem(30864, 'changelog', 'changelog.png', 'DefaultMovies.png') cache.get(changelog.get, 600000000, control.addonInfo('version'), table='changelog') cache.get(self.donation, 336, control.addonInfo('version'), table='changelog') #cache.get(control.resetSettings, 600000000, 'true', control.addonInfo('version'), table='changelog') cache.get(analytics.sendAnalytics, 600000000, ("Installed-%s" % control.addonInfo('version')), table='changelog') self.endDirectory()
def __init__(self): self.resolverList = self.getResolverList() self.hostDict = self.getHostDict() self.hostprDict = self.getHostPrDict() self.srcs = [] self.debridDict = debrid.debridDict() self.itemProperty = "%s.itemProperty" % control.addonInfo('name') self.metaProperty = "%s.itemMeta" % control.addonInfo('name')
def sourcesDirect(self, items): u = None self.progressDialog = control.progressDialog self.progressDialog.create(control.addonInfo('name'), '') self.progressDialog.update(0) self.isRegistered() 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 xbmc.abortRequested == True: return sys.exit() url = self.sourcesResolve(items[i]) if url == None: raise Exception() if u == None: u = url self.selectedSource = items[i]['label'] self.progressDialog.close() return url except: pass try: self.progressDialog.close() except: pass return u
def _inside(self, num): if num == -1: self._inside_root(select=self.insideIndex) return with self.lock: source, links = self.items[num] if len(links) == 1: self.selection = links[0] self.close() return self.list.reset() for item in links: listitem = control.item(item['label']) #listitem.setProperty("Path", item['path']) try: #pluginid = item['path'].split("/")[2] icon = control.addonInfo('icon') listitem.setIconImage(icon) except: pass self.list.addItem(listitem) self.insideIndex = num
def __init__(self): control_background = control.controlImage(0, 0, 1280, 720, control.addonInfo('fanart')) self.addControl(control_background) fanart = control.infoLabel('ListItem.Property(Fanart_Image)') if fanart and fanart != "Fanart_Image": control_fanart = control.controlImage(0, 0, 1280, 720, fanart) self.addControl(control_fanart)
def _update_settings_xml(): settings_location = os.path.join(control.addonInfo('path'), 'resources', 'settings.xml') try: os.makedirs(os.path.dirname(settings_location)) except OSError: pass new_xml = [ '<?xml version="1.0" encoding="utf-8" standalone="yes"?>', '<settings>', '\t <category label = "General">', '\t\t<setting id="cache_enabled" ' 'type="bool" label="Enable Caching" default="true"/>', '\t\t<setting id="debug" ' 'type="bool" label="Debug" default="true"/>', '\t</category>', '\t<category label="Scrapers 1">' ] scrapers = sorted(relevant_scrapers(include_disabled=True), key=lambda x: x.name.lower()) category_number = 2 category_scraper_number = 0 for scraper in scrapers: if category_scraper_number > 50: new_xml.append('\t</category>') new_xml.append('\t<category label="Scrapers %s">' % (category_number)) category_number += 1 category_scraper_number = 0 new_xml.append('\t\t<setting label="%s" type="lsep"/>' % (scraper.name)) scraper_xml = scraper.get_settings_xml() new_xml += ['\t\t' + line for line in scraper_xml] category_scraper_number += len(scraper_xml) + 1 new_xml.append('\t</category>') new_xml.append('</settings>') try: with open(settings_location, 'r') as f: old_xml = f.read() except: old_xml = '' new_xml = '\n'.join(new_xml) if old_xml != new_xml: try: with open(settings_location, 'w') as f: f.write(new_xml) except: pass
def select_ext(title, populator, tasks_count, sort_function=None): addonPath = control.addonInfo('path').decode('utf-8') dlg = SelectorDialog("DialogSelect.xml", addonPath, title=title, populator=populator, steps=tasks_count, sort_function=sort_function) with ExtendedDialogHacks(): dlg.doModal() selection = dlg.get_selection() items = dlg.items del dlg return (selection, items)
def main(): test_type = control.dialog.select("Choose type of test", ["Test List", "Profile List", "Profile Scrapers"]) basepath = xbmc.translatePath(control.addonInfo("profile")) control.makeFile(basepath) if test_type == 0: test() elif test_type == 1: import cProfile cProfile.run('test()', os.path.join(basepath, 'profile_list.profile')) elif test_type == 2: import cProfile cProfile.run('profile_scrapers("movie")', os.path.join(basepath, 'profile_scrapers_movies.profile')) cProfile.run('profile_scrapers("episode")', os.path.join(basepath, 'profile_scrapers_episodes.profile')) testManual()
def _inside_root(self, select=-1): with self.lock: self.list.reset() for source, links in self.items: if len(links) > 1: source += " >>" listitem = control.item(source) try: #icon = xbmcaddon.Addon(id=links[0]['path'].split("/")[2]).getAddonInfo('icon') icon = control.addonInfo('icon') listitem.setIconImage(icon) except: pass self.list.addItem(listitem) if select >= 0: self.list.selectItem(select) self.insideIndex = -1
def sourcesDialog(self, items): try: labels = [i['label'] for i in items] select = control.selectDialog(labels) if select == -1: return 'close://' self.isRegistered() 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 progressDialog.create(control.addonInfo('name'), '') 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 Exception as e: logger.error(e.message) try: progressDialog.close() except: pass
def getSources(self, name, title, year, imdb, tvdb, season, episode, tvshowtitle, date, meta=None): content = 'movie' if tvshowtitle == None else 'episode' control.makeFile(control.dataPath) self.sourceFile = control.sourcescacheFile logger.debug('Content [%s]' % content, __name__) try: timeout = int(control.setting('sources_timeout_40')) except: timeout = 40 try: allowDebrid = bool(control.setting('allow_debrid')) except: allowDebrid = False import desiscrapers control.init('script.module.desiscrapers') totalScrapers = len( desiscrapers.relevant_scrapers(scraper_type=content)) if content == 'movie': title = cleantitle.normalize(title) links_scraper = desiscrapers.scrape_movie( title, year, imdb, timeout=timeout, enable_debrid=allowDebrid) elif content == 'episode': tvshowtitle = cleantitle.normalize(tvshowtitle) imdb = json.loads(meta)['url'] show_year = year tvshowtitle = tvshowtitle.replace('Season', '').replace('season', '') links_scraper = desiscrapers.scrape_episode( tvshowtitle, show_year, year, season, episode, imdb, tvdb, timeout=timeout, enable_debrid=allowDebrid) control.init('plugin.video.swadesi') control.idle() self.progressDialog = control.progressDialog self.progressDialog.create(control.addonInfo('name'), '') self.progressDialog.update(0) thread = workers.Thread(self.get_desi_sources, links_scraper, totalScrapers) thread.start() for i in range(0, timeout * 4): try: if xbmc.abortRequested: return sys.exit() try: if self.progressDialog.iscanceled(): break except: pass if not thread.is_alive(): break time.sleep(0.5) except: pass self.progressDialog.close() for i in range(0, len(self.srcs)): self.srcs[i].update({'content': content}) return self.srcs
def playItem(self, content, title, source): try: self.isRegistered() control.resolve(syshandle, True, control.item(path='')) control.execute('Dialog.Close(okdialog)') next = [] prev = [] total = [] meta = control.window.getProperty(self.metaProperty) #meta = self.metaProperty meta = json.loads(meta) year = meta['year'] if 'year' in meta else None imdb = meta['imdb'] if 'imdb' in meta else None tvdb = meta['tvdb'] if 'tvdb' in meta else 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) items = [i for i in items + next + prev][:40] 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]) 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.0) for x in range(3600): 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.0) 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']) player().run(content, title, self.url, year, imdb, tvdb, meta) return self.url except Exception as e: logger.error(e, __name__) pass try: self.progressDialog.close() except: pass raise Exception() except Exception as e: logger.error(e.message) control.infoDialog(control.lang(30501).encode('utf-8')) pass
def test(): global movies, shows try: test_movies = [] test_episodes = [] profile_path = xbmc.translatePath(control.addonInfo('profile')).decode('utf-8') test_file = xbmcvfs.File(os.path.join(profile_path, "testings.xml")) xml = BeautifulStoneSoup(test_file.read()) test_file.close() items = xml.findAll("item") for item in items: try: content = item.find("content") if content: if "movie" in content.text: meta = item.find("meta") test_movies.append({ 'title': meta.find("title").text, 'imdb': meta.find("imdb").text, 'year': meta.find("year").text, }) elif "episode" in content.text: meta = item.find("meta") test_episodes.append({ 'title': meta.find("tvshowtitle").text, 'show_year': int(meta.find("premiered").text[0:4]), 'year': meta.find("year").text, 'season': meta.find("season").text, 'episode': meta.find("season").text, 'imdb': meta.find("imdb").text, }) except: pass movies = test_movies shows = test_episodes except: pass dialog = xbmcgui.Dialog() pDialog = xbmcgui.DialogProgress() if dialog.yesno("Desiscrapers Testing Mode", 'Clear cache?'): desiscrapers.clear_cache() try: dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() except: dialog.ok("Desiscrapers Testing Mode", 'Error connecting to db') sys.exit() num_movies = len(movies) if num_movies > 0: pDialog.create('Desiscrapers Testing mode active', 'please wait') index = 0 for movie in movies: index += 1 title = movie['title'] year = movie['year'] imdb = movie['imdb'] if pDialog.iscanceled(): pDialog.close() break pDialog.update((index / num_movies) * 100, "Scraping movie {} of {}".format(index, num_movies), title) links_scraper = desiscrapers.scrape_movie(title, year, imdb) links_scraper = links_scraper() for scraper_links in links_scraper: if pDialog.iscanceled(): break if scraper_links: logger.debug(scraper_links, __name__) random.shuffle(scraper_links) pDialog.close() dbcur.execute("SELECT COUNT(DISTINCT(scraper)) FROM rel_src where episode = ''") match = dbcur.fetchone() num_movie_scrapers = match[0] logger.debug('num_movie_scrapers %s' % num_movie_scrapers, __name__) dbcur.execute("SELECT scraper, count(distinct(urls)) FROM rel_src where episode = '' group by scraper") matches = dbcur.fetchall() failed = [] for match in matches: if int(match[1]) <= 1: failed.append(match[0]) if len(failed) > 0: failedstring = "Failed: {}".format(len(failed)) for fail in failed: failedstring += "\n - {}".format(str(fail)) else: failedstring = "Failed: {}".format(len(failed)) logger.debug('failedString %s' % failedstring, __name__) dbcur.execute("SELECT title, count(distinct(urls)) FROM rel_src where episode = '' group by title") matches = dbcur.fetchall() failed_movies = [] for match in matches: if int(match[1]) <= 1: if int(match[1]) == 1: dbcur.execute( "SELECT scraper, urls FROM rel_src where episode == '' and title == '{}' group by scraper".format( match[0])) new_matches = dbcur.fetchall() found = False for new_match in new_matches: if new_match[1] == "[]": continue else: found = True if not found: failed_movies.append(match[0]) else: failed_movies.append(match[0]) if len(failed_movies) > 0: failed_movie_string = "Failed movies: {}".format(len(failed_movies)) for fail in failed_movies: for movie in movies: if cleantitle.get(movie['title']).upper() == str(fail): failed_movie_string += "\n - {}".format(movie["title"]) else: failed_movie_string = "" num_shows = len(shows) if num_shows > 0: pDialog.create('Desiscrapers Testing mode active', 'please wait') index = 0 for show in shows: index += 1 title = show['title'] show_year = show['show_year'] year = show['year'] season = show['season'] episode = show['episode'] imdb = show['imdb'] tvdb = show.get('tvdb', '') if pDialog.iscanceled(): pDialog.close() break pDialog.update((index / num_shows) * 100, "Scraping show {} of {}".format(index, num_shows), title) links_scraper = desiscrapers.scrape_episode(title, show_year, year, season, episode, imdb, tvdb) links_scraper = links_scraper() for scraper_links in links_scraper: if pDialog.iscanceled(): break if scraper_links: random.shuffle(scraper_links) pDialog.close() dbcur.execute("SELECT COUNT(DISTINCT(scraper)) FROM rel_src where episode != ''") match = dbcur.fetchone() num_show_scrapers = match[0] dbcur.execute("SELECT scraper, count(distinct(urls)) FROM rel_src where episode != '' group by scraper") matches = dbcur.fetchall() failed = [] for match in matches: if int(match[1]) <= 1: if int(match[1]) == 1: dbcur.execute( "SELECT scraper, urls FROM rel_src where episode != '' and scraper == '{}' group by scraper".format( match[0])) match = dbcur.fetchone() if match[1] == "[]": failed.append(match[0]) else: failed.append(match[0]) if len(failed) > 0: show_scraper_failedstring = "Failed: {}".format(len(failed)) for fail in failed: show_scraper_failedstring += "\n - {}".format(str(fail)) else: show_scraper_failedstring = "" dbcur.execute("SELECT title, count(distinct(urls)) FROM rel_src where episode != '' group by title") matches = dbcur.fetchall() failed_shows = [] for match in matches: if int(match[1]) <= 1: if int(match[1]) == 1: dbcur.execute( "SELECT scraper, urls FROM rel_src where episode != '' and title == '{}' group by scraper".format( match[0])) new_matches = dbcur.fetchall() found = False for new_match in new_matches: if new_match[1] == "[]": continue else: found = True if not found: failed_shows.append(match[0]) else: failed_shows.append(match[0]) if len(failed_shows) > 0: failed_show_string = "Failed shows: {}".format(len(failed_shows)) for fail in failed_shows: for show in shows: if cleantitle.get(show['title']).upper() == str(fail): failed_show_string += "\n - {} S{}-E{}".format(show["title"], show["season"], show["episode"]) else: failed_show_string = "" resultstring = 'Results:\n' if num_movies > 0: resultstring = resultstring + \ ' Movie Scrapers: {}\n' \ ' {}\n' \ ' {}\n'.format(num_movie_scrapers, failedstring, failed_movie_string) if num_shows > 0: resultstring = resultstring + \ ' Episode Scrapers: {}\n' \ ' {}\n' \ ' {}\n'.format(num_show_scrapers, show_scraper_failedstring, failed_show_string) dialog.textviewer("Desiscrapers Testing Mode", resultstring)