def get_user_agent(self): if self.user_agent: return self.user_agent user_agent = kodi.get_property('user_agent') try: agent_refresh_time = int(kodi.get_property('agent_refresh_time')) except: agent_refresh_time = 0 if not user_agent or agent_refresh_time < (time.time() - (7 * 24 * 60 * 60)): user_agent = self.generate_user_agent() kodi.set_property('user_agent', user_agent) kodi.set_property('agent_refresh_time', str(int(time.time()))) return user_agent
def authorize(self): token = kodi.get_property("TVDB_API_token") if not token: response = self.request('/login', data={"apikey": TVDB_KEY}) if 'token' in response: token = response['token'] kodi.set_property("TVDB_API_token", token) else: response.raise_for_status() self.headers["Authorization"] = "Bearer %s" % token
def search_filter(): from commoncore.core import format_color options = display =['None', 'Repository', 'Feed', 'Music Plugin', 'Video Plugin', 'Script'] filter = kodi.get_property('search.filter') if filter in options: index = options.index(filter) display[index] = format_color(display[index], 'yellow') else: display[0] = format_color(display[0], 'yellow') c = kodi.dialog_select("Filter Results by:", display) if c is not False: if c is 0: kodi.set_property('search.filter', '') else: kodi.set_property('search.filter', options[c])
def resolve_url(self, raw_url): resolved_url = '' kodi.open_busy_dialog() hash = self.get_hash_from_magnet(raw_url) if not hash: hash = self.get_hash_from_url(raw_url) if hash: kodi.set_property('Playback.Hash', hash) else: kodi.clear_property('Playback.Hash') attempt = 0 attempts = 5 try: response = premiumize.create_transfer(raw_url) id = response['id'] except: premiumize.clear_transfers() response = premiumize.create_transfer(raw_url) id = response['id'] try: while attempt < attempts: folder_id = False file_id = False target_folder_id = False kodi.log("Resolve Attempt %s" % attempt) temp = premiumize.list_transfers() for t in temp['transfers']: if t['id'] == id and t['status'] == 'finished': target_folder_id = t['target_folder_id'] folder_id = t['folder_id'] file_id = t['file_id'] break if folder_id: response = premiumize.list_folder(folder_id) resolved_url = premiumize.get_folder_stream(response) break if target_folder_id: response = premiumize.list_folder(target_folder_id) resolved_url = premiumize.get_folder_stream(response) break attempt += 1 kodi.sleep(150) except: kodi.close_busy_dialog() kodi.close_busy_dialog() return resolved_url
def install_scraper(scraper): DB.connect() scraper_id = DB.query("SELECT scraper_id FROM scrapers WHERE service=?", [scraper.service]) if not scraper_id: kodi.set_property("new_scraper", "true", 'script.module.scrapecore') settings_definition = '' for s in scraper.settings_definition: settings_definition += "\n\t\t" + s settings_definition = settings_definition.replace( "{NAME}", scraper.name) settings_definition = settings_definition.replace( "{SERVICE}", scraper.service) DB.execute( "INSERT INTO scrapers(service, name, settings, enabled) VALUES(?,?,?,1)", [scraper.service, scraper.name, settings_definition]) DB.commit()
def realdebrid_resolver(raw_url): resolved_url = '' if kodi.get_setting('realdebrid_enable', ADDON_ID) != 'true': return resolved_url response = realdebrid.add_torrent(raw_url) try: torrent_id = response['id'] info = realdebrid.get_torrent_info(torrent_id) file_id = realdebrid.get_stream_file(info['files']) if not file_id: return realdebrid.select_torrent_files(torrent_id, file_id) kodi.sleep(500) info = realdebrid.get_torrent_info(torrent_id) raw_url = info['links'][0] kodi.set_property('Playback.Resolver', 'realdebrid') kodi.set_property('Playback.ID', torrent_id) resolved_url = realdebrid.resolve_url(raw_url) except: pass return resolved_url
def premiumize_resolver(raw_url): resolved_url = '' if kodi.get_setting('premiumize_enable', ADDON_ID) != 'true': return resolved_url attempt = 0 attempts = 5 try: response = premiumize.create_transfer(raw_url) id = response['id'] except: premiumize.clear_transfers() response = premiumize.create_transfer(raw_url) id = response['id'] try: while attempt < attempts: folder_id = False file_id = False target_folder_id = False kodi.log("Resolve Attempt %s" % attempt) temp = premiumize.list_transfers() for t in temp['transfers']: if t['id'] == id and t['status'] == 'finished': if 'target_folder_id' in t: target_folder_id = t['target_folder_id'] if 'folder_id' in t: folder_id = t['folder_id'] if 'file_id' in t: file_id = t['file_id'] break if file_id: response = premiumize.item_details(file_id) resolved_url = response['stream_link'] kodi.set_property('Playback.Resolver', 'premiumize') kodi.set_property('Playback.ID', file_id) return resolved_url if folder_id: response = premiumize.list_folder(folder_id) resolved_url = premiumize.get_folder_stream(response) kodi.set_property('Playback.Resolver', 'premiumize') kodi.set_property('Playback.ID', folder_id) return resolved_url if target_folder_id: response = premiumize.list_folder(target_folder_id) resolved_url = premiumize.get_folder_stream(response) kodi.set_property('Playback.Resolver', 'premiumize') kodi.set_property('Playback.ID', target_folder_id) return resolved_url attempt += 1 kodi.sleep(150) except: pass return resolved_url
def resolve_url(self, raw_url): from commoncore.dispatcher import WeightedDispatcher resolved_url = '' hash = self.get_hash(raw_url) kodi.set_property('Playback.Hash', hash) dispatcher = WeightedDispatcher() @dispatcher.register(kodi.get_setting('premiumize_priority', ADDON_ID), [raw_url]) def premiumize_resolver(raw_url): resolved_url = '' if kodi.get_setting('premiumize_enable', ADDON_ID) != 'true': return resolved_url attempt = 0 attempts = 5 try: response = premiumize.create_transfer(raw_url) id = response['id'] except: premiumize.clear_transfers() response = premiumize.create_transfer(raw_url) id = response['id'] try: while attempt < attempts: folder_id = False file_id = False target_folder_id = False kodi.log("Resolve Attempt %s" % attempt) temp = premiumize.list_transfers() for t in temp['transfers']: if t['id'] == id and t['status'] == 'finished': if 'target_folder_id' in t: target_folder_id = t['target_folder_id'] if 'folder_id' in t: folder_id = t['folder_id'] if 'file_id' in t: file_id = t['file_id'] break if file_id: response = premiumize.item_details(file_id) resolved_url = response['stream_link'] kodi.set_property('Playback.Resolver', 'premiumize') kodi.set_property('Playback.ID', file_id) return resolved_url if folder_id: response = premiumize.list_folder(folder_id) resolved_url = premiumize.get_folder_stream(response) kodi.set_property('Playback.Resolver', 'premiumize') kodi.set_property('Playback.ID', folder_id) return resolved_url if target_folder_id: response = premiumize.list_folder(target_folder_id) resolved_url = premiumize.get_folder_stream(response) kodi.set_property('Playback.Resolver', 'premiumize') kodi.set_property('Playback.ID', target_folder_id) return resolved_url attempt += 1 kodi.sleep(150) except: pass return resolved_url @dispatcher.register(kodi.get_setting('realdebrid_priority', ADDON_ID), [raw_url]) def realdebrid_resolver(raw_url): resolved_url = '' if kodi.get_setting('realdebrid_enable', ADDON_ID) != 'true': return resolved_url response = realdebrid.add_torrent(raw_url) try: torrent_id = response['id'] info = realdebrid.get_torrent_info(torrent_id) file_id = realdebrid.get_stream_file(info['files']) if not file_id: return realdebrid.select_torrent_files(torrent_id, file_id) kodi.sleep(500) info = realdebrid.get_torrent_info(torrent_id) raw_url = info['links'][0] kodi.set_property('Playback.Resolver', 'realdebrid') kodi.set_property('Playback.ID', torrent_id) resolved_url = realdebrid.resolve_url(raw_url) except: pass return resolved_url kodi.open_busy_dialog() try: resolved_url = dispatcher.run() except Exception, e: kodi.log(e) kodi.close_busy_dialog()
CACHE_PATH = kodi.vfs.join("special://home", "userdata/addon_data/script.module.scrapecore/cache") if not kodi.vfs.exists(CACHE_PATH): kodi.vfs.mkdir(CACHE_PATH) enabled_scrapers = 0 result_count = 0 active_scrapers = [] supported_scrapers = [] _active_scrapers = [] search_results = [] PB = ProgressBar() class ScraperCoreException(Exception): pass """ First get a list of scraper resource modules """ kodi.set_property("new_scraper", "false", 'script.module.scrapecore') available = scrapecore.get_installed_resources() """ Load scrapers from each module serially """ for mod in available: path = kodi.vfs.join(mod['path'], 'scrapers') sys.path.append(path) """ Directory list the resource module """ for filename in sorted(os.listdir(path)): """ Filter out some stuff """ if not re.search('(__)|(common\.py)|(example\.py)|(all\.py)', filename) and re.search('py$', filename): name = filename[0:len(filename)-3] scraper_path = kodi.vfs.join(path, filename) """ Now read the scraper code and execute it """ code = kodi.vfs.read_file(scraper_path) if code: