Improve ripping
This commit is contained in:
parent
d83ad24d5d
commit
3a85f69bc3
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user