-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_dict_constructor.py
116 lines (101 loc) · 3.98 KB
/
video_dict_constructor.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
from time import time
from consts import *
def new_video_dict(response: dict)-> dict:
current_timestamp = int( time() )
video_dict = {
"TYPE": "VIDEO_LATEST_DATA",
"VERSION": VIDEO_LATEST_DATA_VERSION,
"bvid": response["data"]["bvid"],
"timestamp": current_timestamp,
"avaliable_time_intervals":[
{
"start": current_timestamp,
"end": current_timestamp
}
],
"popularity": {
"requested_ips" : [],
"logging_interval": 60,
"next_log": 0,
"logging_end": 1608875287
},
"statics": {
"aid": response["data"]["aid"],
"ownermid": response["data"]["owner"]["mid"],
"pubdate": response["data"]["pubdate"]
},
"semi-statics": {
"latest": {
"title": response["data"]["title"],
"desc": response["data"]["desc"],
"pages": [page["part"] for page in response["data"]["pages"]],
"pic": response["data"]["pic"],
"ownerface": response["data"]["owner"]["face"]
},
"changes": [
]
},
"stats": {
"view": response["data"]["stat"]["view"],
"danmaku": response["data"]["stat"]["danmaku"],
"reply": response["data"]["stat"]["reply"],
"favorite": response["data"]["stat"]["favorite"],
"coin": response["data"]["stat"]["coin"],
"share": response["data"]["stat"]["share"],
"like": response["data"]["stat"]["like"]
},
"dynamics": {
"TYPE": "VIDEO_DYNAMIC_CHANGELOG",
"VERSION": "1.0",
"bvid": response["data"]["bvid"],
"start": current_timestamp,
"end": current_timestamp,
"basis": {
"view": response["data"]["stat"]["view"],
"danmaku": response["data"]["stat"]["danmaku"],
"reply": response["data"]["stat"]["reply"],
"favorite": response["data"]["stat"]["favorite"],
"coin": response["data"]["stat"]["coin"],
"share": response["data"]["stat"]["share"],
"like": response["data"]["stat"]["like"]
},
"changes":[
]
}
}
return video_dict
def update_video_dict(response: dict, video_dict: dict)-> None:
current_timestamp = int( time() )
# Update timestamps
video_dict["timestamp"] = current_timestamp
video_dict["avaliable_time_intervals"][-1]["end"] = current_timestamp
video_dict["dynamics"]["end"] = current_timestamp
# Update semi-statics
new_semi_statics = {
"title": response["data"]["title"],
"desc": response["data"]["desc"],
"pages": [page["part"] for page in response["data"]["pages"]],
"pic": response["data"]["pic"],
"ownerface": response["data"]["owner"]["face"]
}
for field_name in new_semi_statics:
if new_semi_statics[field_name] != \
video_dict["semi-statics"]["latest"][field_name]:
changelog = {
"timestamp": current_timestamp,
"field_name": field_name,
"old": video_dict["semi-statics"]["latest"][field_name],
"new": new_semi_statics[field_name]
}
video_dict["semi-statics"]["changes"].append(changelog)
video_dict["semi-statics"]["latest"][field_name] = new_semi_statics[field_name]
# Update dynamics
changelog = {
"timestamp": current_timestamp
}
for field_name in video_dict["stats"]:
diff = response["data"]["stat"][field_name] - video_dict["stats"][field_name]
if diff != 0:
changelog[field_name] = diff
video_dict["stats"][field_name] += diff
video_dict["dynamics"]["changes"].append(changelog)