forked from wangwc18/mygoFlaskProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
231 lines (210 loc) · 11.4 KB
/
Copy pathapp.py
File metadata and controls
231 lines (210 loc) · 11.4 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import json
from flask import Flask, render_template, request, send_file, redirect, url_for
import xmltodict
app = Flask(__name__)
mygo_data = {'Av914573114': {'rank': 1,
'title': "「BanG Dream! It's MyGO!!!!!」#1",
'play_time': '150.1万', 'danmaku_num': '9063', 'upload_time': '2023-08-11 19:00:00',
'long': "23:50", 'comment_num': 5670, 'load_danmaku': 3600,
'like': '5.3万', 'coin': '2.8万', 'star': '3.5万', 'share': '2.5万'
},
'Av404602621': {'rank': 2,
'title': "「BanG Dream! It's MyGO!!!!!」#2",
'play_time': '30.1万', 'danmaku_num': '5624', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 638, 'load_danmaku': 3600,
'like': '9653', 'coin': '5086', 'star': '2388', 'share': '750'
},
'Av404618862': {'rank': 3,
'title': "「BanG Dream! It's MyGO!!!!!」#3",
'play_time': '28.1万', 'danmaku_num': '5173', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 746, 'load_danmaku': 3600,
'like': '9897', 'coin': '5490', 'star': '2454', 'share': '415'
},
'Av872091035': {'rank': 4,
'title': "「BanG Dream! It's MyGO!!!!!」#4",
'play_time': '23.4万', 'danmaku_num': '5562', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 266, 'load_danmaku': 3600,
'like': '6545', 'coin': '3634', 'star': '1624', 'share': '415'
},
'Av659528201': {'rank': 5,
'title': "「BanG Dream! It's MyGO!!!!!」#5",
'play_time': '20.7万', 'danmaku_num': '4827', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 277, 'load_danmaku': 3600,
'like': '6263', 'coin': '3412', 'star': '1505', 'share': '354'
},
'Av659536079': {'rank': 6,
'title': "「BanG Dream! It's MyGO!!!!!」#6",
'play_time': '19.9万', 'danmaku_num': '3886', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 262, 'load_danmaku': 3600,
'like': '5952', 'coin': '3357', 'star': '1439', 'share': '320'
},
'Av447061316': {'rank': 7,
'title': "「BanG Dream! It's MyGO!!!!!」#7",
'play_time': '32.2万', 'danmaku_num': '6430', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 1014, 'load_danmaku': 3600,
'like': '9796', 'coin': '6394', 'star': '2332', 'share': '1146'
},
'Av362022045': {'rank': 8,
'title': "「BanG Dream! It's MyGO!!!!!」#8",
'play_time': '37.6万', 'danmaku_num': '6454', 'upload_time': '2023-08-11 19:00:00',
'long': "23:40", 'comment_num': 2060, 'load_danmaku': 3600,
'like': '1.2万', 'coin': '5879', 'star': '2586', 'share': '1506'
},
'Av232235089': {'rank': 9,
'title': "「BanG Dream! It's MyGO!!!!!」#9",
'play_time': '49.9万', 'danmaku_num': '7770', 'upload_time': '2023-08-13 22:49:03',
'long': "23:40", 'comment_num': 5079, 'load_danmaku': 3600,
'like': '1.9万', 'coin': '9793', 'star': '3723', 'share': '2318'
},
'Av702479882': {'rank': 10,
'title': "「BanG Dream! It's MyGO!!!!!」#10",
'play_time': '71.0万', 'danmaku_num': '1.2万', 'upload_time': '2023-08-20 19:00:00',
'long': "23:40", 'comment_num': 5672, 'load_danmaku': 3600,
'like': '3.0万', 'coin': '2.3万', 'star': '7348', 'share': '4356'
},
'Av275135823': {'rank': 11,
'title': "「BanG Dream! It's MyGO!!!!!」#11",
'play_time': '55.0万', 'danmaku_num': '1.0万', 'upload_time': '2023-08-27 19:00:00',
'long': "23:40", 'comment_num': 3278, 'load_danmaku': 3600,
'like': '2.5万', 'coin': '1.4万 ', 'star': '4692', 'share': '2459'
},
'Av703057448': {'rank': 12,
'title': "「BanG Dream! It's MyGO!!!!!」#12",
'play_time': '51.6万', 'danmaku_num': '8875', 'upload_time': '2023-09-03 19:00:00',
'long': "23:40", 'comment_num': 4007, 'load_danmaku': 3600,
'like': '2.2万', 'coin': '1.4万', 'star': '4334', 'share': '2149'
},
'Av618134604': {'rank': 13,
'title': "「BanG Dream! It's MyGO!!!!!」#1-#12 总集篇",
'play_time': '35.5万', 'danmaku_num': '5513', 'upload_time': '2023-09-07 21:30:00',
'long': "23:40", 'comment_num': 2234, 'load_danmaku': 3600,
'like': '1.5万', 'coin': '6202', 'star': '3568', 'share': '2545'
},
'Av575884077': {'rank': 14,
'title': "「BanG Dream! It's MyGO!!!!!」#13",
'play_time': '94.5万', 'danmaku_num': '2.4万', 'upload_time': '2023-09-14 21:35:00',
'long': "23:40", 'comment_num': 13494, 'load_danmaku': 3600,
'like': '4.3万', 'coin': '3.9万', 'star': '1.3万', 'share': '7674'
},
}
@app.route('/video/<vid>')
def video_player(vid):
if vid not in mygo_data.keys():
return
return render_template("main.html", vid=vid, videos=mygo_data)
@app.route('/')
def main_page():
return redirect('/video/Av914573114')
@app.route('/mygo')
def mygo_page():
vid = request.args.get("vid")
if vid not in mygo_data.keys():
vid = 'Av914573114'
return render_template("mygo.html", vid=vid, videos=mygo_data)
@app.route('/favicon.ico')
def favicon():
return send_file('static/favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/api/comment')
def get_comment():
vid = request.args.get("vid")
rank = mygo_data[vid]['rank']
cid = request.args.get("cid")
page = request.args.get("page")
if cid == '1':
json_file = open('comment_hot_json/' + str(rank) + '/' + str(page) + '.json', 'r', encoding='UTF-8')
elif cid == '2':
json_file = open('comment_new_json/' + str(rank) + '/' + str(page) + '.json', 'r', encoding='UTF-8')
else:
return
json_str = json_file.read()
headers = {"Content-Type": "application/json"}
json_file.close()
return json_str, 200, headers
@app.route("/api/video")
def video_server():
vid = request.args.get("vid")
if vid not in mygo_data.keys():
return
rank = mygo_data[vid]['rank']
return send_file('video/' + str(rank) + '.mp4')
# @app.route("/api/danmu", methods=['GET'])
# def danmu_server():
# vid = request.args.get("id")
# if vid not in mygo_data.keys():
# return
# rank = mygo_data[vid]['rank']
# xml_file = open('danmaku/' + str(rank) + '.xml', 'r', encoding="UTF-8")
# parsed_data = xmltodict.parse(xml_file.read())
# xml_file.close()
# json_conversion = parsed_data['i']['d']
# json_out = {'code': 1, 'danmaku': []}
# for danmu in json_conversion:
# list_param = danmu['@p'].split(',')
# hex_color = hex(int(list_param[3]))[2:]
# hex_color = '#' + '0' * (6 - len(hex_color)) + hex_color
# one_danmaku = {"__v": 0, "author": list_param[6], "time": float(list_param[0]), "text": danmu['#text'],
# "color": hex_color, "type": "right"}
# if list_param[1] == '4':
# one_danmaku['type'] = "bottom"
# if list_param[1] == '4':
# one_danmaku['type'] = "top"
# json_out['danmaku'].append(one_danmaku)
# json_str = json.dumps(json_out, ensure_ascii=False)
# headers = {"Content-Type": "application/json"}
# return json_str, 200, headers
@app.route("/api/danmu", methods=['GET'])
def danmu_server():
vid = request.args.get("id")
if vid not in mygo_data.keys():
return
rank = mygo_data[vid]['rank']
xml_file = open('danmaku/' + str(rank) + '.xml', 'r', encoding="UTF-8")
parsed_data = xmltodict.parse(xml_file.read())
xml_file.close()
json_conversion = parsed_data['i']['d']
json_out = {'code': 1, 'data': []}
for danmu in json_conversion:
list_param = danmu['@p'].split(',')
hex_color = hex(int(list_param[3]))[2:]
hex_color = '#' + '0' * (6 - len(hex_color)) + hex_color
one_danmaku = {"author": list_param[6], "time": float(list_param[0]), "text": danmu['#text'],
"color": hex_color, "type": "scroll"}
if list_param[1] == '4':
one_danmaku['type'] = "bottom"
if list_param[1] == '5':
one_danmaku['type'] = "top"
json_out['data'].append(one_danmaku)
json_out['data'] = sorted(json_out['data'], key=lambda x: x['time'])
json_str = json.dumps(json_out, ensure_ascii=False)
headers = {"Content-Type": "application/json"}
return json_str, 200, headers
# @app.route("/api/danmu", methods=['POST'])
# def danmu_post():
# data = json.loads(request.get_data())
# vid = data["player"]
# if vid not in mygo_data.keys():
# return
# rank = mygo_data[vid]['rank']
# xml_file = open('danmaku/' + str(rank) + '.xml', 'r', encoding="UTF-8")
# parsed_data = xmltodict.parse(xml_file.read())
# xml_file.close()
# json_conversion = parsed_data['i']['d']
# json_out = {'code': 1, 'danmaku': []}
# for danmu in json_conversion:
# list_param = danmu['@p'].split(',')
# hex_color = hex(int(list_param[3]))[2:]
# hex_color = '#' + '0' * (6 - len(hex_color)) + hex_color
# one_danmaku = {"__v": 0, "author": list_param[6], "time": float(list_param[0]), "text": danmu['#text'],
# "color": hex_color, "type": "right"}
# if list_param[1] == '4':
# one_danmaku['type'] = "bottom"
# if list_param[1] == '4':
# one_danmaku['type'] = "top"
# json_out['danmaku'].append(one_danmaku)
# json_out['danmaku'].append({"__v": 0, "author": '1', "time": data["time"], "text": data["text"],
# "color": data["color"], "type": data["type"]})
# json_str = json.dumps(json_out, ensure_ascii=False)
# headers = {"Content-Type": "application/json"}
# return json_str, 200, headers
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)