-
Notifications
You must be signed in to change notification settings - Fork 1
/
dvdtoiso
executable file
·59 lines (50 loc) · 1.85 KB
/
dvdtoiso
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import argparse
import os, sys
import subprocess
def build_argparser():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("dvd", nargs="?", default="/dev/dvd", help="dvd device")
parser.add_argument("output", help="file to write iso to")
parser.add_argument("--flag", action="store_true", help="flag to do something")
return parser
def main():
args = build_argparser().parse_args()
cmd = ["isoinfo", "-d", "-i", args.dvd]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
pstr = process.stdout.read()
process.stdout.close()
pstr = pstr.decode("utf-8")
rows = pstr.split("\n")
if not pstr:
print("Failed to get DVD info")
exit(1)
for row in rows:
if row.startswith("Logical block size is:"):
block_size = int(row.split()[-1])
elif row.startswith("Volume size is:"):
block_count = int(row.split()[-1])
print("Copying %i blocks of size %i from %s to %s" %
(block_count, block_size, args.dvd, args.output))
# Switched to using ddrescue with dvdcss support built in
# # Put dvd drive into decrypt mode:
# cmd = ["cvlc", "--run-time", "6", "--start-time", "16", "dvd://" + args.dvd + "#4",
# "vlc://quit"]
# res = subprocess.call(cmd)
# if res != -11:
# print("Unable to run cvlc", res)
# print(cmd)
# exit(1)
# os.system("reset")
base, ext = os.path.splitext(args.output)
# cmd = ["dd", "if=" + args.dvd, "of=" + args.output,
# "bs=" + str(block_size), "count=" + str(block_count)]
cmd = ["ddrescue",
"--sector-size=" + str(block_size),
"--size=" + str(block_count * block_size),
args.dvd, args.output, base + ".ddlog"]
subprocess.call(cmd)
return
if __name__ == '__main__':
exit(main() or 0)