def get(imdb_id): from streamajoker.caching import shelf with shelf("com.imdb.%s" % imdb_id) as movie: if not movie: try: import urllib2 from streamajoker.utils import url_get_json movie.update(url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits"}, headers=HEADERS, with_immunicity=False) or {}) except urllib2.HTTPError: pass return dict(movie)
def search(query, **kwargs): from streamajoker.utils import url_get_json kwargs["query"] = query return url_get_json("%s/search/movie" % BASE_URL, params=kwargs, headers=HEADERS, with_immunicity=False)
def tmdb_config(): from streamajoker.utils import url_get_json return url_get_json("%s/configuration" % BASE_URL, params={"api_key": API_KEY}, headers=HEADERS, with_immunicity=False)
def yify_show_data(callback): import xbmc import xbmcgui from contextlib import nested, closing from itertools import izip, chain from concurrent import futures from streamajoker import tmdb from streamajoker.utils import url_get_json, terminating, SafeDialogProgress plugin.set_content("movies") args = dict((k, v[0]) for k, v in plugin.request.args.items()) current_page = int(args["set"]) limit = int(args["limit"]) with closing(SafeDialogProgress(delay_close=0)) as dialog: dialog.create(plugin.name) dialog.update(percent=0, line1="Fetching movie information...", line2="", line3="") try: search_result = url_get_json("%s/api/list.json" % BASE_URL, params=args, headers=HEADERS) except: plugin.notify("Unable to connect to %s." % BASE_URL) raise movies = search_result.get("MovieList") or [] if not movies: return state = {"done": 0} def on_movie(future): data = future.result() state["done"] += 1 dialog.update( percent=int(state["done"] * 100.0 / len(movies)), line2=data.get("title") or data.get("MovieTitleClean") or "", ) with futures.ThreadPoolExecutor(max_workers=2) as pool_tmdb: tmdb_list = [pool_tmdb.submit(tmdb.get, movie["ImdbCode"]) for movie in movies] [future.add_done_callback(on_movie) for future in tmdb_list] while not all(job.done() for job in tmdb_list): if dialog.iscanceled(): return xbmc.sleep(100) tmdb_list = map(lambda job: job.result(), tmdb_list) for movie, tmdb_meta in izip(movies, tmdb_list): if tmdb_meta: item = tmdb.get_list_item(tmdb_meta) if args.get("quality") == "all" and movie["Quality"] != "720p": item["label"] = "%s (%s)" % (item["label"], movie["Quality"]) item.update({"path": plugin.url_for("play", uri=movie["TorrentMagnetUrl"]), "is_playable": True}) item.setdefault("info", {}).update( { "count": movie["MovieID"], "genre": "%s (%s S:%s P:%s)" % (item["info"]["genre"], movie["Size"], movie["TorrentSeeds"], movie["TorrentPeers"]), "plot_outline": tmdb_meta["overview"], "video_codec": "h264", } ) width = 1920 height = 1080 if movie["Quality"] == "720p": width = 1280 height = 720 item.setdefault("stream_info", {}).update( {"video": {"codec": "h264", "width": width, "height": height}, "audio": {"codec": "aac"}} ) yield item if current_page < (int(search_result["MovieCount"]) / limit): next_args = args.copy() next_args["set"] = int(next_args["set"]) + 1 yield {"label": ">> Next page", "path": plugin.url_for(callback, **next_args)}