-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract.py
executable file
·91 lines (78 loc) · 2.55 KB
/
extract.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#! /usr/bin/env python3
import sqlite3
import os
import argparse
con = sqlite3.connect("opensubs.db")
con.row_factory = sqlite3.Row
def save(name, file, path):
with open("{}/{}".format(path, name), "wb") as w:
w.write(file)
def get_range(start, end):
with con:
cur = con.cursor()
cur.execute(
"select * from subz where num >= (?) and num <= (?)",
(
start,
end,
),
)
rows = cur.fetchall()
return rows
def get_single(num):
with con:
cur = con.cursor()
cur.execute("select * from subz where num = (?)", (num,))
row = cur.fetchone()
return row
##save all
##tmp_start=9200000
##while tmp_start >=0:
## rows = get_range(tmp_start-1000, tmp_start)
## tmp_start-=1000
## for row in rows:
## save(row['name'], row['file'])
# examples
##ten = get_range (0, 10)
##one = get_single(1 )
##print(one['name'])
##print('-')
##for row in ten:
## print(row['name'])
#### save(row['name'], row['file'])
if __name__ == "__main__":
print("main")
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--start", help="extract start", required=True)
parser.add_argument(
"-e", "--end", help="extract end (omit to extract one)", required=False
)
parser.add_argument("-p", "--path", help="path", required=False)
args = vars(parser.parse_args())
path = args.get("path") if args.get("path") else "./tmp"
if not os.path.isdir(path):
os.mkdir(path)
if args.get("end"):
rows = get_range(args.get("start"), args.get("end"))
for row in rows:
#print("row.name = " + repr(row["name"]))
# row.name = 'attachment; filename="ghost.in.the.shell.2.innocence.(2004).eng.1cd.(3).zip"'
name = row["name"][22:-1]
num = row["num"]
# 6 million subtitles = 6 000 000
name = f'{num:09d}.{name}'
#print("name = " + repr(name))
save(name, row["file"], path)
else:
row = get_single(args.get("start"))
#save(row["name"], row["file"], path)
# TODO refactor
if True:
#print("row.name = " + repr(row["name"]))
# row.name = 'attachment; filename="ghost.in.the.shell.2.innocence.(2004).eng.1cd.(3).zip"'
name = row["name"][22:-1]
num = row["num"]
# 6 million subtitles = 6 000 000
name = f'{num:09d}.{name}'
#print("name = " + repr(name))
save(name, row["file"], path)