def search(params): listing = [] content = "videos" page = 1 update = False category = "Search" if params.mod == "index": listing = get_listing("search") else: category = category + "/" + params.mod result = query = "" dialog = xbmcgui.Dialog() if params.mod == "Discover": content = "" if params.page: page = params.page update = True results = client("/search/movie", get_data={ "type": "discover", "primary_release_year": 2018, "sort_by": "popularity.desc", "page": page }) else: query = dialog.input(translate('Search ' + params.mod), type=xbmcgui.INPUT_ALPHANUM) content = "videos" if query == "": return Plugin.create_listing(listing, succeeded=False) results = client("/search/" + params.mod.lower()[:-1], get_data={ 'page': page, 'type': "search", "language": 'ru', 'query': query }) for i in results: item = [] if params.mod == "Shows": item = makeTvShowItem(i) else: item = makeMovieItem(i) listing.append(item) if len(listing) > 19 and params.mod == "Discover": listing.append({ "label": "Next Page >", "url": plugin.get_url(action='search', mod=params.mod, page=int(page) + 1) }) return Plugin.create_listing(listing, succeeded=True, content=content, update_listing=update, category="Search")
def torrents(params): listing = [] if params.mod == "list": listing = get_listing("torrents") elif params.mod == "files": listing = makeFileList(params.hash) elif params.mod == "delete": client("/torrent/rem", post_data={"Hash": params.hash}) notify("Deleted!") xbmc.executebuiltin("Container.Refresh") return return Plugin.create_listing(listing, content="videos", category="Torrents")
def play_now(params): pDialog = xbmcgui.DialogProgress() pDialog.create("TorrServer", "Wait for info....") success = False counter = 0 selFile = None while True: if pDialog.iscanceled(): pDialog.close() client("/torrent/drop", post_data={"Hash": params.magnet[20:60]}) break time.sleep(0.5) stat = client("/torrent/play", get_data={ "stat": "true", "link": params.magnet, }) if stat is None or len(stat['FileStats']) == 0: counter += 1 if counter < 60: time.sleep(0.5) continue else: pDialog.close() break if len(stat['FileStats']) > 1 and selFile is None: sDialog = xbmcgui.Dialog() filelist = [] for f in stat['FileStats']: filelist.append(f['Path']) sel = sDialog.select('Choose a file', filelist) if sel == -1: client("/torrent/drop", post_data={"Hash": stat['Hash']}) break else: selFile = sel continue elif len(stat['FileStats']) == 1 and selFile is None: selFile = 0 continue else: pDialog.close() preload = touch(TORRSERVED_HOST + "/torrent/play?link=" + params.magnet + "&file=" + str(selFile)) success = makePreloadDialog(stat['Hash']) break return Plugin.resolve_url(TORRSERVED_HOST + "/torrent/play?link=" + params.magnet + "&file=" + str(selFile), succeeded=success)
def makeFileList(hash): request = int(plugin.get_setting("without_info", True)) response = client("/torrent/list", post_data={"Request": request}) listing = [] for t in response: if t['Hash'] == hash: for f in t['Files']: listing.append({ "label": parseName(f['Name']), "title": f['Name'], "url": plugin.get_url(action="play", link=f['Preload'].encode( "utf-8", "replace")), "is_playable": True, "info": { "video": { 'size': f['Size'], 'playcount': int(f['Viewed']) } } }) return listing
def root(): resp = client("/echo") if not resp: notify(translate("Server is down") % TORRSERVED_HOST) return else: listing = get_listing("index") return Plugin.create_listing(listing, category="TorrServer:v " + resp)
def show_torrents(params): info = '{"TmdbID": "' + params.id + '", "VideoType": "' + params.type + '"}' filter = params.year title = params.title if (params.type == 'tvshow'): info = '{"TmdbID": "' + params.id + '", "VideoType": "show"}' pSelSeason = xbmcgui.Dialog() list = ["Season %d" % x for x in range(1, int(params.season) + 1)] list.insert(0, "All") ret = pSelSeason.select("Select Season", list) if ret != 0: selSeason = str(ret) filter = "S0" + selSeason + "|0" + selSeason + "x" else: filter = "" resp = client("/search/torrent", get_data={'query': title, 'ft': filter}) list = [] if resp is None: return False for tor in resp: size = 0 try: if (tor['Size'][-2:] == u"МБ" or tor['Size'][-2:].lower() == "mb"): size = int(tor['Size'][:3]) * 2 << 19 else: size = float(tor['Size'][:-3]) * float(2 << 29) except: pass name = parseName(tor['Name']) if tor['PeersUl'] >= 0: name = "%s [U:%d|D:%d]" % (name, tor['PeersUl'], tor['PeersDl']) list.append({ 'label': name, 'info': { 'video': { 'size': size, 'mediatype': 'video' } }, 'url': plugin.get_url(action="play_now", magnet=tor['Magnet']), 'is_folder': False, "is_playable": True, 'context_menu': [(translate('Add to DB'), 'RunPlugin(' + plugin.get_url( action='torrents', mod='add', magnet=tor['Magnet'], info=info) + ')')], }) return Plugin.create_listing(list, succeeded=True, content="videos", sort_methods=xbmcplugin.SORT_METHOD_SIZE, cache_to_disk=True)
def makePreloadDialog(hash): if plugin.get_setting("disable_dialog", True): return True pDialog = xbmcgui.DialogProgress() pDialog.create("TorrServer", "Wait for info....") success = False counter = 0 while True: if pDialog.iscanceled(): pDialog.close() client("/torrent/drop", post_data={"Hash": hash}) break time.sleep(0.5) stat = client("/torrent/stat", post_data={"Hash": hash}) if stat is None: counter += 1 if counter < 60: time.sleep(0.5) continue else: pDialog.close() break name = parseName(stat['Name']) downSpeed = humanizeSize(stat['DownloadSpeed']) preloadedBytes = stat['PreloadedBytes'] preloadSize = stat['PreloadSize'] line2 = translate("line2") % (stat['ConnectedSeeders'], stat['ActivePeers'], stat['TotalPeers']) line3 = u"D: {0}/сек [{1}/{2}]".format(downSpeed, humanizeSize(preloadedBytes), humanizeSize(preloadSize)) if preloadSize > 0 and preloadedBytes < preloadSize: prc = preloadedBytes * 100 / preloadSize if prc > 100: prc = 100 pDialog.update(prc, name, line2, line3) elif preloadedBytes > preloadSize: success = True pDialog.close() break return success
def settings(params): if params.mod == "open": resp = client("/settings/read", post_data={"read": 1}) for k, v in resp.items(): if k == "CacheSize" or k == "PreloadBufferSize": v = (v / 1024) / 1024 plugin.set_setting(k, str(v).lower()) plugin.addon.openSettings() while settingsIsOpen(): continue jset = { "CacheSize": plugin.get_setting("CacheSize", True) * 1024 * 1024, "PreloadBufferSize": plugin.get_setting("PreloadBufferSize", True) * 1024 * 1024, "RetrackersMode": plugin.get_setting("RetrackersMode", True), "DisableTCP": plugin.get_setting("DisableTCP", True), "DisableUTP": plugin.get_setting("DisableUTP", True), "DisableUPNP": plugin.get_setting("DisableUPNP", True), "DisableDHT": plugin.get_setting("DisableDHT", True), "DisableUpload": plugin.get_setting("DisableUpload", True), "Encryption": plugin.get_setting("Encryption", True), "DownloadRateLimit": plugin.get_setting("DownloadRateLimit", True), "UploadRateLimit": plugin.get_setting("UploadRateLimit", True), "ConnectionsLimit": plugin.get_setting("ConnectionsLimit", True) } client("/settings/write", post_data=jset) client("/torrent/restart")
def get_listing(params): listing = [] if params == "index": listing.append({ 'label': translate("Torrents List"), 'url': plugin.get_url(action='torrents', mod='list'), 'icon': os.path.join(ADDON_PATH, "resources", "img", "list.png"), 'is_folder': True }) listing.append({ 'label': translate("Settings"), 'icon': os.path.join(ADDON_PATH, "resources", "img", "settings.png"), 'url': plugin.get_url(action='settings', mod='open'), 'is_folder': False }) elif params == "torrents": request = int(plugin.get_setting("without_info", True)) resp = client("/torrent/list", post_data={"Request": request}) for t in resp: listing.append({ "label": "[" + humanizeSize(t['Length']) + "] " + parseName(t['Name']), "url": plugin.get_url(action="torrents", mod="files", hash=t['Hash']), "icon": os.path.join(ADDON_PATH, "resources", "img", "magnet.png"), "context_menu": [( translate("Delete from DB"), "RunPlugin(%s)" % plugin.get_url( action="torrents", mod="delete", hash=t["Hash"]), )], }) return listing
def get_listing(params): listing = [] if params == "index": listing.append({ 'label': translate("Torrents List"), 'url': plugin.get_url(action='torrents', mod='list'), 'icon': os.path.join(ADDON_PATH, "resources", "img", "list.png"), 'is_folder': True }) listing.append({ 'label': translate("Search"), 'url': plugin.get_url(action='search', mod='index'), 'icon': os.path.join(ADDON_PATH, "resources", "img", "search.png"), 'is_folder': True }) listing.append({ 'label': translate("Settings"), 'icon': os.path.join(ADDON_PATH, "resources", "img", "settings.png"), 'url': plugin.get_url(action='settings', mod='open'), 'is_folder': False }) elif params == "search": listing.append({ 'label': translate("Search Movies"), 'url': plugin.get_url(action='search', mod='Movies'), 'icon': os.path.join(ADDON_PATH, "resources", "img", "movies.png"), }) listing.append({ 'label': translate("Search Shows"), 'url': plugin.get_url(action='search', mod='Shows'), 'icon': os.path.join(ADDON_PATH, "resources", "img", "tv.png"), }) listing.append({ 'label': translate("Search Discover"), 'url': plugin.get_url(action='search', mod='Discover'), 'icon': os.path.join(ADDON_PATH, "resources", "img", "top.png"), }) elif params == "torrents": request = int(plugin.get_setting("without_info", True)) resp = client("/torrent/list", post_data={"Request": request}) for t in resp: if t['Info'] == "{}": listing.append({ "label": "[" + humanizeSize(t['Length']) + "] " + parseName(t['Name']), "url": plugin.get_url(action="torrents", mod="files", torr=json.dumps(t)), "icon": os.path.join(ADDON_PATH, "resources", "img", "magnet.png"), "context_menu": [( translate("Delete from DB"), "RunPlugin(%s)" % plugin.get_url( action="torrents", mod="delete", hash=t["Hash"]), )], }) else: i = json.loads(t['Info']) info = client('/search/' + i['VideoType'] + "/" + i['TmdbID']) item = [] if i['VideoType'] == "show": item = makeTvShowItem(info) else: item = makeMovieItem(info) item['label'] = "[" + humanizeSize( t['Length']) + "] " + parseName(t['Name']) item['url'] = plugin.get_url(action="torrents", mod="files", torr=json.dumps(t)) item['context_menu'] = [ (translate("Delete from DB"), "RunPlugin(%s)" % plugin.get_url( action="torrents", mod="delete", hash=t["Hash"])) ] listing.append(item) return listing