def index(): try: items = [] if len(PROVIDERS['movies']) == 1: sys_kwargs = { 'module': import_module(provider), 'provider': PROVIDERS['movies'][0] } for item in sys_kwargs['module'].list(): if not item.get("kodipopcorn_endpoint"): continue kwargs = {} if item.get("kodipopcorn_kwargs"): kwargs = item.pop('kodipopcorn_kwargs') item["path"] = plugin.url_for(item.pop('kodipopcorn_endpoint'), **kwargs.update(sys_kwargs)) items.append(item) elif len(PROVIDERS['movies']) > 0: for provider in PROVIDERS: module = import_module(provider) item["path"] = plugin.url_for('list', provider=provider, module=module) items.append(module.INDEX) plugin.finish(items, update_listing=False) except: plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def library_add(): import os, xbmc, xbmcgui from urllib import 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 index(): try: items = [] if len(PROVIDERS['movies']) == 1: sys_kwargs = { 'module': import_module(provider), 'provider': PROVIDERS['movies'][0] } for item in sys_kwargs['module'].list(): if not item.get("kodipopcorn_endpoint"): continue kwargs = {} if item.get("kodipopcorn_kwargs"): kwargs = item.pop('kodipopcorn_kwargs') item["path"] = plugin.url_for(item.pop('kodipopcorn_endpoint'), **kwargs.update(sys_kwargs)) items.append(item) elif len(PROVIDERS['movies']) > 0: for provider in PROVIDERS: module = import_module(provider) item["path"] = plugin.url_for('list', provider=provider, module=module) items.append(module.INDEX) plugin.finish(items, update_listing=False) except: plugin.notify( "{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def play(): try: TorrentPlayer().init(**dict( (k, v[0]) for k, v in plugin.request.args.items())).loop() except: plugin.notify( "{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def search_query(query, page): try: kwargs, sys_kwargs = _filter_kwargs() return sys_kwargs['module'].search_query(query, page, **kwargs.update(sys_kwargs)) except: plugin.notify( "{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def search(): try: query = plugin.keyboard("", plugin.addon.getLocalizedString(30001)) if query: kwargs, sys_kwargs = _filter_kwargs({'query': query, 'page': 1}) plugin.redirect( plugin.url_for("search_query", **kwargs.update(sys_kwargs))) except: plugin.notify( "{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def init(self, uri, **kwargs): max_upload_rate = int(plugin.get_setting("max_upload_rate")) if max_upload_rate and max_upload_rate < 10: max_upload_rate = 0 self.torrent2http_options = { "uri": uri, "dlpath": xbmc.validatePath(xbmc.translatePath(plugin.get_setting("dlpath"))) or CACHE_DIR, "dlrate": plugin.get_setting("max_download_rate") or "0", "ulrate": max_upload_rate, "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): self.torrent2http_options["keep"] = True self.on_playback_started = [] self.on_playback_resumed = [] self.on_playback_paused = [] self.on_playback_stopped = [] return self
def search(): try: query = plugin.keyboard("", plugin.addon.getLocalizedString(30001)) if query: kwargs, sys_kwargs = _filter_kwargs({ 'query': query, 'page': 1 }) plugin.redirect(plugin.url_for("search_query", **kwargs.update(sys_kwargs))) except: plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def clear_cache(): import os, glob from kodipopcorntime.common 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 list(): try: kwargs, sys_kwargs = _filter_kwargs() for item in sys_kwargs['module'].list(**kwargs): if not item.get("kodipopcorn_endpoint"): continue kwargs = {} if item.get("kodipopcorn_kwargs"): kwargs = item.pop('kodipopcorn_kwargs') item["path"] = plugin.url_for(item.pop('kodipopcorn_endpoint'), **kwargs.update(sys_kwargs)) yield item except: plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def tmdb_config(): from kodipopcorntime.caching import shelf try: with shelf("com.imdb.conf", DEFAULT_TTL) as conf: if not conf: from kodipopcorntime.utils import url_get_json conf.update(url_get_json("%s/configuration" % BASE_URL, params={"api_key": API_KEY}, headers=HEADERS)) if not conf: raise return dict(conf) except: plugin.notify(plugin.addon.getLocalizedString(30304)) plugin.log.error('Could not connect to %s/configuration?api_key=%s' %(BASE_URL, API_KEY))
def list(): try: kwargs, sys_kwargs = _filter_kwargs() for item in sys_kwargs['module'].list(**kwargs): if not item.get("kodipopcorn_endpoint"): continue kwargs = {} if item.get("kodipopcorn_kwargs"): kwargs = item.pop('kodipopcorn_kwargs') item["path"] = plugin.url_for(item.pop('kodipopcorn_endpoint'), **kwargs.update(sys_kwargs)) yield item except: plugin.notify( "{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def get(imdb_id): from kodipopcorntime.caching import shelf try: with shelf("com.imdb.%s" % imdb_id, DEFAULT_TTL) as movie: if not movie: import xbmc from kodipopcorntime.utils import url_get_json sys_lang = xbmc.getLanguage(xbmc.ISO_639_1) movie.update(url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits", "language": "en", "include_image_language": "en,null"}, headers=HEADERS)) if not sys_lang == 'en': movie.update(url_get_json("%s/movie/%s" % (BASE_URL, imdb_id), params={"api_key": API_KEY, "append_to_response": "credits", "language": sys_lang, "include_image_language": "%s" % sys_lang}, headers=HEADERS) or {}) if not movie: raise return dict(movie) except: plugin.notify(plugin.addon.getLocalizedString(30304)) plugin.log.error('Could not connect to %s/movie/%s?api_key=%s' %(BASE_URL, imdb_id, API_KEY))
def library_add(): import os, xbmc, xbmcgui from urllib import 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, **kwargs): max_upload_rate = int(plugin.get_setting("max_upload_rate")) if max_upload_rate and max_upload_rate < 10: max_upload_rate = 0 self.torrent2http_options = { "uri": uri, "dlpath": xbmc.validatePath(xbmc.translatePath(plugin.get_setting("dlpath"))) or CACHE_DIR, "dlrate": plugin.get_setting("max_download_rate") or "0", "ulrate": max_upload_rate, "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): self.torrent2http_options["keep"] = True self.on_playback_started = [] self.on_playback_resumed = [] self.on_playback_paused = [] self.on_playback_stopped = [] return self
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources', 'lib')) from kodipopcorntime.common import plugin, PLATFORM, RESOURCES_PATH, AnErrorOccurred from kodipopcorntime.utils import ensure_fanart, SafeDialogProgress from kodipopcorntime.providers import PROVIDERS from kodipopcorntime.magnet import from_meta_data from kodipopcorntime.player import TorrentPlayer if __name__ == '__main__': try: plugin.run() except Exception, e: map(xbmc.log, traceback.format_exc().split("\n")) sys.exit(0) if not PLATFORM.get('os'): plugin.notify(plugin.addon.getLocalizedString(30302), delay=15000) plugin.log.error(plugin.addon.getLocalizedString(30302)) sys.exit(0) LIMIT = 20 QUALITY = 'all' @plugin.route("/") @ensure_fanart def index(): try: items = [] if len(PROVIDERS['movies']) == 1: sys_kwargs = {
def search_query(query, page): try: kwargs, sys_kwargs = _filter_kwargs() return sys_kwargs['module'].search_query(query, page, **kwargs.update(sys_kwargs)) except: plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def play(): try: TorrentPlayer().init(**dict((k, v[0]) for k, v in plugin.request.args.items())).loop() except: plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def browse(provider, item, page): try: kwargs, sys_kwargs = _filter_kwargs() content = 'movies' items = [] with closing(SafeDialogProgress(delay_close=0)) as dialog: dialog.create(plugin.name) dialog.update(percent=0, line1=plugin.addon.getLocalizedString(30007)) movies = sys_kwargs['module'].browse(item, page, **kwargs) jobs = len(movies) * 2 + 1 done = 1 dialog.update(percent=int(done * 100 / jobs), line2=plugin.addon.getLocalizedString(30007)) def on_future_done(future): done = done + 1 data = future.result() dialog.update(percent=int(done * 100 / jobs), line2="{prefix}{label}".format( prefix=data.get('kodipopcorn_subtitle', ''), label=data.get("label", ''))) subtitle = import_module(PROVIDERS['subtitle.yify']) meta = import_module(PROVIDERS['meta.tmdb']) with futures.ThreadPoolExecutor(max_workers=2) as pool: subtitle_list = [ pool.submit( subtitle.get, id=item.get( "info", {}).get("code")).add_done_callback(on_future_done) for item in movies ] meta_list = [ pool.submit(meta.get, id=item.get( "info", {}).get("code")).add_done_callback(on_future_done) for item in movies ] while not all(future.done() for future in subtitle_list) and not all( future.done() for future in meta_list): if dialog.iscanceled(): return xbmc.sleep(100) subtitles = map(lambda future: future.result(), subtitle_list) metadata = map(lambda future: future.result(), meta_list) for i, movie in enumerate(movies): # Update the movie with subtitle and meta data movie.update(subtitles[i]) movie.update(metadata[i]) # Catcher content type and remove it from movie # NOTE: This is not the best way to dynamic set the content type, since the content type can not be set for each movie if movie.get("kodipopcorn_content"): content = movie.pop('kodipopcorn_content') # Catcher quality, build magnet label and remove quality from movie quality = fQuality = '' if movie.get("kodipopcorn_quality"): quality = movie.pop('kodipopcorn_quality') fQuality = " [{quality}]".format(quality=quality) # Build magnet label fYear = '' if movie.get("year"): fYear = " ({year})".format(year=movie["year"]) # Builds targets for the player kwargs = {} if movie.get("kodipopcorn_subtitle"): kwargs['subtitle'] = movie.pop('kodipopcorn_subtitle') kwargs.update({ 'url': from_meta_data(movie.pop('kodipopcorn_hash'), movie["label"] + fYear + fQuality), 'info': movie }) # Update the final information for the movie if quality and not quality == '720p': movie["label"] = "{label} ({quality})".format( label=movie["label"], quality=quality) movie["path"] = plugin.url_for('play', **kwargs) items.append(movie) if items: plugin.set_content(content) return items raise AnErrorOccurred(30307) except AnErrorOccurred as e: plugin.notify("{default} {strerror}".format( default=plugin.addon.getLocalizedString(30306), strerror=plugin.addon.getLocalizedString(e.errno)), delay=15000) except: plugin.notify( "{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
def browse(provider, item, page): try: kwargs, sys_kwargs = _filter_kwargs() content = 'movies' items = [] with closing(SafeDialogProgress(delay_close=0)) as dialog: dialog.create(plugin.name) dialog.update(percent=0, line1=plugin.addon.getLocalizedString(30007)) movies = sys_kwargs['module'].browse(item, page, **kwargs) jobs = len(movies)*2+1 done = 1 dialog.update(percent=int(done*100/jobs), line2=plugin.addon.getLocalizedString(30007)) def on_future_done(future): done = done+1 data = future.result() dialog.update(percent=int(done*100/jobs), line2="{prefix}{label}".format(prefix=data.get('kodipopcorn_subtitle', ''), label=data.get("label", ''))) subtitle = import_module(PROVIDERS['subtitle.yify']) meta = import_module(PROVIDERS['meta.tmdb']) with futures.ThreadPoolExecutor(max_workers=2) as pool: subtitle_list = [pool.submit(subtitle.get, id=item.get("info", {}).get("code")).add_done_callback(on_future_done) for item in movies] meta_list = [pool.submit(meta.get, id=item.get("info", {}).get("code")).add_done_callback(on_future_done) for item in movies] while not all(future.done() for future in subtitle_list) and not all(future.done() for future in meta_list): if dialog.iscanceled(): return xbmc.sleep(100) subtitles = map(lambda future: future.result(), subtitle_list) metadata = map(lambda future: future.result(), meta_list) for i, movie in enumerate(movies): # Update the movie with subtitle and meta data movie.update(subtitles[i]) movie.update(metadata[i]) # Catcher content type and remove it from movie # NOTE: This is not the best way to dynamic set the content type, since the content type can not be set for each movie if movie.get("kodipopcorn_content"): content = movie.pop('kodipopcorn_content') # Catcher quality, build magnet label and remove quality from movie quality=fQuality='' if movie.get("kodipopcorn_quality"): quality = movie.pop('kodipopcorn_quality') fQuality = " [{quality}]".format(quality=quality) # Build magnet label fYear = '' if movie.get("year"): fYear = " ({year})".format(year=movie["year"]) # Builds targets for the player kwargs = {} if movie.get("kodipopcorn_subtitle"): kwargs['subtitle'] = movie.pop('kodipopcorn_subtitle') kwargs.update({ 'url': from_meta_data(movie.pop('kodipopcorn_hash'), movie["label"]+fYear+fQuality), 'info': movie }) # Update the final information for the movie if quality and not quality == '720p': movie["label"] = "{label} ({quality})".format(label=movie["label"], quality=quality) movie["path"] = plugin.url_for('play', **kwargs) items.append(movie) if items: plugin.set_content(content) return items raise AnErrorOccurred(30307) except AnErrorOccurred as e: plugin.notify("{default} {strerror}".format(default=plugin.addon.getLocalizedString(30306), strerror=plugin.addon.getLocalizedString(e.errno)), delay=15000) except: plugin.notify("{default}".format(default=plugin.addon.getLocalizedString(30306)), delay=15000)
import sys, os sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'resources', 'lib')) from kodipopcorntime.common import plugin, PLATFORM, RESOURCES_PATH if __name__ == '__main__': try: plugin.run() except Exception, e: import xbmc import traceback map(xbmc.log, traceback.format_exc().split("\n")) sys.exit(0) if PLATFORM["os"] not in ["android", "linux", "windows", "darwin"]: plugin.notify(plugin.addon.getLocalizedString(30302) % PLATFORM, delay=15000) sys.exit(0) from kodipopcorntime.caching import cached_route from kodipopcorntime.utils import ensure_fanart from kodipopcorntime.providers import yify from kodipopcorntime.player import TorrentPlayer # Cache TTLs DEFAULT_TTL = 24 * 3600 # 24 hours @plugin.route("/") @ensure_fanart def index(): for provider in providers['movie']: yield { "label": provider['label'],