def wait_for_nzf(folder, sab_nzo_id, nzf): log("wait_for_nzf: folder: %s sab_nzo_id: %s nzf.filename: %s" % (folder, sab_nzo_id, nzf.filename)) iscanceled = False is_rar_found = False # If rar exist we skip dialogs some_rar = os.path.join(folder, nzf.filename) if utils.exists(some_rar): is_rar_found = True if not is_rar_found: progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Request to SABnzbd succeeded, waiting for ', utils.short_string(nzf.filename)) time_now = time.time() while not is_rar_found: time.sleep(1) if utils.exists(some_rar): # TODO Look for optimization # Wait until the file is written to disk before proceeding size_now = float(nzf.bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = utils.size(some_rar) if size_now != size_later: time.sleep(0.5) size_later = utils.size(some_rar) is_rar_found = True break nzo = Nzo(sab_nzo_id) m_nzf = nzo.get_nzf_id(nzf.nzf_id) percent, label = utils.wait_for_rar_label(nzo, m_nzf, time_now) progressDialog.update(percent, 'Request to SABnzbd succeeded, waiting for', utils.short_string(nzf.filename), label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) # Fix for hang when playing .strm xbmc.Player().stop() xbmc.executebuiltin('Dialog.Close(all, true)') if ret == 0: sabnzbd.nzo_pause(sab_nzo_id) time.sleep(3) delete_ = sabnzbd.nzo_delete_files(sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) utils.notification("Deleting failed") else: utils.notification("Deleting succeeded") elif ret == 1: # allow the previous select dialog to close time.sleep(1) just_download({'nzoid': sab_nzo_id}) return True progressDialog.close() return iscanceled
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
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") return