def get_url(scraper, title, show_year, year, season, episode, imdb, tvdb, type, cache_location, maximum_age, check_url=False, debrid=False): cache_enabled = xbmcaddon.Addon('script.module.universalscrapers' ).getSetting("cache_enabled") == 'true' try: dbcon = database.connect(cache_location) dbcur = dbcon.cursor() try: dbcur.execute("SELECT * FROM version") match = dbcur.fetchone() except: universalscrapers.clear_cache() dbcur.execute("CREATE TABLE version (" "version TEXT)") dbcur.execute("INSERT INTO version Values ('0.5.4')") dbcon.commit() dbcur.execute("CREATE TABLE IF NOT EXISTS rel_src (" "scraper TEXT, " "title Text, show_year TEXT, year TEXT, " "season TEXT, " "episode TEXT, " "imdb_id TEXT, " "urls TEXT, " "added TEXT, " "UNIQUE(scraper, title, year, season, episode)" ");") except: pass if cache_enabled: try: sources = [] dbcur.execute( "SELECT * FROM rel_src WHERE scraper = '%s' AND title = '%s' AND show_year= '%s' AND year = '%s' AND season = '%s' AND episode = '%s'" % (scraper.name, clean_title(title).upper(), show_year, year, season, episode)) match = dbcur.fetchone() t1 = int(re.sub('[^0-9]', '', str(match[8]))) t2 = int(datetime.datetime.now().strftime("%Y%m%d%H%M")) update = abs(t2 - t1) > maximum_age if update == False: sources = json.loads(match[7]) return sources except: pass try: sources = [] if type == "movie": sources = scraper.scrape_movie(title, year, imdb, debrid=debrid) elif type == "episode": sources = scraper.scrape_episode(title, show_year, year, season, episode, imdb, tvdb, debrid=debrid) if sources == None: sources = [] else: if cache_enabled: try: dbcur.execute( "DELETE FROM rel_src WHERE scraper = '%s' AND title = '%s' AND show_year= '%s' AND year = '%s' AND season = '%s' AND episode = '%s'" % (scraper.name, clean_title(title).upper(), show_year, year, season, episode)) dbcur.execute( "INSERT INTO rel_src Values (?, ?, ?, ?, ?, ?, ?, ?, ?)", (scraper.name, clean_title(title).upper(), show_year, year, season, episode, imdb, json.dumps(sources), datetime.datetime.now().strftime("%Y-%m-%d %H:%M") )) dbcon.commit() except: pass if check_url: noresolver = False try: import resolveurl as urlresolver except: try: import urlresolver as urlresolver except: noresolver = True new_sources = [] from common import check_playable for source in sources: if source["direct"]: check = check_playable(source["url"]) if check: new_sources.append(source) elif not noresolver: try: hmf = urlresolver.HostedMediaFile( url=source['url'], include_disabled=False, include_universal=False) if hmf.valid_url(): resolved_url = hmf.resolve() check = check_playable(resolved_url) if check: new_sources.append(source) except: pass else: new_sources.append(source) sources = new_sources return sources except: pass
def get_url(scraper, title, show_year, year, season, episode, imdb, tvdb, type, cache_location, maximum_age, check_url = False, debrid = False): cache_enabled = xbmcaddon.Addon('script.module.universalscrapers').getSetting("cache_enabled") == 'true' try: dbcon = database.connect(cache_location) dbcur = dbcon.cursor() try: dbcur.execute("SELECT * FROM version") match = dbcur.fetchone() except: universalscrapers.clear_cache() dbcur.execute("CREATE TABLE version (""version TEXT)") dbcur.execute("INSERT INTO version Values ('0.5.4')") dbcon.commit() dbcur.execute( "CREATE TABLE IF NOT EXISTS rel_src (""scraper TEXT, ""title Text, show_year TEXT, year TEXT, ""season TEXT, ""episode TEXT, ""imdb_id TEXT, ""urls TEXT, ""added TEXT, ""UNIQUE(scraper, title, year, season, episode)"");") except: pass if cache_enabled: try: sources = [] dbcur.execute( "SELECT * FROM rel_src WHERE scraper = '%s' AND title = '%s' AND show_year= '%s' AND year = '%s' AND season = '%s' AND episode = '%s'" % ( scraper.name, clean_title(title).upper(), show_year, year, season, episode)) match = dbcur.fetchone() t1 = int(re.sub('[^0-9]', '', str(match[8]))) t2 = int(datetime.datetime.now().strftime("%Y%m%d%H%M")) update = abs(t2 - t1) > maximum_age if update == False: sources = json.loads(match[7]) return sources except: pass try: sources = [] if type == "movie": sources = scraper.scrape_movie(title, year, imdb, debrid = debrid) elif type == "episode": sources = scraper.scrape_episode(title, show_year, year, season, episode, imdb, tvdb, debrid = debrid) if sources == None: sources = [] else: if cache_enabled: try: dbcur.execute( "DELETE FROM rel_src WHERE scraper = '%s' AND title = '%s' AND show_year= '%s' AND year = '%s' AND season = '%s' AND episode = '%s'" % ( scraper.name, clean_title(title).upper(), show_year, year, season, episode)) dbcur.execute("INSERT INTO rel_src Values (?, ?, ?, ?, ?, ?, ?, ?, ?)", ( scraper.name, clean_title(title).upper(), show_year, year, season, episode, imdb, json.dumps(sources), datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))) dbcon.commit() except: pass if check_url: noresolver = False try: import resolveurl as urlresolver except: try: import urlresolver as urlresolver except: noresolver = True new_sources = [] from common import check_playable for source in sources: if source["direct"]: check = check_playable(source["url"]) if check: new_sources.append(source) elif not noresolver: try: hmf = urlresolver.HostedMediaFile(url=source['url'], include_disabled=False, include_universal=False) if hmf.valid_url(): resolved_url = hmf.resolve() check = check_playable(resolved_url) if check: new_sources.append(source) except: pass else: new_sources.append(source) sources = new_sources return sources except: pass