def wait_for_rar(folder, sab_nzo_id, some_rar): isCanceled = False is_rar_found = False # If some_rar exist we skip dialogs for file, bytes in utils.sorted_rar_file_list(utils.list_dir(folder)): if file == some_rar: is_rar_found = True break if not is_rar_found: seconds = 0 progressDialog = xbmcgui.DialogProgress() progressDialog.create('NZBS', 'Request to SABnzbd succeeded, waiting for ', some_rar) while not is_rar_found: seconds += 1 time.sleep(1) dirList = utils.sorted_rar_file_list(utils.list_dir(folder)) for file, bytes in dirList: if file == some_rar: path = os.path.join(folder,file) # Wait until the file is written to disk before proceeding size_now = int(bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = os.stat(path).st_size if size_now != size_later: time.sleep(0.5) size_later = os.stat(path).st_size is_rar_found = True break label = str(seconds) + " seconds" # TODO # Shorten some_rar if to long for the dialog window progressDialog.update(0, 'Request to SABnzbd succeeded, waiting for', some_rar, label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) if ret == 0: pause = SABNZBD.pause('',sab_nzo_id) time.sleep(3) delete_ = SABNZBD.delete_queue('',sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) xbmc.executebuiltin('Notification("NZBS","Deleting failed")') else: xbmc.executebuiltin('Notification("NZBS","Deleting succeeded")') iscanceled = True return iscanceled if ret == 1: iscanceled = True xbmc.executebuiltin('Notification("NZBS","Downloading")') return iscanceled progressDialog.close() return isCanceled
def pre_play(nzbname, mode = None): iscanceled = False folder = INCOMPLETE_FOLDER + nzbname sab_nzo_id = SABNZBD.nzo_id(nzbname) file_list = utils.list_dir(folder) sab_file_list = [] multi_arch_list = [] if sab_nzo_id is None: sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname) else: sab_file_list = SABNZBD.file_list(sab_nzo_id) file_list.extend(sab_file_list) sab_nzo_id_history = None file_list = utils.sorted_rar_file_list(file_list) multi_arch_list = utils.sorted_multi_arch_list(file_list) # Loop though all multi archives and add file to the play_list = [] for arch_rar, byte in multi_arch_list: if sab_nzo_id is not None: t = Thread(target=to_bottom, args=(sab_nzo_id, sab_file_list, file_list,)) t.start() iscanceled = get_rar(folder, sab_nzo_id, arch_rar) if iscanceled: break else: if sab_nzo_id: set_streaming(sab_nzo_id) # TODO is this needed? time.sleep(1) # RAR ANALYSYS # in_rar_file_list = utils.rar_filenames(folder, arch_rar) movie_list = utils.sort_filename(in_rar_file_list) # Make sure we have a movie if not (len(movie_list) >= 1): xbmc.executebuiltin('Notification("NZBS","Not a movie!")') 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(arch_rar) play_list.append(movie_file) else: for movie_file in movie_list: play_list.append(arch_rar) play_list.append(movie_file) # If the movie is a .mkv we need the last rar if utils.is_movie_mkv(movie_list) and sab_nzo_id: # If we have a sample or other file, the second rar is also needed.. if len(in_rar_file_list) > 1: second_rar = utils.find_rar(file_list, 0) iscanceled = get_rar(folder, sab_nzo_id, second_rar) last_rar = utils.find_rar(file_list, -1) iscanceled = get_rar(folder, sab_nzo_id, last_rar) if iscanceled: break if iscanceled: return else: rar_file_list = [x[0] for x in file_list] if (len(rar_file_list) >= 1): if AUTO_PLAY and ( mode is None or mode is MODE_JSONRPC): video_params = dict() if not mode: video_params['mode'] = MODE_AUTO_PLAY else: video_params['mode'] = MODE_JSONRPC video_params['play_list'] = urllib.quote_plus(';'.join(play_list)) video_params['file_list'] = urllib.quote_plus(';'.join(rar_file_list)) video_params['folder'] = urllib.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: xbmc.executebuiltin('Notification("NZBS","No rar\'s in the NZB!!")') return
def wait_for_rar(folder, sab_nzo_id, some_rar): isCanceled = False is_rar_found = False # If some_rar exist we skip dialogs for file, bytes in utils.sorted_rar_file_list(utils.list_dir(folder)): if file == some_rar: is_rar_found = True break if not is_rar_found: seconds = 0 progressDialog = xbmcgui.DialogProgress() progressDialog.create('NZBS', 'Request to SABnzbd succeeded, waiting for ', utils.short_string(some_rar)) while not is_rar_found: seconds += 1 time.sleep(1) dirList = utils.sorted_rar_file_list(utils.list_dir(folder)) for file, bytes in dirList: if file == some_rar: path = os.path.join(folder, file) # Wait until the file is written to disk before proceeding size_now = int(bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = os.stat(path).st_size if size_now != size_later: time.sleep(0.5) size_later = os.stat(path).st_size is_rar_found = True break label = str(seconds) + " seconds" progressDialog.update(0, 'Request to SABnzbd succeeded, waiting for', utils.short_string(some_rar), label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) if ret == 0: pause = SABNZBD.pause('', sab_nzo_id) time.sleep(3) delete_ = SABNZBD.delete_queue('', sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) xbmc.executebuiltin( 'Notification("NZBS","Deleting failed")') else: xbmc.executebuiltin( 'Notification("NZBS","Deleting succeeded")') iscanceled = True return iscanceled if ret == 1: iscanceled = True xbmc.executebuiltin('Notification("NZBS","Downloading")') return iscanceled progressDialog.close() return isCanceled
def pre_play(nzbname, mode=None): iscanceled = False folder = INCOMPLETE_FOLDER + nzbname sab_nzo_id = SABNZBD.nzo_id(nzbname) file_list = utils.list_dir(folder) sab_file_list = [] multi_arch_list = [] if sab_nzo_id is None: sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname) else: sab_file_list = SABNZBD.file_list(sab_nzo_id) file_list.extend(sab_file_list) sab_nzo_id_history = None file_list = utils.sorted_rar_file_list(file_list) multi_arch_list = utils.sorted_multi_arch_list(file_list) # Loop though all multi archives and add file to the play_list = [] for arch_rar, byte in multi_arch_list: if sab_nzo_id is not None: t = Thread(target=to_bottom, args=( sab_nzo_id, sab_file_list, file_list, )) t.start() iscanceled = get_rar(folder, sab_nzo_id, arch_rar) if iscanceled: break else: if sab_nzo_id: set_streaming(sab_nzo_id) # TODO is this needed? time.sleep(1) # RAR ANALYSYS # in_rar_file_list = utils.rar_filenames(folder, arch_rar) movie_list = utils.sort_filename(in_rar_file_list) # Make sure we have a movie if not (len(movie_list) >= 1): xbmc.executebuiltin('Notification("NZBS","Not a movie!")') 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(arch_rar) play_list.append(movie_file) else: for movie_file in movie_list: play_list.append(arch_rar) play_list.append(movie_file) # If the movie is a .mkv we need the last rar if utils.is_movie_mkv(movie_list) and sab_nzo_id: # If we have a sample or other file, the second rar is also needed.. if len(in_rar_file_list) > 1: second_rar = utils.find_rar(file_list, 0) iscanceled = get_rar(folder, sab_nzo_id, second_rar) last_rar = utils.find_rar(file_list, -1) iscanceled = get_rar(folder, sab_nzo_id, last_rar) if iscanceled: break if iscanceled: return else: rar_file_list = [x[0] for x in file_list] if (len(rar_file_list) >= 1): if AUTO_PLAY and (mode is None or mode is MODE_JSONRPC): video_params = dict() if not mode: video_params['mode'] = MODE_AUTO_PLAY else: video_params['mode'] = MODE_JSONRPC video_params['play_list'] = urllib.quote_plus( ';'.join(play_list)) video_params['file_list'] = urllib.quote_plus( ';'.join(rar_file_list)) video_params['folder'] = urllib.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: xbmc.executebuiltin( 'Notification("NZBS","No rar\'s in the NZB!!")') return