From 3a85f69bc3a6b21e1db12d4d77ac5e10015ffe2d Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Mon, 6 Mar 2023 10:44:55 +0100 Subject: [PATCH] Improve ripping --- ripper/rip_dvd.py | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/ripper/rip_dvd.py b/ripper/rip_dvd.py index 7d7e66b..43848df 100755 --- a/ripper/rip_dvd.py +++ b/ripper/rip_dvd.py @@ -16,8 +16,8 @@ LOGFILE = "rip.log" NOTIFICATION_SOUND = "bell.oga" SERIES_TITLE_REGEX = r"S\d+[ _]?E(\d+)-(\d+)$" -MAX_FILENAME_LEN_IN_TMP = 30 # dvdbackup cuts name of output files at 33 chars -WAIT_FOR_DEVICE_TIME_SECONDS = 1 +MAX_FILENAME_LEN_IN_TMP = 25 # dvdbackup cuts name of output files at 33 chars +WAIT_FOR_DEVICE_TIME_SECONDS = 3 def main(): @@ -38,6 +38,7 @@ def main(): if args.wait: wait_for_dev_to_exist(args) + wait_for_dev_to_be_readable(args) success = rip_to_tmp_dir(args) program_execution_time_str = get_program_execution_time_str(program_start_time) @@ -125,17 +126,45 @@ def wait_for_dev_to_exist(args): time.sleep(WAIT_FOR_DEVICE_TIME_SECONDS) +def wait_for_dev_to_be_readable(args): + while not is_dvd_readable(args): + print( + f"Device {args.dev} found, but not readable. Waiting {WAIT_FOR_DEVICE_TIME_SECONDS} sec..." + ) + time.sleep(WAIT_FOR_DEVICE_TIME_SECONDS) + + +def is_dvd_readable(args): + command = create_info_command(args) + proc = subprocess.run(command, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + return proc.returncode != 255 + + def rip_to_tmp_dir(args) -> bool: """Returns: success of command""" command = create_rip_command(args, TMP_DIR) - proc = subprocess.run(command, shell=True, capture_output=False) + proc = subprocess.run(command) return proc.returncode == 0 +def create_info_command(args): + return ["dvdbackup", "-i", args.dev, "-I"] + def create_rip_command(args, dest): - shortened_title = args.title[:MAX_FILENAME_LEN_IN_TMP] - return f"dvdbackup -v -p -i '{args.dev}' -o '{dest}' -M -n \"{shortened_title}\"" + shortened_title = shorten_title(args) + return [ + "dvdbackup", + "-v", + "-p", + "-i", + args.dev, + "-o", + dest, + "-M", + "-n", + shortened_title, + ] def get_program_execution_time_str(program_start_time): @@ -168,13 +197,17 @@ def send_notification(text): def mv_ripped_from_tmp_to_ripped_dir(args): - shortened_title = args.title[:MAX_FILENAME_LEN_IN_TMP] + shortened_title = shorten_title(args) src = os.path.join(TMP_DIR, shortened_title) dst = os.path.join(RIPPED_DIR, args.type, args.title) shutil.move(src, dst) +def shorten_title(args): + return args.title[-MAX_FILENAME_LEN_IN_TMP:] + + def delete_tmp_dir(): try: os.rmdir(os.path.join(TMP_DIR))