Add wait for dvd device
This commit is contained in:
parent
b29131d45f
commit
d83ad24d5d
@ -17,6 +17,7 @@ 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
|
||||
|
||||
|
||||
def main():
|
||||
@ -35,6 +36,9 @@ def main():
|
||||
)
|
||||
exit(1)
|
||||
|
||||
if args.wait:
|
||||
wait_for_dev_to_exist(args)
|
||||
|
||||
success = rip_to_tmp_dir(args)
|
||||
program_execution_time_str = get_program_execution_time_str(program_start_time)
|
||||
if success:
|
||||
@ -66,6 +70,10 @@ def parse_args():
|
||||
default=DEFAULT_DVD_DEVICE,
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--wait", help=f"Wait for dvd device to exist.", action="store_true"
|
||||
)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@ -109,6 +117,14 @@ def write_to_logfile(args, tag):
|
||||
file.write(log_line + "\n")
|
||||
|
||||
|
||||
def wait_for_dev_to_exist(args):
|
||||
while not os.path.exists(args.dev):
|
||||
print(
|
||||
f"Device {args.dev} not found. Waiting {WAIT_FOR_DEVICE_TIME_SECONDS} sec..."
|
||||
)
|
||||
time.sleep(WAIT_FOR_DEVICE_TIME_SECONDS)
|
||||
|
||||
|
||||
def rip_to_tmp_dir(args) -> bool:
|
||||
"""Returns: success of command"""
|
||||
command = create_rip_command(args, TMP_DIR)
|
||||
@ -119,7 +135,7 @@ def rip_to_tmp_dir(args) -> bool:
|
||||
|
||||
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}"
|
||||
return f"dvdbackup -v -p -i '{args.dev}' -o '{dest}' -M -n \"{shortened_title}\""
|
||||
|
||||
|
||||
def get_program_execution_time_str(program_start_time):
|
||||
|
Loading…
x
Reference in New Issue
Block a user