-
Notifications
You must be signed in to change notification settings - Fork 0
/
vuze-unrar.py
executable file
·70 lines (53 loc) · 1.71 KB
/
vuze-unrar.py
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
#!/usr/bin/python3
#
import os
import shutil
import re
from sys import argv
from subprocess import call
RAR_EXT = ".rar"
CAT_PREFIX = "unrar-"
outDir = argv[1]
cat = argv[2]
path = argv[3]
name = argv[4]
def getRarFile(path: str):
if os.path.isfile(path) and path.endswith(".rar"):
return path
files = os.listdir(path)
for file in files:
if file.endswith(".rar"):
return os.path.join(path, file)
def handleZDay(outDir: str, rarFile: str, name: str):
macth = re.search(r"^([^.]*).(\d\d.\d\d.\d\d).(.*).XXX.*", name, re.IGNORECASE)
if not macth:
print("ZDAY: Can't match %s" % name)
return
series = re.sub(r"(([0-9]+)|([A-Z][a-z]*))", r"\1 ", macth.group(1)).strip()
date = macth.group(2).replace(".", "-")
episode = macth.group(3).replace(".", " ")
dir = "%s/video/zday/%s" % (outDir, series)
tmpDir = "%s/tmp" % (dir)
os.makedirs(tmpDir, exist_ok=True)
print("Extracting %s" % rarFile)
call(["unrar", "-o-", "-inul", "x", rarFile], cwd=tmpDir)
videoFile = os.listdir(tmpDir)[0]
src = "%s/%s" % (tmpDir, videoFile)
dest = "%s/%s %s%s" % (dir, date, episode, os.path.splitext(videoFile)[1])
shutil.move(src, dest)
shutil.rmtree(tmpDir)
def extractArchive(rarFile: str, dest: str):
print("Extracting %s to %s" % (rarFile, dest))
os.makedirs(dest, exist_ok=True)
call(["unrar", "-o-", "-inul", "x", rarFile], cwd=dest)
def process(outDir: str, cat: str, path: str, name: str):
if not cat.startswith(CAT_PREFIX):
return
rarFile = getRarFile(path)
if rarFile == None:
return
if cat == "unrar-zday":
handleZDay(outDir, rarFile, name)
else:
extractArchive(rarFile, outDir + "/" + cat[len(CAT_PREFIX):].replace("-", "/"))
process(outDir, cat, path, name)