-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
150 lines (108 loc) · 3.18 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from concurrent.futures import ThreadPoolExecutor
import shutil
import os
import requests
import xmltodict, json
baseurl='http://api.fqzy.cc/api.php/provide/vod/'
u = baseurl+'?ac=videolist&pg='
try:
shutil.rmtree('./zlog')
shutil.rmtree('./zdata')
except Exception as e:
print(e)
try:
os.mkdir('./zlog')
os.mkdir('./zdata')
except Exception as e:
print(e)
def to(n):
try:
res = requests.get(u + str(n), timeout=(5, 10))
a = res.content.decode('utf-8')
b = json.dumps(xmltodict.parse(a), ensure_ascii=False)
fh = open('./zdata/' + str(n) + '.json', 'w', encoding='utf-8')
fh.write(b)
fh.close()
except Exception as e:
print('pg:',n)
print(e)
fh = open('./zlog/' + str(n) + '.err', 'a+', encoding='utf-8')
fh.write(str(e))
fh.write('\n')
fh.close()
print('重发')
to(n)
def getpage():
try:
pgn=int(xmltodict.parse( requests.get(u, timeout=(10, 20)).content.decode('utf-8'))['rss']['list']['@pagecount'])+1
except Exception as e:
getpage()
return pgn
with ThreadPoolExecutor(max_workers=30) as t: # 创建一个 线程池
for i in range(1,getpage()):
t.submit(to, i)
vlist = []
# 总列表
t = {}
# 分类对象
file_names = os.listdir("./zdata/")
# 分页列表
try:
shutil.rmtree('./class')
except Exception as e:
print(e)
# 删除 class
def add(i):
f = open('./zdata/' + i, 'r', encoding='UTF-8')
a = json.loads(f.read())['rss']['list']['video']
f.close()
for c in a:
vlist.append(c)
# 读入 总列表方法
def sp(movielist, size, path, start):
start = start + 1
if (len(movielist) <= 0):
return
b = movielist[:size]
fh = open(path + str(start), 'w', encoding='utf-8')
fh.write(json.dumps(b, ensure_ascii=False))
fh.close()
del movielist[:size]
sp(movielist, size, path, start)
# 递归 写入 分页后的 数据方法
for i in file_names:
add(i)
# 初始分页 汇入总列表
print(len(vlist))
vlist= sorted(vlist,key=lambda a: a['last'] ,reverse=True)
# 排序
# fh = open('./z.json', 'w', encoding='utf-8')
# fh.write(json.dumps(vlist, ensure_ascii=False))
# fh.close()
# # 写出总列表json 到文件 z.json
for i in vlist:
t[i['type']] = []
for j in vlist:
t[j['type']].append(j)
# 生成 总分类 数据
# fh = open('./t.json', 'w', encoding='utf-8')
# fh.write(json.dumps(t, ensure_ascii=False))
# fh.close()
# 写出总列表t.json
for classdirname in t:
os.makedirs('./class/' + classdirname)
# 创建 分类文件夹
classname = os.listdir('./class/')
fh = open('./class/index.json', 'w', encoding='utf-8')
fh.write(json.dumps(classname, ensure_ascii=False))
fh.close()
for movieclass in t:
sp(t[movieclass], 24, './class/' + movieclass + '/', 0)
file_names = os.listdir('./class/' + movieclass + '/')
for num in range(len(file_names)):
file_names[num] = int(file_names[num])
file_names.sort()
fh = open('./class/' + movieclass + '/index.json', 'w', encoding='utf-8')
fh.write(json.dumps(file_names, ensure_ascii=False))
fh.close()
# 创建分类文件夹下的 分页文件