diff --git a/src/args.py b/src/args.py index 413b63b25..b1f55cf3b 100644 --- a/src/args.py +++ b/src/args.py @@ -56,6 +56,7 @@ def parse(self, args, meta): parser.add_argument('-th', '--torrenthash', nargs='*', required=False, help="Torrent Hash to re-use from your client's session directory") parser.add_argument('-nfo', '--nfo', action='store_true', required=False, help="Use .nfo in directory for description") parser.add_argument('-k', '--keywords', nargs='*', required=False, help="Add comma seperated keywords e.g. 'keyword, keyword2, etc'") + parser.add_argument('-kf', '--keep-folder', action='store_true', required=False, help="Keep the folder containing the single file. Works only when supplying a directory as input. For uploads with poor filenames, like some scene.") parser.add_argument('-reg', '--region', nargs='*', required=False, help="Region for discs") parser.add_argument('-a', '--anon', action='store_true', required=False, help="Upload anonymously") parser.add_argument('-st', '--stream', action='store_true', required=False, help="Stream Optimized Upload") diff --git a/src/clients.py b/src/clients.py index c8d5fcba1..14a756d91 100644 --- a/src/clients.py +++ b/src/clients.py @@ -118,8 +118,8 @@ async def is_valid_torrent(self, meta, torrent_path, torrenthash, torrent_client console.log(torrent_path) if os.path.exists(torrent_path): torrent = Torrent.read(torrent_path) - # Reuse if disc and basename matches - if meta.get('is_disc', None) != None: + # Reuse if disc and basename matches or --keep-folder was specified + if meta.get('is_disc', None) != None or (meta['keep_folder'] and meta['isdir']): torrent_filepath = os.path.commonpath(torrent.files) if os.path.basename(meta['path']) in torrent_filepath: valid = True diff --git a/src/prep.py b/src/prep.py index a912ccbad..c53cdaf79 100644 --- a/src/prep.py +++ b/src/prep.py @@ -2060,14 +2060,18 @@ def get_edition(self, video, bdinfo, filelist, manual_edition): def create_torrent(self, meta, path, output_filename, piece_size_max): piece_size_max = int(piece_size_max) if piece_size_max is not None else 0 if meta['isdir'] == True: - os.chdir(path) - globs = glob.glob1(path, "*.mkv") + glob.glob1(path, "*.mp4") + glob.glob1(path, "*.ts") - no_sample_globs = [] - for file in globs: - if not file.lower().endswith('sample.mkv') or "!sample" in file.lower(): - no_sample_globs.append(os.path.abspath(f"{path}{os.sep}{file}")) - if len(no_sample_globs) == 1: - path = meta['filelist'][0] + if meta['keep_folder']: + cli_ui.info('--keep-folder was specified. Using complete folder for torrent creation.') + path = path + else: + os.chdir(path) + globs = glob.glob1(path, "*.mkv") + glob.glob1(path, "*.mp4") + glob.glob1(path, "*.ts") + no_sample_globs = [] + for file in globs: + if not file.lower().endswith('sample.mkv') or "!sample" in file.lower(): + no_sample_globs.append(os.path.abspath(f"{path}{os.sep}{file}")) + if len(no_sample_globs) == 1: + path = meta['filelist'][0] if meta['is_disc']: include, exclude = "", "" else: diff --git a/upload.py b/upload.py index 4b1845a7d..cd2018809 100644 --- a/upload.py +++ b/upload.py @@ -467,7 +467,14 @@ def get_confirmation(meta): if meta.get('unattended', False) == False: get_missing(meta) ring_the_bell = "\a" if config['DEFAULT'].get("sfx_on_prompt", True) == True else "" # \a rings the bell - cli_ui.info_section(cli_ui.yellow, f"Is this correct?{ring_the_bell}") + cli_ui.info(ring_the_bell) + if meta['isdir'] and meta['keep_folder']: + cli_ui.info_section(cli_ui.yellow, f"Uploading with --keep-folder") + kf_confirm = cli_ui.ask_yes_no("You specified --keep-folder. Uploading in folders might not be allowed. Are you sure you want to proceed?", default=False) + if not kf_confirm: + cli_ui.info('Aborting...') + exit() + cli_ui.info_section(cli_ui.yellow, f"Is this correct?") cli_ui.info(f"Name: {meta['name']}") confirm = cli_ui.ask_yes_no("Correct?", default=False) else: