def playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history): log("playlist_item: play_list: %s rar_file_list: %s folder: %s sab_nzo_id: %s sab_nzo_id_history: %s" %\ (play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history)) new_play_list = play_list[:] for arch_rar, movie_file in zip(play_list[0::2], play_list[1::2]): info = nfo.ReadNfoLabels(folder) xurl = "%s?mode=%s" % (sys.argv[0],MODE_LIST_PLAY) url = (xurl + "&nzoid=" + str(sab_nzo_id) + "&nzoidhistory=" + str(sab_nzo_id_history)) +\ "&play_list=" + utils.quote_plus(';'.join(new_play_list)) + "&folder=" + utils.quote_plus(folder) +\ "&file_list=" + utils.quote_plus(';'.join(rar_file_list)) new_play_list.remove(arch_rar) new_play_list.remove(movie_file) item = xbmcgui.ListItem(movie_file, iconImage='DefaultVideo.png', thumbnailImage=info.thumbnail) item.setInfo(type="Video", infoLabels=info.info_labels) item.setProperty("Fanart_Image", info.fanart) item.setPath(url) isfolder = False # item.setProperty("IsPlayable", "true") cm = [] if sab_nzo_id_history: cm_url_repair = sys.argv[0] + '?' + "mode=repair" + "&nzoidhistory=" + str(sab_nzo_id_history) + "&folder=" + utils.quote_plus(folder) cm.append(("Repair" , "XBMC.RunPlugin(%s)" % (cm_url_repair))) cm_url_delete = sys.argv[0] + '?' + "mode=delete" + "&nzoid=" + str(sab_nzo_id) + "&nzoidhistory=" + str(sab_nzo_id_history) + "&folder=" + utils.quote_plus(folder) cm.append(("Delete" , "XBMC.RunPlugin(%s)" % (cm_url_delete))) item.addContextMenuItems(cm, replaceItems=True) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=item, isFolder=isfolder) xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) return
def _search_request(self, url, query): if '=%s' in url.search: query = quote_plus(query) else: query = query.decode('utf-8') return self._request.get(url.base + url.search % query)
def search(url, query): if '=%s' in url.search: query = quote_plus(query) else: query = query.decode('utf-8') return request.get(url.base + url.search % query)
def incomplete(): log("incomplete:") active_nzbname_list, nzbname_list = nzbname_lists() nzoid_history_list = [x[1] for x in nzbname_list if x[1] is not None] for row in active_nzbname_list: url = "&nzoid=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\ "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\ "&folder=" + utils.quote_plus(row[0]) info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0])) info.info_labels['title'] = "Active - " + info.info_labels['title'] add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail, info.fanart) for row in nzbname_list: if row[1]: url = "&nzoidhistory=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\ "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\ "&folder=" + utils.quote_plus(row[0]) info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0])) add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail, info.fanart) else: # Clean out a failed SABnzbd folder removal utils.dir_exists(utils.join(INCOMPLETE_FOLDER, row[0]), None) xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) return
def local(): log("local:") type = 'add_file' folder_list = __settings__.getSetting('nzb_folder_list').split(';') if len(folder_list) == 1 and len(folder_list[0]) == 0: add_posts({'title':'Add folder'}, '', MODE_ADD_LOCAL, '', '', False) else: for folder in folder_list: folder_path = unicode(folder, 'utf-8') folder_name = os.path.split(os.path.dirname(folder_path))[1] if len(folder_path) > 1: url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path) add_posts({'title':folder_name}, url, MODE_LOCAL_LIST_TOP, '', '') xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True)
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 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 incomplete(): log("incomplete:") active_nzbname_list = [] m_nzbname_list = [] m_row = [] for folder in utils.listdir_dirs(INCOMPLETE_FOLDER): sab_nzo_id = SABNZBD.nzo_id(folder) if not sab_nzo_id: m_row.append(folder) m_row.append(None) m_nzbname_list.append(m_row) log("incomplete: m_nzbname_list.append: %s" % m_row) m_row = [] else: m_row.append(folder) m_row.append(sab_nzo_id) active_nzbname_list.append(m_row) log("incomplete: active_nzbname_list: %s" % m_row) m_row = [] nzbname_list = SABNZBD.nzo_id_history_list(m_nzbname_list) nzoid_history_list = [x[1] for x in nzbname_list if x[1] is not None] for row in active_nzbname_list: url = "&nzoid=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\ "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\ "&folder=" + utils.quote_plus(row[0]) info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0])) info.info_labels['title'] = "Active - " + info.info_labels['title'] add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail, info.fanart) for row in nzbname_list: if row[1]: url = "&nzoidhistory=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\ "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\ "&folder=" + utils.quote_plus(row[0]) info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0])) add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail, info.fanart) else: # Clean out a failed SABnzbd folder removal utils.dir_exists(utils.join(INCOMPLETE_FOLDER, row[0]), None) xbmcplugin.setContent(HANDLE, 'movies') xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True) return
def pre_play(nzbname, **kwargs): log("pre_play: nzbname: %s kwargs: %s" % (nzbname, kwargs)) mode = kwargs.get('mode', None) sab_nzo_id = kwargs.get('nzo', None) iscanceled = False folder = utils.join(INCOMPLETE_FOLDER, nzbname) folder_one = folder + '.1' if utils.exists(folder_one): folder = folder_one sab_file_list = [] multi_arch_list = [] if sab_nzo_id is None: sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname) nzf_list = utils.dir_to_nzf_list(folder, sabnzbd) else: nzo = sabnzbd.Nzo(SABNZBD, sab_nzo_id) nzf_list = nzo.nzf_list() sab_nzo_id_history = None sorted_rar_nzf_list = utils.sorted_rar_nzf_file_list(nzf_list) # TODO # If we cant find any rars in the queue, we have to wait for SAB # and then guess the names... # if len(nzf_list) == 0: # iscanceled = get_nzf(folder, sab_nzo_id, None) is_movie_in_rar = True if len(sorted_rar_nzf_list) == 0: # look for other playable files multi_nzf_list = sorted_nzf_list = utils.sorted_movie_nzf_file_list(nzf_list) if len(multi_nzf_list) > 0: is_movie_in_rar = False else: multi_nzf_list = utils.sorted_multi_arch_nzf_list(sorted_rar_nzf_list) sorted_nzf_list = sorted_rar_nzf_list clean_sorted_nzf_list = utils.nzf_diff_list(sorted_nzf_list, multi_nzf_list) if len(multi_nzf_list) > 0: # Loop though all multi archives and add file to the play_list = [] for nzf in multi_nzf_list: if sab_nzo_id is not None: response = set_streaming(sab_nzo_id) log("pre_play: set_streaming: %s" % response) t = Thread(target=nzf_to_bottom, args=(sab_nzo_id, nzf_list, sorted_nzf_list,)) t.start() iscanceled = get_nzf(folder, sab_nzo_id, nzf) if iscanceled: break else: if is_movie_in_rar: # RAR ANALYSYS # in_rar_file_list = utils.rar_filenames(folder, nzf.filename) movie_list = utils.sort_filename(in_rar_file_list) log("pre_play: folder: %s nzf.filename: %s in_rar_file_list: %s" % (folder, nzf.filename, in_rar_file_list)) else: movie_list = [os.path.join(folder, nzf.filename)] # Make sure we have a movie if not (len(movie_list) >= 1): utils.notification("Not a movie!") log("pre_play: no movie in movie_list") break # Who needs sample? movie_no_sample_list = utils.no_sample_list(movie_list) # If auto play is enabled we skip samples in the play_list if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST: for movie_file in movie_no_sample_list: play_list.append(nzf.filename) play_list.append(movie_file) else: for movie_file in movie_list: play_list.append(nzf.filename) play_list.append(movie_file) # If the movie is a .mkv or .mp4 we need the last rar if utils.is_movie_mkv(movie_list) and sab_nzo_id and is_movie_in_rar: # If we have a sample or other file, the second rar is also needed.. if len(in_rar_file_list) > 1: second_nzf = clean_sorted_nzf_list[1] iscanceled = get_nzf(folder, sab_nzo_id, second_nzf) last_nzf = clean_sorted_nzf_list[-1] iscanceled = get_nzf(folder, sab_nzo_id, last_nzf) if iscanceled: break if iscanceled: log("pre_play: get_nzf: canceled") return else: rar_file_list = [x.filename for x in sorted_nzf_list] if (len(rar_file_list) >= 1) or (not is_movie_in_rar and len(movie_list) >= 1): if AUTO_PLAY and ( mode is None or mode is MODE_STRM): video_params = dict() if not mode: video_params['mode'] = MODE_AUTO_PLAY else: video_params['mode'] = MODE_STRM video_params['play_list'] = utils.quote_plus(';'.join(play_list)) video_params['file_list'] = utils.quote_plus(';'.join(rar_file_list)) video_params['folder'] = utils.quote_plus(folder) return play_video(video_params) else: return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history) else: utils.notification("No rar\'s in the NZB!") log("pre_play: no rar\'s in the NZB") return else: utils.notification("No playable files found!") log("pre_play: no playable files found") return
def pre_play(nzbname, **kwargs): log("pre_play: nzbname: %s kwargs: %s" % (nzbname, kwargs)) mode = kwargs.get('mode', None) sab_nzo_id = kwargs.get('nzo', None) iscanceled = False folder = utils.join(INCOMPLETE_FOLDER, os.path.join(nzbname, '')) folder_one = folder + '.1' if utils.exists(os.path.join(folder_one, '')): folder = folder_one if sab_nzo_id is None: sab_nzo_id_history = sabnzbd.nzo_id_history(nzbname) nzf_list = utils.dir_to_nzf_list(folder) else: nzo = Nzo(sab_nzo_id) nzf_list = nzo.nzf_list() sab_nzo_id_history = None sorted_rar_nzf_list = utils.sorted_rar_nzf_file_list(nzf_list) # TODO # If we cant find any rars in the queue, we have to wait for SAB # and then guess the names... # if len(nzf_list) == 0: # iscanceled = get_nzf(folder, sab_nzo_id, None) is_movie_in_rar = True if len(sorted_rar_nzf_list) == 0: # look for other playable files multi_nzf_list = sorted_nzf_list = utils.sorted_movie_nzf_file_list(nzf_list) if len(multi_nzf_list) > 0: is_movie_in_rar = False else: multi_nzf_list = utils.sorted_multi_arch_nzf_list(sorted_rar_nzf_list) sorted_nzf_list = sorted_rar_nzf_list clean_sorted_nzf_list = utils.nzf_diff_list(sorted_nzf_list, multi_nzf_list) if len(multi_nzf_list) > 0: # Loop though all multi archives and add file to the play_list = [] for nzf in multi_nzf_list: if sab_nzo_id is not None: response = set_streaming(sab_nzo_id) log("pre_play: set_streaming: %s" % response) t = Thread(target=nzf_to_bottom, args=(sab_nzo_id, nzf_list, sorted_nzf_list,)) t.start() iscanceled = get_nzf(folder, sab_nzo_id, nzf) if iscanceled: break else: if is_movie_in_rar: # RAR ANALYSYS # in_rar_file_list = utils.rar_filenames(folder, nzf.filename) movie_list = utils.sort_filename(in_rar_file_list) log("pre_play: folder: %s nzf.filename: %s in_rar_file_list: %s" % (folder, nzf.filename, in_rar_file_list)) else: movie_list = [os.path.join(folder, nzf.filename)] # Make sure we have a movie if not (len(movie_list) >= 1): utils.notification("Not a movie!") log("pre_play: no movie in movie_list") break # Who needs sample? movie_no_sample_list = utils.no_sample_list(movie_list) # If auto play is enabled we skip samples in the play_list if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST: for movie_file in movie_no_sample_list: play_list.append(nzf.filename) play_list.append(movie_file) else: for movie_file in movie_list: play_list.append(nzf.filename) play_list.append(movie_file) # If the movie is a .mkv or .mp4 we need the last rar if utils.is_movie_mkv(movie_list) and sab_nzo_id and is_movie_in_rar: # If we have a sample or other file, the second rar is also needed.. if len(in_rar_file_list) > 1: second_nzf = clean_sorted_nzf_list[1] iscanceled = get_nzf(folder, sab_nzo_id, second_nzf) last_nzf = clean_sorted_nzf_list[-1] iscanceled = get_nzf(folder, sab_nzo_id, last_nzf) if iscanceled: break if iscanceled: log("pre_play: get_nzf: canceled") return else: rar_file_list = [x.filename for x in sorted_nzf_list] if (len(rar_file_list) >= 1) or (not is_movie_in_rar and len(movie_list) >= 1): if AUTO_PLAY and ( mode is None or mode is MODE_STRM): video_params = dict() if not mode: video_params['mode'] = MODE_AUTO_PLAY else: video_params['mode'] = MODE_STRM video_params['play_list'] = utils.quote_plus(';'.join(play_list)) video_params['file_list'] = utils.quote_plus(';'.join(rar_file_list)) video_params['folder'] = utils.quote_plus(folder) video_params['nzoid'] = sab_nzo_id video_params['nzoidhistory'] = sab_nzo_id_history return play_video(video_params) else: return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history) else: utils.notification("No rar\'s in the NZB!") log("pre_play: no rar\'s in the NZB") return else: utils.notification("No playable files found!") log("pre_play: no playable files found") #log("the_end(folder, True, sab_nzo_id, sab_nzo_id_history): %s, %s, %s" % (folder, sab_nzo_id, sab_nzo_id_history)) the_end(folder, True, sab_nzo_id, sab_nzo_id_history) return