def get(imdb_id): from stream.caching import shelf with shelf("com.imdb.%s" % imdb_id) as movie: if not movie: try: import urllib2 from stream.utils import url_get_json movie.update( url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={ "api_key": API_KEY, "language": LANG, "append_to_response": "credits" }, headers=HEADERS, with_immunicity=False) or {}) overview = movie.get('overview') if overview == None: movie.update( url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={ "api_key": API_KEY, "language": "en", "append_to_response": "credits" }, headers=HEADERS, with_immunicity=False) or {}) else: pass except urllib2.HTTPError: pass return dict(movie)
def popcorn_index(): import json from stream.utils import url_get with shelf("popcorn.shows") as popcorn_shows: #print popcorn_shows if not popcorn_shows: pages = json.loads( url_get("%sshows" % BASE_URL, headers=HEADERS) ) popcorn_shows['shows'] = [] for page in pages: print "%s%s" % (BASE_URL,page) response = url_get("%s%s" % (BASE_URL,page), headers=HEADERS) if response=="": continue page_shows = json.loads(response) for show in page_shows: popcorn_shows['shows'].append( { "label": show['title'], "icon": show['images']['poster'], "thumbnail": show['images']['poster'], "path": plugin.url_for("popcorn_get_show", show_id=show['_id'] ), "is_playable":False, 'properties': {'fanart_image': show['images']['fanart'] } } ) #print popcorn_shows return popcorn_shows['shows']
def get(imdb_id): from stream.caching import shelf with shelf("com.imdb.%s" % imdb_id) as movie: if not movie: try: import urllib2 from stream.utils import url_get_json movie.update( url_get_json( "%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "language": LANG, "append_to_response": "credits"}, headers=HEADERS, with_immunicity=False, ) or {} ) overview = movie.get("overview") if overview == None: movie.update( url_get_json( "%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "language": "en", "append_to_response": "credits"}, headers=HEADERS, with_immunicity=False, ) or {} ) else: pass except urllib2.HTTPError: pass return dict(movie)
def config(): global _config if not _config: with shelf("stream.immunicity.pac_config", ttl=CACHE) as pac_config: plugin.log.info("Fetching Immunicity PAC file") pac_data = urllib2.urlopen(PAC_URL).read() pac_config["server"] = re.search(r"var proxyserver = '(.*)'", pac_data).group(1) pac_config["domains"] = map(lambda x: x.replace(r"\Z(?ms)", ""), map(fnmatch.translate, re.findall(r"\"(.*?)\",", pac_data))) _config = pac_config return _config
def config(): global _config if not _config: with shelf("stream.immunicity.pac_config", ttl=CACHE) as pac_config: plugin.log.info("Fetching Immunicity PAC file") pac_data = urllib2.urlopen(PAC_URL).read() pac_config["server"] = re.search(r"var proxyserver = '(.*)'", pac_data).group(1) pac_config["domains"] = map( lambda x: x.replace(r"\Z(?ms)", ""), map(fnmatch.translate, re.findall(r"\"(.*?)\",", pac_data))) _config = pac_config return _config
def get(show_id): from stream.caching import shelf with shelf("com.thetvdb.show.%s" % show_id) as show: if not show: import xml.etree.ElementTree as ET from stream.utils import url_get dom = ET.fromstring(url_get(show_url(show_id), headers=HEADERS, with_immunicity=False)) if not len(dom): return meta = dom2dict(dom[0]) meta = split_keys(meta, "actors", "genre", "writer") update_image_urls(meta) show.update(meta) return dict(show)
def get(show_id): from stream.caching import shelf with shelf("com.thetvdb.show.%s" % show_id) as show: if not show: import xml.etree.ElementTree as ET from stream.utils import url_get dom = ET.fromstring( url_get(show_url(show_id), headers=HEADERS, with_immunicity=False)) if not len(dom): return meta = dom2dict(dom[0]) meta = split_keys(meta, "actors", "genre", "writer") update_image_urls(meta) show.update(meta) return dict(show)
def search(name, complete=False): from stream.caching import shelf import hashlib search_hash = hashlib.sha1(name).hexdigest() with shelf("com.thetvdb.search.%s" % search_hash) as show: if not show: import re import xml.etree.ElementTree as ET from stream.utils import url_get dom = ET.fromstring(url_get("%s/api/GetSeries.php" % BASE_URL, params={ "seriesname": name, }, headers=HEADERS, with_immunicity=False)) if not len(dom): return meta = dom2dict(dom[0]) if not complete: return update_image_urls(meta) show.update(get(meta["id"])) return show
def search(name, complete=False): from stream.caching import shelf import hashlib search_hash = hashlib.sha1(name).hexdigest() with shelf("com.thetvdb.search.%s" % search_hash) as show: if not show: import re import xml.etree.ElementTree as ET from stream.utils import url_get dom = ET.fromstring( url_get("%s/api/GetSeries.php" % BASE_URL, params={ "seriesname": name, }, headers=HEADERS, with_immunicity=False)) if not len(dom): return meta = dom2dict(dom[0]) if not complete: return update_image_urls(meta) show.update(get(meta["id"])) return show
def eztv_shows_by_letter(letter): import re import xbmc import xbmcgui from bs4 import BeautifulSoup from contextlib import nested, closing from itertools import izip, groupby from concurrent import futures from stream.scrapers import ungenerate from stream.utils import terminating, url_get, SafeDialogProgress from stream import tvdb with shelf("it.eztv.shows") as eztv_shows: if not eztv_shows: response = url_get("%s/showlist/" % BASE_URL, headers=HEADERS) soup = BeautifulSoup(response, "html5lib") nodes = soup.findAll("a", "thread_link") for node in nodes: show_id, show_named_id = node["href"].split("/")[2:4] show_name = node.text if show_name == "": continue print "#%s %s" , (show_id,show_name) show_first_letter = show_name[0].lower() if re.match("\d+", show_first_letter): show_first_letter = "0-9" eztv_shows.setdefault(show_first_letter, {}).update({ show_id: { "id": show_id, "named_id": show_named_id, "name": node.text, } }) shows_list = sorted(eztv_shows[letter.lower()].values(), key=lambda x: x["name"].lower()) with closing(SafeDialogProgress(delay_close=0)) as dialog: dialog.create(plugin.name) dialog.update(percent=0, line1="Fetching series...", line2="", line3="") state = {"done": 0} def on_serie(future): data = future.result() state["done"] += 1 dialog.update( percent=int(state["done"] * 100.0 / len(shows_list)), line2=data and data["seriesname"] or "", ) with futures.ThreadPoolExecutor(max_workers=5) as pool_tvdb: tvdb_list = [pool_tvdb.submit(tvdb.search, show["name"], True) for show in shows_list] [future.add_done_callback(on_serie) for future in tvdb_list] while not all(job.done() for job in tvdb_list): if dialog.iscanceled(): return xbmc.sleep(100) print shows_list tvdb_list_new = [] for job in tvdb_list: try: result = job.result() print "RESULT: (%s)" % result if result is not None: tvdb_list_new.append(result) except: None tvdb_list = tvdb_list_new #tvdb_list = [job.result() for job in tvdb_list] print tvdb_list for i, (eztv_show, tvdb_show) in enumerate(izip(shows_list, tvdb_list)): if tvdb_show: item = tvdb.get_list_item(tvdb_show) item.update({ "path": plugin.url_for("eztv_get_show_seasons", show_id=eztv_show["id"], tvdb_id=tvdb_show["id"]) }) yield item else: yield { "label": eztv_show["name"], "path": plugin.url_for("eztv_get_show_seasons", show_id=eztv_show["id"]) }
def eztv_shows_by_letter(letter): import re import xbmc import xbmcgui from bs4 import BeautifulSoup from contextlib import nested, closing from itertools import izip, groupby from concurrent import futures from stream.scrapers import ungenerate from stream.utils import terminating, url_get, SafeDialogProgress from stream import tvdb with shelf("it.eztv.shows") as eztv_shows: if not eztv_shows: response = url_get("%s/showlist/" % BASE_URL, headers=HEADERS) soup = BeautifulSoup(response, "html5lib") nodes = soup.findAll("a", "thread_link") for node in nodes: show_id, show_named_id = node["href"].split("/")[2:4] show_name = node.text show_first_letter = show_name[0].lower() if re.match("\d+", show_first_letter): show_first_letter = "0-9" eztv_shows.setdefault(show_first_letter, {}).update({ show_id: { "id": show_id, "named_id": show_named_id, "name": node.text, } }) shows_list = sorted(eztv_shows[letter.lower()].values(), key=lambda x: x["name"].lower()) with closing(SafeDialogProgress(delay_close=0)) as dialog: dialog.create(plugin.name) dialog.update(percent=0, line1="Fetching series...", line2="", line3="") state = {"done": 0} def on_serie(future): data = future.result() state["done"] += 1 dialog.update( percent=int(state["done"] * 100.0 / len(shows_list)), line2=data and data["seriesname"] or "", ) with futures.ThreadPoolExecutor(max_workers=5) as pool_tvdb: tvdb_list = [pool_tvdb.submit(tvdb.search, show["name"], True) for show in shows_list] [future.add_done_callback(on_serie) for future in tvdb_list] while not all(job.done() for job in tvdb_list): if dialog.iscanceled(): return xbmc.sleep(100) tvdb_list = [job.result() for job in tvdb_list] for i, (eztv_show, tvdb_show) in enumerate(izip(shows_list, tvdb_list)): if tvdb_show: item = tvdb.get_list_item(tvdb_show) item.update({ "path": plugin.url_for("eztv_get_show_seasons", show_id=eztv_show["id"], tvdb_id=tvdb_show["id"]) }) yield item else: yield { "label": eztv_show["name"], "path": plugin.url_for("eztv_get_show_seasons", show_id=eztv_show["id"]) }