-
Notifications
You must be signed in to change notification settings - Fork 35
/
acfunDanmu.py
63 lines (59 loc) · 2.43 KB
/
acfunDanmu.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
# (C) 2019-2021 lifegpc
# This file is part of bili.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from hashl import crc32
from requests import Session
from Logger import Logger
from inspect import currentframe
def convertToBiliVer(dm: dict) -> dict:
return {"t": dm["body"], "mod": dm["mode"], "fs": dm["size"], "fc": dm["color"], "ut":
round(dm["createTime"] / 1000), "dp": dm["danmakuType"], "ti":
dm["position"] / 1000, "si": crc32(dm["userId"]), "ri": dm["danmakuId"]}
def getDanmuList(r: Session, rid: str, totalCount: int, se: dict, ip: dict, logg: Logger = None) -> list:
rel = []
page = 0
pageLimit = 40
if 'mxd' in se:
pageLimit = se['mxd']
if 'mxd' in ip:
pageLimit = ip['mxd']
if logg:
logg.write(f"pageLimit = {pageLimit}", currentframe(), "Acfun Danmu Para")
while pageLimit <= 0 or page < pageLimit:
page += 1
url = "https://www.acfun.cn/rest/pc-direct/new-danmaku/list"
data = {"resourceId": rid, "resourceType": "9", "enableAdvanced": "true",
"pcursor": str(page), "count": "200", "sortType": "1", "asc": "false"}
if logg:
logg.write(f"POST {url}\ndata = {data}", currentframe(), "Get Acfun Danmu Page")
re = r.post(url, data)
re.encoding = 'utf8'
if logg:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "Acfun Danme Page Result")
re = re.json()
if re['result'] != 0:
print(f"{re['result']} {re['error_msg']}")
break
if len(re['danmakus']) == 0:
break
rel += re['danmakus']
if totalCount is None:
totalCount = re['totalCount']
if len(rel) >= totalCount:
break
rel2 = []
for i in rel:
rel2.append(convertToBiliVer(i))
return rel2