def process_movie_dir(movie_dir_source: Path): name = movie_dir_source.name pfcs(f"processing: i[{name}] as type b[movie dir]") nfo_loc = find_nfo_file_in_path(movie_dir_source) rar_loc = find_rar_in_path(movie_dir_source) mkv_loc = find_mkv_in_path(movie_dir_source) if not rar_loc and not mkv_loc: pfcs(f"could e[not] find item to process in w[{movie_dir_source}]!") return if rar_loc and mkv_loc: pfcs(f"found e[both] rar and mkv in w[{movie_dir_source}]!") return pfcs(f"found file: i[{mkv_loc or rar_loc}]") dest = determine_movie_destination(name) pfcs(f"destination: i[{dest}]") if rar_loc: if not run.extract(rar_loc, dest, create_dirs=True): return # extract failed if mkv_loc: run.move_file(mkv_loc, dest, create_dirs=True) if nfo_loc: imdb_id = util.parse_imdbid_from_file(nfo_loc) if imdb_id: print( f"found imdb-id: {cstr(imdb_id, 154)}, will create movie.nfo") util_movie.create_movie_nfo(dest, imdb_id) shutil.rmtree(movie_dir_source) print(f'removed {cstr(movie_dir_source, "orange")}')
def process_movie_file(movie_file_path): movie_path = validate_path(movie_file_path) if not movie_file_path: return if not movie_file_path.is_file(): print(f"path {movie_file_path.name} is not a file!") return pfcs(f"processing: i[{movie_file_path.name}] as type b[movie file]") if not movie_file_path.suffix in util.video_extensions(): pfcs(f"could not determine destination for w[{movie_file_path.name}]") return directory = str(movie_file_path.name).replace(movie_file_path.suffix, "") dest = determine_movie_destination(directory) pfcs(f"destination: i[{dest}]") run.move_file(movie_file_path, dest, create_dirs=True)
def process_episode(ep_path: Path): ep_path = validate_path(ep_path) if not ep_path: return dest = determine_episode_destination(ep_path.name) if not dest: pfcs(f"could not determine destination for w[{ep_path}]") return if ep_path.is_dir(): pfcs(f"processing: i[{ep_path.name}] as type b[episode dir]") rar_loc = find_rar_in_path(ep_path) if not run.extract(rar_loc, dest, create_dirs=True): return # extract failed return pfcs(f"processing: i[{ep_path.name}] as type b[episode file]") run.move_file(ep_path, dest, create_dirs=True)
def move_finished_downloads(extensions=util.video_extensions(), delete_source_dir=True, dest_dir=user_download_dir(), pre_rename=True): if not util.is_dir(dest_dir): pfcs(f'destination dir does not exist: e[{dest_dir}]') return count = 0 found_items = find_finished_downloads(extensions=extensions) if not found_items: pfcs( f'found no completed files with extension(s) i<{extensions}> in NZBGet destination path', format_chars=['<', '>']) if found_items: print("processing finished downloads...") for download in found_items: filename = download.name containing_dir = download.parent rename_log_str = "" if pre_rename: pre_result = pre_search_from_file(download.name) if pre_result: filename = f"{pre_result}{download.suffix}" rename_log_str = f"\n renamed i[{filename}]" if move_file(download, dest_dir, new_filename=filename, debug_print=False): pfcs(f'moved i[{download.name}] to g[{dest_dir}]{rename_log_str}') count += 1 if delete_source_dir: shutil.rmtree(containing_dir) pfcs(f'removed w[{containing_dir}]') else: pfcs(f'failed to move e[{download.name}] to w[{dest_dir}]!') pfcs(f"d[{'-' * util.terminal_width()}]") return count
def process_source_item(item_path, dest_path): print(f"filename: {item_path.name}") suffix = "" # ask for title/seas/ep? if "dvdrip.xvid" in item_path.name: suffix = "DVDRip.XviD-MEMETiC" elif item_path.name.startswith("Smyth"): suffix = "SmythEdit" elif item_path.suffix == ".mp4": res = VideoFileMetadata(item_path).res print("> determined resolution:", res) suffix = f"{res}p.WEB-DL" if res != 0 else "WEB-DL" try: season = int(input("enter season: ")) except ValueError: print("requires integer!") return False if 2003 < season > 2020: print("not a valid season!") return False try: episode = int(input("enter episode: ")) except ValueError: print("requires integer!") return False if 1 < episode > 40: print("not a valid episode!") return title_words = input("enter title: ").split() title_str = ".".join([w.capitalize() for w in title_words]) ext = item_path.suffix filename = f"Mythbusters.S{season}E{episode:02d}.{title_str}.{suffix}{ext}" season_dest_path = dest_path / f"S{season}" if not season_dest_path.is_dir(): print("no season path:", season_dest_path) return False print("> moving to", item_path) move_file(item_path, season_dest_path, new_filename=filename) sub_path = item_path.with_suffix(".vtt") if sub_path.is_file(): new_sub_name = f"Mythbusters.S{season}E{episode:02d}.{title_str}.{suffix}.sv.vtt" print("> moving sub to", season_dest_path) move_file(sub_path, season_dest_path, new_filename=new_sub_name) return True
def move_nzbs_from_download(): dest_dir = nzbget_nzb_path() if not util.is_dir(dest_dir): pfcs(f'destination dir does not exist: e[{dest_dir}]') return count = 0 for dir_name, _, file_list in os.walk(user_download_dir()): nzb_files = [Path( dir_name) / file_item for file_item in file_list if file_item.endswith('.nzb')] if not nzb_files: continue for nzb_file in nzb_files: if move_file(nzb_file, dest_dir, debug_print=False): pfcs(f'moved i[{nzb_file.name}] to g[{dest_dir}]') count += 1 else: pfcs(f'failed to move e[{nzb_file.name}] to w[{dest_dir}]!') return count