-
Notifications
You must be signed in to change notification settings - Fork 1
/
ripdir
executable file
·87 lines (81 loc) · 2.91 KB
/
ripdir
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
#!/usr/bin/env python3
# Copyright 2019 by Chris Osborn <[email protected]>
#
# This file is part of viddin.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License at <http://www.gnu.org/licenses/> for
# more details.
import argparse
import os, glob
import sys
from viddin import viddin
FLAGS="--lang=eng --bluray"
def build_argparser():
parser = argparse.ArgumentParser()
parser.add_argument("dirs", nargs="+", help="input files")
parser.add_argument("--flags", default=FLAGS, help="flags to pass to rip-video")
parser.add_argument("--outtype", default=".mkv", help="file type to rip to")
parser.add_argument("--dryrun", action="store_true", help="only print actions, don't rip")
parser.add_argument("--subdirs", action="store_true", help="keep subdirectory organization")
parser.add_argument("--debug", action="store_true", help="pass debug flag")
return parser
def main():
args = build_argparser().parse_args()
for d in args.dirs:
basedir = os.path.basename(os.path.abspath(d))
files = []
for ext in ("*.mkv", "*.mp4", "*.webm"):
files.extend(glob.glob(os.path.join(d, ext)))
for file in sorted(files):
output = video = os.path.basename(file)
if not args.subdirs:
if not output.startswith(basedir):
output = basedir + "_" + video
else:
output = os.path.join(basedir, video)
os.makedirs(basedir, exist_ok=True)
p, e = os.path.splitext(output)
output = p + args.outtype
log = p + ".log"
doRip = False
if not os.path.exists(log):
print("Not ripped yet")
doRip = True
else:
if os.path.exists(output):
inlength = viddin.getLength(file)
outlength = viddin.getLength(output)
diff = inlength - outlength
if diff > 20 or diff / inlength > 0.03:
print("Short", diff, diff / inlength)
doRip = True
else:
with open(log) as f:
lines = f.read().splitlines()
if len(lines) < 2 or lines[-2] != "Encode done!":
print("Incomplete")
doRip = True
if doRip:
print(output)
cmd = "rip-video " + args.flags
if args.debug:
cmd += " --debug"
cmd += " \"%s\" \"%s\"" % (file, output)
print(cmd)
if not args.dryrun:
result = os.WEXITSTATUS(os.system(cmd))
if result != 0:
exit(result)
else:
print(output, "Skipped")
return
if __name__ == '__main__':
exit(main() or 0)