def library_add(): import os, xbmc, xbmcgui from urllib import quote_plus, unquote from kodipopcorntime.magnet import display_name play_url = "plugin://plugin.video.kodipopcorntime/play/" name = LIBRARY_PATHS.iterkeys().next() entry = LIBRARY_PATHS.itervalues().next() if not xbmcgui.Dialog().yesno( "Add to %s" % name, "Add \"%s\" to %s ?" % (plugin.request.args_dict["label"], name), ""): return real_path = xbmc.translatePath(entry["strPath"]) if not os.path.exists(real_path): os.makedirs(real_path) sub, magnet_uri = plugin.request.args_dict["href"].replace(play_url, "").split( '/', 1) with open( os.path.join(real_path, "%s.strm" % display_name(unquote(magnet_uri))), "w") as fp: fp.write("%s%s/%s" % (play_url, sub, magnet_uri)) _rescan_library(entry["strPath"]) plugin.notify("Added to %s." % name)
def clear_cache(): import os import glob from kodipopcorntime.caching import CACHE_DIR for directory in [CACHE_DIR, plugin.storage_path]: for dbfile in glob.glob(os.path.join(directory, "*.db")): os.remove(dbfile) for file in glob.glob(CACHE_DIR + '/com.imdb.*'): os.remove(file) for file in glob.glob(CACHE_DIR + '/kodipopcorntime.route.*'): os.remove(file) plugin.notify(plugin.addon.getLocalizedString(30301))
def library_add(): import os, xbmc, xbmcgui from urllib import quote_plus, unquote from kodipopcorntime.magnet import display_name play_url = "plugin://plugin.video.kodipopcorntime/play/" name = LIBRARY_PATHS.iterkeys().next() entry = LIBRARY_PATHS.itervalues().next() if not xbmcgui.Dialog().yesno( "Add to %s" % name, 'Add "%s" to %s ?' % (plugin.request.args_dict["label"], name), "" ): return real_path = xbmc.translatePath(entry["strPath"]) if not os.path.exists(real_path): os.makedirs(real_path) sub, magnet_uri = plugin.request.args_dict["href"].replace(play_url, "").split("/", 1) with open(os.path.join(real_path, "%s.strm" % display_name(unquote(magnet_uri))), "w") as fp: fp.write("%s%s/%s" % (play_url, sub, magnet_uri)) _rescan_library(entry["strPath"]) plugin.notify("Added to %s." % name)
def init(self, uri, sub=None): self.subtitles = sub self.torrent2http_options = { "uri": uri, "dlpath": xbmc.validatePath(xbmc.translatePath(plugin.get_setting("dlpath"))) or ".", "dlrate": plugin.get_setting("max_download_rate") or "0", "encryption": plugin.get_setting("encryption"), } if "://" in self.torrent2http_options["dlpath"]: # Translate smb:// url to UNC path on windows, very hackish if PLATFORM["os"] == "windows" and self.torrent2http_options["dlpath"].lower().startswith("smb://"): self.torrent2http_options["dlpath"] = self.torrent2http_options["dlpath"].replace("smb:", "").replace("/", "\\") else: plugin.notify("Downloading to an unmounted network share is not supported. Resetting.", delay=15000) plugin.set_setting("dlpath", "") self.torrent2http_options["dlpath"] = "." # Check for Android and FAT32 SD card issues if PLATFORM["os"] == "android" and self.torrent2http_options["dlpath"] != ".": from kodipopcorntime.utils import get_path_fs fs = get_path_fs(self.torrent2http_options["dlpath"]) plugin.log.info("Download path filesytem is %s" % fs) if fs == "vfat": # FAT32 is not supported plugin.notify("Downloading to FAT32 is not supported. Resetting.", delay=15000) plugin.set_setting("dlpath", "") self.torrent2http_options["dlpath"] = "." if plugin.get_setting("keep_files", bool): plugin.log.info("Will keep file after playback.") self.torrent2http_options["keep"] = None self.on_playback_started = [] self.on_playback_resumed = [] self.on_playback_paused = [] self.on_playback_stopped = [] return self
import os from kodipopcorntime import plugin from kodipopcorntime.utils import ensure_fanart from kodipopcorntime.platform import PLATFORM from kodipopcorntime.scrapers import yify from kodipopcorntime.player import TorrentPlayer if PLATFORM["os"] not in [ "android", "linux", "windows", "darwin" ] or PLATFORM["os"] == "android" and not PLATFORM["arch"] == "arm": plugin.notify(plugin.addon.getLocalizedString(30302) % PLATFORM, delay=15000) os._exit(os.EX_SOFTWARE) @plugin.route("/") @ensure_fanart def index(): return yify.index() @plugin.route("/play/<sub>/<uri>") def play(uri, sub=None): if sub == "none": sub = None TorrentPlayer().init(uri, sub).loop()
def show_data(callback): import xbmc import xbmcgui from contextlib import nested, closing from itertools import izip, chain from concurrent import futures from kodipopcorntime.scrapers import tmdb, yifysubs from kodipopcorntime.utils import url_get_json, SafeDialogProgress plugin.set_content("movies") args = dict((k, v[0]) for k, v in plugin.request.args.items()) current_page = int(args["page"]) 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/v2/list_movies.json" % BASE_URL, params=args, headers=HEADERS) except: plugin.notify("Unable to connect to %s." % BASE_URL) raise movies = search_result.get("data").get("movies") or [] movie_count = int(search_result.get("data")["movie_count"]) 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["imdb_code"]) 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: sub = yifysubs.get_sub_items(movie["imdb_code"]) if sub == None: sub = ["none", ""] for torrent in movie["torrents"]: item = tmdb.get_list_item(tmdb_meta) if args.get("quality") == "all" and torrent["quality"] != "720p": item["label"] = "%s (%s)" % (item["label"], torrent["quality"]) if item.get("info").get("duration") == 0: item["info"]["duration"] = movie["runtime"] item.update({ "path": plugin.url_for("play", sub=sub[0], uri=from_meta_data(torrent["hash"], movie["title_long"], torrent["quality"])), "is_playable": True, }) item.setdefault("info", {}).update({ "code": movie["imdb_code"], "size": torrent["size_bytes"], }) width = 1920 height = 1080 if torrent["quality"] == "720p": width = 1280 height = 720 item.setdefault("stream_info", {}).update({ "video": { "codec": "h264", "width": width, "height": height, }, "audio": { "codec": "aac", "language": "en", }, "subtitle": { "language": sub[1], }, }) yield item if current_page < (movie_count / limit): next_args = args.copy() next_args["page"] = int(next_args["page"]) + 1 yield { "label": ">> Next page", "path": plugin.url_for(callback, **next_args), }
import os from kodipopcorntime import plugin from kodipopcorntime.utils import ensure_fanart from kodipopcorntime.platform import PLATFORM from kodipopcorntime.scrapers import yify from kodipopcorntime.player import TorrentPlayer if ( PLATFORM["os"] not in ["android", "linux", "windows", "darwin"] or PLATFORM["os"] == "android" and not PLATFORM["arch"] == "arm" ): plugin.notify(plugin.addon.getLocalizedString(30302) % PLATFORM, delay=15000) os._exit(os.EX_SOFTWARE) @plugin.route("/") @ensure_fanart def index(): return yify.index() @plugin.route("/play/<sub>/<uri>") def play(uri, sub=None): if sub == "none": sub = None TorrentPlayer().init(uri, sub).loop()
def show_data(callback): import xbmc import xbmcgui from contextlib import nested, closing from itertools import izip, chain from concurrent import futures from kodipopcorntime.scrapers import tmdb, yifysubs from kodipopcorntime.utils import url_get_json, SafeDialogProgress plugin.set_content("movies") args = dict((k, v[0]) for k, v in plugin.request.args.items()) current_page = int(args["page"]) 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/v2/list_movies.json" % BASE_URL, params=args, headers=HEADERS) except: plugin.notify("Unable to connect to %s." % BASE_URL) raise movies = search_result.get("data").get("movies") or [] movie_count = int(search_result.get("data")["movie_count"]) 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["imdb_code"]) 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: sub = yifysubs.get_sub_items(movie["imdb_code"]) if sub == None: sub = ["none", ""] for torrent in movie["torrents"]: item = tmdb.get_list_item(tmdb_meta) if args.get("quality" ) == "all" and torrent["quality"] != "720p": item["label"] = "%s (%s)" % (item["label"], torrent["quality"]) if item.get("info").get("duration") == 0: item["info"]["duration"] = movie["runtime"] item.update({ "path": plugin.url_for("play", sub=sub[0], uri=from_meta_data( torrent["hash"], movie["title_long"], torrent["quality"])), "is_playable": True, }) item.setdefault("info", {}).update({ "code": movie["imdb_code"], "size": torrent["size_bytes"], }) width = 1920 height = 1080 if torrent["quality"] == "720p": width = 1280 height = 720 item.setdefault("stream_info", {}).update({ "video": { "codec": "h264", "width": width, "height": height, }, "audio": { "codec": "aac", "language": "en", }, "subtitle": { "language": sub[1], }, }) yield item if current_page < (movie_count / limit): next_args = args.copy() next_args["page"] = int(next_args["page"]) + 1 yield { "label": ">> Next page", "path": plugin.url_for(callback, **next_args), }