-
Notifications
You must be signed in to change notification settings - Fork 1
/
rip-series
executable file
·101 lines (83 loc) · 2.9 KB
/
rip-series
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
import argparse
import os
import subprocess
import stat
import viddin
def build_argparser():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("first", help="number of first episode")
parser.add_argument("sources", nargs="+", help="title numbers or chapters to rip")
parser.add_argument("--dvd", default="/dev/dvd", help="dvd device")
parser.add_argument("--extension", default="mkv",
help="extension to use for output, default is mkv")
parser.add_argument("--split-chapters", action="store_true",
help="each chapter is its own episode")
parser.add_argument("--title",
help="rip only this title, sources are the chapters of each episode")
parser.add_argument("--debug", action="store_true", help="print debug info")
return parser
def main():
args, unused = build_argparser().parse_known_args()
ripdir = os.path.dirname(__file__)
os.environ['PATH'] = f"{ripdir}:{os.environ['PATH']}"
if args.extension[0] != '.':
args.extension = "." + args.extension
start = args.first.split('x')
season = int(start[0])
episode = int(start[1])
flags = unused
err = False
sources = []
for source in args.sources:
if os.path.isdir(source):
sources.extend(viddin.videosInDirectory(source))
elif source.isdigit():
sources.append(int(source))
else:
# FIXME - if source is format t:c-c then it is title:chapters
sources.append(source)
media = viddin.Media(args.dvd)
is_dvd = media.isDVD
chap_sources = []
for idx in range(len(sources)):
source = sources[idx]
if args.split_chapters:
expanded = []
media = viddin.Media(args.dvd, titleNumber=source if is_dvd else None)
for chap in range(len(media.chapters) - 1):
chap_args = []
chap_args.extend(["--chapters", str(chap+1)])
if is_dvd:
chap_args.extend(["--title", str(source), args.dvd])
else:
chap_args.append(source)
chap_sources.append(chap_args)
elif args.title:
sources[idx] = ["--title", args.title, "--chapters", f"{sources[idx]}", args.dvd]
elif is_dvd:
sources[idx] = ["--title", f"{sources[idx]}", args.dvd]
if chap_sources:
sources = chap_sources
for idx, source in enumerate(sources):
cmd = ["rip-video"]
cmd.extend(flags)
epid = f"{season}x{episode+idx:02d}{args.extension}"
if isinstance(source, (list, tuple)):
cmd.extend(source)
else:
cmd.append(source)
cmd.append(epid)
if args.debug:
cmd.append("--debug")
print(viddin.listToShell(cmd))
result = subprocess.run(cmd)
if result.returncode:
err = True
break
if not err and is_dvd and stat.S_ISBLK(os.stat(args.dvd).st_mode):
cmd = ["eject", args.dvd]
subprocess.run(cmd)
return
if __name__ == '__main__':
exit(main() or 0)