def play_video(params): get = params.get mode = get("mode") file_list = get("file_list") file_list = utils.unquote_plus(file_list).split(";") play_list = get("play_list") play_list = utils.unquote_plus(play_list).split(";") folder = get("folder") folder = utils.unquote_plus(folder) # We might have deleted the path if os.path.exists(folder): # we trick xbmc to play avi by creating empty rars if the download is only partial utils.write_fake(file_list, folder) # Prepare potential file stacking if (len(play_list) > 2): rar = [] for arch_rar, movie_file in zip(play_list[0::2], play_list[1::2]): raruri = "rar://" + utils.rarpath_fixer(folder, arch_rar) + "/" + movie_file rar.append(raruri) raruri = 'stack://' + ' , '.join(rar) else: raruri = "rar://" + utils.rarpath_fixer(folder, play_list[0]) + "/" + play_list[1] info = nfo.NfoLabels() item = xbmcgui.ListItem(info.info_labels['title'], iconImage='DefaultVideo.png', thumbnailImage=info.thumbnail) item.setInfo(type="Video", infoLabels=info.info_labels) item.setPath(raruri) item.setProperty("IsPlayable", "true") xbmcplugin.setContent(HANDLE, 'movies') wait = 0 player = xbmcplayer.XBMCPlayer(xbmc.PLAYER_CORE_AUTO) player.sleep(1000) if mode == MODE_AUTO_PLAY or mode == MODE_LIST_PLAY: player.play( raruri, item ) else: xbmcplugin.setResolvedUrl(handle=HANDLE, succeeded=True, listitem=item) removed_fake = False while player.is_active: player.sleep(500) wait+= 1 if player.is_playing and not removed_fake: utils.remove_fake(file_list, folder) removed_fake = True if player.is_stopped: the_end(folder, player.is_stopped) player.is_active = False elif player.is_ended: the_end(folder) player.is_active = False elif wait >= 6000 and not player.isPlayingVideo(): notification("Error playing file!") break if not removed_fake: utils.remove_fake(file_list, folder) else: notification("File deleted") time.sleep(1) xbmc.executebuiltin("Action(ParentDir)") return
def list_movie(params): get = params.get mode = get("mode") file_list = utils.unquote_plus(get("file_list")).split(";") play_list = utils.unquote_plus(get("play_list")).split(";") folder = get("folder") folder = utils.unquote_plus(folder) sab_nzo_id = get("nzoid") sab_nzo_id_history = get("nzoidhistory") return playlist_item(play_list, file_list, folder, sab_nzo_id, sab_nzo_id_history)
def list_movie(params): log("list_movie: params: %s" % params) get = params.get mode = get("mode") file_list = utils.unquote_plus(get("file_list")).split(";") play_list = utils.unquote_plus(get("play_list")).split(";") folder = get("folder") folder = utils.unquote_plus(folder) sab_nzo_id = get("nzoid") sab_nzo_id_history = get("nzoidhistory") return playlist_item(play_list, file_list, folder, sab_nzo_id, sab_nzo_id_history)
def delete(params): log("delete: params: %s" % params) get = params.get sab_nzo_id = get("nzoid") sab_nzo_id_history = get("nzoidhistory") sab_nzo_id_history_list = get("nzoidhistory_list") if sab_nzo_id_history_list: sab_nzo_id_history_list = utils.unquote_plus( sab_nzo_id_history_list).split(";") folder = get("folder") folder = utils.unquote_plus(folder) incomplete = get("incomplete") end = get("end") delete_all = get("delete_all") if delete_all: utils.notification("Deleting all incomplete") else: utils.notification("Deleting %s" % xbmc.translatePath(folder)) if sab_nzo_id or sab_nzo_id_history: delete_ = "ok" if sab_nzo_id: if not "None" in sab_nzo_id and not delete_all: pause = sabnzbd.nzo_pause(sab_nzo_id) log("delete: pause: %s" % pause) time.sleep(3) if "ok" in pause: delete_ = sabnzbd.nzo_delete_files(sab_nzo_id) log("delete: delete_: %s" % delete_) else: delete_ = "failed" if sab_nzo_id_history: if not "None" in sab_nzo_id_history and not delete_all: delete_ = sabnzbd.nzo_delete_history_files(sab_nzo_id_history) if delete_all and sab_nzo_id_history_list: for sab_nzo_id_history_item in sab_nzo_id_history_list: delete_state = sabnzbd.nzo_delete_history_files( sab_nzo_id_history_item) if delete_state is not delete_: delete_state = "failed" delete_ = delete_state if not "ok" in delete_: utils.notification("Deleting failed") else: utils.notification("Deleting failed") log("delete: deleting failed") if end: return elif incomplete: time.sleep(2) xbmc.executebuiltin("Container.Refresh") else: xbmc.executebuiltin("Action(ParentDir)") return
def delete(params): log("delete: params: %s" % params) get = params.get sab_nzo_id = get("nzoid") sab_nzo_id_history = get("nzoidhistory") sab_nzo_id_history_list = get("nzoidhistory_list") if sab_nzo_id_history_list: sab_nzo_id_history_list = utils.unquote_plus(sab_nzo_id_history_list).split(";") folder = get("folder") folder = utils.unquote_plus(folder) incomplete = get("incomplete") end = get("end") delete_all = get("delete_all") if delete_all: utils.notification("Deleting all incomplete") else: utils.notification("Deleting %s" % xbmc.translatePath(folder)) if sab_nzo_id or sab_nzo_id_history: delete_ = "ok" if sab_nzo_id: if not "None" in sab_nzo_id and not delete_all: pause = SABNZBD.pause_queue(id=sab_nzo_id) log("delete: pause: %s" % pause) time.sleep(3) if "ok" in pause: delete_ = SABNZBD.delete_queue('',sab_nzo_id) log("delete: delete_: %s" % delete_) else: delete_ = "failed" if sab_nzo_id_history: if not "None" in sab_nzo_id_history and not delete_all: delete_ = SABNZBD.delete_history('',sab_nzo_id_history) if delete_all and sab_nzo_id_history_list: for sab_nzo_id_history_item in sab_nzo_id_history_list: delete_state = SABNZBD.delete_history('',sab_nzo_id_history_item) if delete_state is not delete_: delete_state = "failed" delete_ = delete_state if not "ok" in delete_: utils.notification("Deleting failed") else: utils.notification("Deleting failed") log("delete: deleting failed") if end: return elif incomplete: time.sleep(2) xbmc.executebuiltin("Container.Refresh") else: xbmc.executebuiltin("Action(ParentDir)") return
def del_local_file(params): log("del_local_file: params: %s" % params) local_file = utils.unquote_plus(params.get("nzb")) if xbmcgui.Dialog().yesno("Pneumatic", "Delete:", "%s" % local_file): log("del_local_file: delete: %s" % local_file) utils.delete(local_file) xbmc.executebuiltin("Container.Refresh")
def PrettyUrlToQuery(url, root='', order=''): """Transforms a pretty url into a query. The order of the query terms is given using a url query parameter of name "ot" or by explicitely using the order variable. """ root = root.split('/') url = urlparse.urlparse(url) path = utils.unquote_plus(url.path) # make the query string from url query = [] for field, terms, all in PATH_PATTERN.findall(path): if all and all not in root: terms = all field = '*' if not terms: continue for term in terms.split('|'): if term[0] == '*': status = '-' term = term[1:] else: status = '' query.append('(@%s%s %s)' % (status, field, term)) # handle the order of the query terms if not order: order = re.search('(?:\?|&|^)ot=(\d+)', url.query) order = order and order.group(1) if order: order = dict((q, int(i)) for q, i in zip(query, order)) query = sorted(query, key=lambda x: order.get(x, 0)) return ' '.join(qt for qt in query)
def download(params): get = params.get nzb = utils.unquote_plus(get("nzb")) nzbname = utils.unquote_plus(get("nzbname")) category = get_category(ask = True) addurl = SABNZBD.addurl(nzb, nzbname, category=category) progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Sending request to SABnzbd') if "ok" in addurl: progressDialog.update(100, 'Request to SABnzbd succeeded') time.sleep(1) else: xbmc.log(addurl) progressDialog.update(0, 'Request to SABnzbd failed!') time.sleep(1) progressDialog.close() return
def del_local(params): folder = utils.unquote_plus(params.get("folder")) folder_path = folder.encode('utf-8') folder_list = __settings__.getSetting("nzb_folder_list").split(';') folder_list.remove(folder_path) new_folder_list = ';'.join(folder_list) __settings__.setSetting("nzb_folder_list", new_folder_list) xbmc.executebuiltin("Container.Refresh")
def download(params): log("download: params: %s" % params) get = params.get nzb = utils.unquote_plus(get("nzb")) nzbname = utils.unquote_plus(get("nzbname")) category = get_category(ask = True) addurl = sabnzbd.addurl(nzb, nzbname, category=category) log("download: addurl: %s" % addurl) progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Sending request to SABnzbd') if "ok" in addurl: progressDialog.update(100, 'Request to SABnzbd succeeded') time.sleep(1) else: progressDialog.update(0, 'Request to SABnzbd failed!') time.sleep(1) progressDialog.close() return
def list_local(params): log("list_local: params: %s" % params) top_folder = utils.unquote_plus(params.get("folder")) type = utils.unquote_plus(params.get("type")) for folder in utils.listdir_dirs(top_folder): folder_path = utils.join(top_folder, folder) # Check if the folder contains a single nzb and no folders nzb_list = [] folder_list = [] for file in utils.listdir_files(folder_path): file_path = utils.join(folder_path, file) ext = os.path.splitext(file_path)[1] if ext == '.nzb' or ext == '.gz' or ext == '.zip': nzb_list.append(file_path) for sub_folder in utils.listdir_dirs(folder_path): folder_list.append(sub_folder) # If single nzb allow the folder to be playable and show info if len(nzb_list) == 1 and len(folder_list) == 0: # Fixing the naming of nzb according to SAB rules nzb_name = m_nzb.Nzbname(os.path.basename(nzb_list[0])).final_name if folder.lower() == nzb_name.lower(): info = nfo.ReadNfoLabels(folder_path) info.info_labels['title'] = info.info_labels['title'] url = "&nzbname=" + utils.quote_plus(nzb_name) +\ "&nzb=" + utils.quote_plus(nzb_list[0]) + "&type=" + type add_posts(info.info_labels, url, MODE_LOCAL_FILE_IN_DIR, info.thumbnail, info.fanart, False) else: url = "&type=" + type + "&folder=" + utils.quote_plus( folder_path) add_posts({'title': folder}, url, MODE_LOCAL_LIST, '', '') else: url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path) add_posts({'title': folder}, url, MODE_LOCAL_LIST, '', '') for file in utils.listdir_files(top_folder): ext = os.path.splitext(file)[1] if ext == '.nzb' or ext == '.gz' or ext == '.zip': file_path = utils.join(top_folder, file) url = "&nzbname=" + utils.quote_plus(m_nzb.Nzbname(file).final_name) +\ "&nzb=" + utils.quote_plus(file_path) + "&type=" + type add_posts({'title': file}, url, MODE_LOCAL_FILE, '', '', False) xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) return
def del_local(params): log("del_local: params: %s" % params) folder = utils.unquote_plus(params.get("folder")) folder_path = folder.encode('utf-8') folder_list = __settings__.getSetting("nzb_folder_list").split(';') folder_list.remove(folder_path) new_folder_list = ';'.join(folder_list) log("del_local: new_folder_list: %s" % new_folder_list) __settings__.setSetting("nzb_folder_list", new_folder_list) xbmc.executebuiltin("Container.Refresh")
def list_local(params): log("list_local: params: %s" % params) top_folder = utils.unquote_plus(params.get("folder")) type = utils.unquote_plus(params.get("type")) for folder in utils.listdir_dirs(top_folder): folder_path = utils.join(top_folder, folder) # Check if the folder contains a single nzb and no folders nzb_list = [] folder_list = [] for file in utils.listdir_files(folder_path): file_path = utils.join(folder_path, file) ext = os.path.splitext(file_path)[1] if ext == '.nzb' or ext == '.gz' or ext == '.zip': nzb_list.append(file_path) for sub_folder in utils.listdir_dirs(folder_path): folder_list.append(sub_folder) # If single nzb allow the folder to be playable and show info if len(nzb_list) == 1 and len(folder_list) == 0: # Fixing the naming of nzb according to SAB rules nzb_name = m_nzb.Nzbname(os.path.basename(nzb_list[0])).final_name if folder.lower() == nzb_name.lower(): info = nfo.ReadNfoLabels(folder_path) info.info_labels['title'] = info.info_labels['title'] url = "&nzbname=" + utils.quote_plus(nzb_name) +\ "&nzb=" + utils.quote_plus(nzb_list[0]) + "&type=" + type add_posts(info.info_labels, url, MODE_PLAY, info.thumbnail, info.fanart, False) else: url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path) add_posts({'title':folder}, url, MODE_LOCAL_LIST, '', '') else: url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path) add_posts({'title':folder}, url, MODE_LOCAL_LIST, '', '') for file in utils.listdir_files(top_folder): ext = os.path.splitext(file)[1] if ext == '.nzb' or ext == '.gz' or ext == '.zip': file_path = utils.join(top_folder, file) url = "&nzbname=" + utils.quote_plus(m_nzb.Nzbname(file).final_name) +\ "&nzb=" + utils.quote_plus(file_path) + "&type=" + type add_posts({'title':file}, url, MODE_PLAY, '', '', False) xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) return
def del_local_file_in_dir(params): log("del_local_file_in_dir: params: %s" % params) local_file = utils.unquote_plus(params.get("nzb")) local_path = os.path.dirname(local_file) if xbmcgui.Dialog().yesno("Pneumatic", "Delete:", "%s" % local_path): for file in utils.listdir_files(local_path): local_file_path = utils.join(local_path, file) log("del_local_file_in_dir: delete: %s" % local_file_path) utils.delete(local_file_path) log("del_local_file_in_dir: rmdir: %s" % local_path) utils.rmdir(local_path) xbmc.executebuiltin("Container.Refresh")
def list_incomplete(params): log("list_incomplete: params: %s" % params) nzbname = utils.unquote_plus(params.get("nzbname")) sab_nzo_id = params.get("nzoid") pre_play(nzbname, mode=MODE_INCOMPLETE_LIST, nzo=sab_nzo_id)
def is_nzb_home(params): log("is_nzb_home: params: %s" % params) get = params.get nzb = utils.unquote_plus(get("nzb")) nzbname = m_nzb.Nzbname(utils.unquote_plus(get("nzbname"))).final_name folder = utils.join(INCOMPLETE_FOLDER, nzbname) iscanceled = False type = get('type', 'addurl') sab_nzo_id = SABNZBD.nzo_id(nzbname, nzb) log("is_nzb_home: folder: %s sab_nzo_id: %s" %(folder, sab_nzo_id)) if not utils.dir_exists(folder, sab_nzo_id): progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Sending request to SABnzbd') category = get_category() if type == 'addurl': type, nzb = nzb_cache(type, nzb, nzbname) # SABnzbd and URI should be latin-1 encoded if type == 'addurl': response = SABNZBD.addurl(nzb.encode('latin-1'), nzbname, category=category) elif type == 'add_local': response = SABNZBD.add_local(nzb.encode('latin-1'), category=category) elif type == 'add_file': response = SABNZBD.add_file(nzb.encode('latin-1'), category=category) log("is_nzb_home: type: %s response: %s" %(type, response)) if "ok" in response: progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download') seconds = 0 #SABnzbd uses nzb url as name until it has downloaded the nzb file sab_nzo_id_init = SABNZBD.nzo_id(nzbname, nzb) log("is_nzb_home: sab_nzo_id_init: %s" % sab_nzo_id_init) while not (sab_nzo_id and utils.exists(folder)): sab_nzo_id = SABNZBD.nzo_id(nzbname) label = str(seconds) + " seconds" log("is_nzb_home: waiting for nzb: sab_nzo_id: %s for: %s" % (sab_nzo_id, label)) progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download', label) if progressDialog.iscanceled(): progressDialog.close() log("is_nzb_home: waiting for nzb: canceled") # Fix for hang when playing .strm time.sleep(1) xbmc.Player().stop() if sab_nzo_id is None and sab_nzo_id_init is not None: sab_nzo_id = sab_nzo_id_init #Trying to delete both the queue and history if sab_nzo_id is not None: pause = SABNZBD.pause_queue(id=sab_nzo_id) log("is_nzb_home: pause: sab_nzo_id: %s msg: %s" % (sab_nzo_id, pause)) time.sleep(3) delete_msg = SABNZBD.delete_queue('',sab_nzo_id) log("is_nzb_home: delete_queue: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg)) if not "ok" in delete_msg: delete_msg = SABNZBD.delete_history('',sab_nzo_id) log("is_nzb_home: delete_history: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg)) else: log("is_nzb_home: failed removing %s from the queue" % nzbname) iscanceled = True break time.sleep(1) seconds += 1 if not iscanceled: switch = SABNZBD.switch(0, '', sab_nzo_id) log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch)) if not "ok" in switch: progressDialog.update(0, 'Failed to prioritize the nzb!') time.sleep(1) # Dont add meta data for local nzb's if type == 'addurl': t = Thread(target=save_nfo, args=(folder,)) t.start() progressDialog.close() return True, sab_nzo_id else: progressDialog.close() return False, sab_nzo_id else: progressDialog.close() log("is_nzb_home: failed adding nzb to SAB") # Fix for hang when playing .strm xbmc.Player().stop() utils.notification("Request to SABnzbd failed!") return False, sab_nzo_id else: switch = SABNZBD.switch(0,'' , sab_nzo_id) log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch)) if not "ok" in switch: utils.notification("Failed to prioritize the nzb!") # TODO make sure there is also a NZB in the queue return True, sab_nzo_id
__settings__.openSettings() if utils.pass_setup_test(SABNZBD.setup_streaming(), __settings__.getSetting("sabnzbd_incomplete")): __settings__.setSetting("firstrun", '1') else: if (not sys.argv[2]): add_posts({'title':'Incomplete'}, '', MODE_INCOMPLETE) add_posts({'title':'Browse local NZB\'s'}, '', MODE_LOCAL, '', '') xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) else: params = utils.get_parameters(sys.argv[2]) get = params.get if get("mode")== MODE_PLAY: is_home, sab_nzo_id = is_nzb_home(params) if is_home: nzbname = utils.unquote_plus(get("nzbname")) pre_play(nzbname, nzo=sab_nzo_id) if get("mode")== MODE_LIST_PLAY or get("mode")== MODE_AUTO_PLAY: play_video(params) if get("mode")== MODE_DELETE: delete(params) if get("mode")== MODE_DOWNLOAD: download(params) if get("mode")== MODE_REPAIR: repair(params) if get("mode")== MODE_INCOMPLETE: incomplete() if get("mode")== MODE_INCOMPLETE_LIST: list_incomplete(params) if get("mode")== MODE_STRM: xbmc.executebuiltin('Dialog.Close(all, true)')
def play_video(params): log("play_video: params: %s" % params) get = params.get mode = get("mode") file_list = get("file_list") file_list = utils.unquote_plus(file_list).split(";") play_list = get("play_list") play_list = utils.unquote_plus(play_list).split(";") folder = get("folder") folder = utils.unquote_plus(folder) # We might have deleted the path if utils.exists_incomplete(folder): if len(file_list) > 0 and not play_list[1].endswith(play_list[0]): # we trick xbmc to play avi by creating empty rars if the download is only partial utils.write_fake(file_list, folder) # Prepare potential file stacking if (len(play_list) > 2): rar = [] for arch_rar, movie_file in zip(play_list[0::2], play_list[1::2]): raruri = "rar://" + utils.rarpath_fixer(folder, arch_rar) + "/" + movie_file rar.append(raruri) raruri = 'stack://' + ' , '.join(rar) else: raruri = "rar://" + utils.rarpath_fixer(folder, play_list[0]) + "/" + play_list[1] uri = raruri else: # we have a plain file if (len(play_list) > 2): uri = "stack://%s" % ' , '.join(play_list[1::2]) else: uri = play_list[1] log("play_video: uri: %s" % uri) info = nfo.NfoLabels() item = xbmcgui.ListItem(info.info_labels['title'], iconImage='DefaultVideo.png', thumbnailImage=info.thumbnail) item.setInfo(type="Video", infoLabels=info.info_labels) item.setPath(uri) item.setProperty("IsPlayable", "true") xbmcplugin.setContent(HANDLE, 'movies') wait = 0 player = xbmcplayer.XBMCPlayer(xbmc.PLAYER_CORE_AUTO) player.sleep(1000) if mode == MODE_AUTO_PLAY or mode == MODE_LIST_PLAY: player.play( uri, item ) log("play_video: player.play uri: %s" % uri) else: xbmcplugin.setResolvedUrl(handle=HANDLE, succeeded=True, listitem=item) log("play_video: setResolvedUrl uri: %s" % uri) removed_fake = False while player.is_active: player.sleep(500) wait+= 1 if player.is_playing and not removed_fake: utils.remove_fake(file_list, folder) removed_fake = True if player.is_stopped: the_end(folder, player.is_stopped, params.get("nzoid"), params.get("nzoidhistory")) player.is_active = False elif player.is_ended: time.sleep(1) log("rassi: player.is_ended, player.is_stopped %s" % player.is_stopped) the_end(folder, True, params.get("nzoid"), params.get("nzoidhistory")) player.is_active = False elif wait >= 6000 and not player.isPlayingVideo(): utils.notification("Error playing file!") break if not removed_fake: utils.remove_fake(file_list, folder) else: utils.notification("File deleted") time.sleep(1) xbmc.executebuiltin("Action(ParentDir)") return
def is_nzb_home(params): log("is_nzb_home: params: %s" % params) get = params.get nzb = utils.unquote_plus(get("nzb")) nzbname = m_nzb.Nzbname(utils.unquote_plus(get("nzbname"))).final_name folder = utils.join(INCOMPLETE_FOLDER, os.path.join(nzbname, '')) iscanceled = False type = get('type', 'addurl') sab_nzo_id = sabnzbd.nzo_id(nzbname, nzb) log("is_nzb_home: folder: %s sab_nzo_id: %s" %(folder, sab_nzo_id)) if sab_nzo_id is None: nzo_id = sabnzbd.nzo_id_history(nzbname) else: nzo_id = sab_nzo_id log("is_nzb_home: nzo_id: %s" % nzo_id) if not utils.dir_exists(folder, nzo_id): progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Sending request to SABnzbd') category = get_category() # correct wrong type mode if nzb.startswith('http'): type = "addurl" log("is_nzb_home: type changed to addurl") elif type == 'addurl': type = 'add_file' log("is_nzb_home: type changed to add_file") if type == 'addurl': type, nzb = nzb_cache(type, nzb, nzbname) # SABnzbd and URI should be latin-1 encoded if type == 'addurl': response = sabnzbd.addurl(nzb.encode('latin-1'), nzbname, category=category) # add_local will not work on remote shares, thus add_file elif type == 'add_file' or type == 'add_local': response = sabnzbd.add_file(nzb.encode('latin-1'), category=category) log("is_nzb_home: type: %s response: %s" %(type, response)) if "ok" in response: progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download') seconds = 0 timer = 0 #SABnzbd uses nzb url as name until it has downloaded the nzb file sab_nzo_id_init = sabnzbd.nzo_id(nzbname, nzb) log("is_nzb_home: sab_nzo_id_init: %s" % sab_nzo_id_init) while not (sab_nzo_id and utils.exists_incomplete(folder)): # Ask user what incomplete dir is right every 10s if timer > 9: timer = 0 folder, nzbname = find_incomplete(folder, nzbname) sab_nzo_id = sabnzbd.nzo_id(nzbname) label = str(seconds) + " seconds" log("is_nzb_home: waiting for nzb: sab_nzo_id: %s for: %s" % (sab_nzo_id, label)) progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download', label) if progressDialog.iscanceled(): progressDialog.close() log("is_nzb_home: waiting for nzb: canceled") # Fix for hang when playing .strm time.sleep(1) xbmc.Player().stop() if sab_nzo_id is None and sab_nzo_id_init is not None: sab_nzo_id = sab_nzo_id_init #Trying to delete both the queue and history if sab_nzo_id is not None: pause = sabnzbd.nzo_pause(sab_nzo_id) #log("rassi pause") log("is_nzb_home: pause: sab_nzo_id: %s msg: %s" % (sab_nzo_id, pause)) time.sleep(3) #log("rassi before delete") delete_msg = sabnzbd.nzo_delete_files(sab_nzo_id) log("is_nzb_home: delete_queue: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg)) if not "ok" in delete_msg: delete_msg = sabnzbd.nzo_delete_history_files(sab_nzo_id) log("is_nzb_home: delete_history: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg)) #log("rassi after delete") else: log("is_nzb_home: failed removing %s from the queue" % nzbname) iscanceled = True break time.sleep(1) seconds += 1 timer += 1 if not iscanceled: switch = sabnzbd.nzo_switch(sab_nzo_id, 0).replace('\n', '') log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch)) if not "0" in switch: progressDialog.update(0, 'Failed to prioritize the nzb!') time.sleep(1) # Dont add meta data for local nzb's if type == 'addurl': t = Thread(target=save_nfo, args=(folder,)) t.start() progressDialog.close() return True, sab_nzo_id else: progressDialog.close() return False, sab_nzo_id else: progressDialog.close() log("is_nzb_home: failed adding nzb to SAB") # Fix for hang when playing .strm xbmc.Player().stop() utils.notification("Request to SABnzbd failed!") return False, sab_nzo_id else: switch = sabnzbd.nzo_switch(sab_nzo_id, 0).replace('\n', '') log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch)) if not "0" in switch: utils.notification("Failed to prioritize the nzb!") # TODO make sure there is also a NZB in the queue return True, sab_nzo_id
#TODO fix this if utils.pass_setup_test(sabnzbd.self_test(), __settings__.getSetting("sabnzbd_incomplete")): __settings__.setSetting("firstrun", '1') else: if (not sys.argv[2]): add_posts({'title':'Incomplete'}, '', MODE_INCOMPLETE) add_posts({'title':'Browse local NZB\'s'}, '', MODE_LOCAL, '', '') xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) else: params = utils.get_parameters(sys.argv[2]) get = params.get if get("mode")== MODE_PLAY: is_home, sab_nzo_id = is_nzb_home(params) if is_home: nzbname = utils.unquote_plus(get("nzbname")) pre_play(nzbname, nzo=sab_nzo_id) if get("mode")== MODE_LIST_PLAY or get("mode")== MODE_AUTO_PLAY: play_video(params) if get("mode")== MODE_DELETE: delete(params) if get("mode")== MODE_DOWNLOAD: download(params) if get("mode")== MODE_REPAIR: repair(params) if get("mode")== MODE_INCOMPLETE: incomplete() if get("mode")== MODE_INCOMPLETE_LIST: list_incomplete(params) if get("mode")== MODE_STRM: xbmc.executebuiltin('Dialog.Close(all, true)')