def library_add(content_type): import os import xbmc import xbmcgui from xbmctorrent.magnet import ensure_magnet, display_name from xbmctorrent.utils import get_show_info_from_name from urllib import quote_plus, unquote play_url = "plugin://plugin.video.xbmctorrent/play/" for name, entry in LIBRARY_PATHS.items(): if entry["strContent"] == content_type: 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"]) uri = unquote(plugin.request.args_dict["href"].replace(play_url, "")) magnet_uri = ensure_magnet(uri) filename = display_name(magnet_uri) if not filename: plugin.notify("Unable to add this file. Magnet is incomplete.") return if content_type == "tvshows": show_info = get_show_info_from_name(filename) if show_info: real_path = os.path.join(real_path, show_info["show"]) if not os.path.exists(real_path): os.makedirs(real_path) with open(os.path.join(real_path, "%s.strm" % filename), "w") as fp: fp.write("%s%s" % (play_url, quote_plus(magnet_uri))) _rescan_library(entry["strPath"]) plugin.notify("Added to %s." % name) break
def library_add(content_type): import os import xbmc import json from xbmctorrent.magnet import ensure_magnet, display_name from xbmctorrent.utils import get_show_info_from_name from urllib import quote, unquote play_url = "plugin://plugin.video.xbmctorrent/play/" for name, entry in LIBRARY_PATHS.items(): if entry["strContent"] == content_type: real_path = xbmc.translatePath(entry["strPath"]) uri = unquote(plugin.request.args_dict["href"].replace(play_url, "")) magnet_uri = ensure_magnet(uri) filename = display_name(magnet_uri) if not filename: plugin.notify("Unable to add this file. Magnet is incomplete.") return if content_type == "tvshows": show_info = get_show_info_from_name(filename) if show_info: real_path = os.path.join(real_path, show_info["show"]) if not os.path.exists(real_path): os.makedirs(real_path) with open(os.path.join(real_path, "%s.strm" % filename), "w") as fp: fp.write("%s%s" % (play_url, quote(magnet_uri))) xbmc.executeJSONRPC(json.dumps({ "jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.Scan", "params": {"directory": entry["strPath"]}, })) plugin.notify("Added to %s." % name) break
def library_add(content_type): import os import xbmc import xbmcgui from xbmctorrent.magnet import ensure_magnet, display_name from xbmctorrent.utils import get_show_info_from_name from urllib import quote_plus, unquote play_url = "plugin://plugin.video.xbmctorrent/play/" for name, entry in LIBRARY_PATHS.items(): if entry["strContent"] == content_type: 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"]) uri = unquote(plugin.request.args_dict["href"].replace( play_url, "")) magnet_uri = ensure_magnet(uri) filename = display_name(magnet_uri) if not filename: plugin.notify("Unable to add this file. Magnet is incomplete.") return if content_type == "tvshows": show_info = get_show_info_from_name(filename) if show_info: real_path = os.path.join(real_path, show_info["show"]) if not os.path.exists(real_path): os.makedirs(real_path) with open(os.path.join(real_path, "%s.strm" % filename), "w") as fp: fp.write("%s%s" % (play_url, quote_plus(magnet_uri))) _rescan_library(entry["strPath"]) plugin.notify("Added to %s." % name) break