-
Notifications
You must be signed in to change notification settings - Fork 35
/
biliDanmuDown.py
57 lines (53 loc) · 2.22 KB
/
biliDanmuDown.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
# (C) 2019-2020 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 inspect import currentframe
from traceback import format_exc
def downloadn(cid, r, logg=None):
"下载当前弹幕"
uri = f"https://comment.bilibili.com/{cid}.xml"
try:
if logg is not None:
logg.write(f"GET {uri}", currentframe(), "Download Barrage Request")
re = r.get(uri)
except:
if logg is not None:
logg.write(format_exc(), currentframe(), "Download Barrage Failed")
return -1
re.encoding = 'utf8'
if logg is not None:
if re.ok:
logg.write(f"status = {re.status_code}", currentframe(), "Download Barrage Result")
else:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "Download Barrage Result2")
return re.text if re.ok else -1
def downloadh(cid, r, date, logg=None):
"下载历史弹幕"
uri = f"https://api.bilibili.com/x/v2/dm/history?type=1&date={date}&oid={cid}"
if logg is not None:
logg.write(f"GET {uri}", currentframe(), "Download History Barrage Request")
try:
re = r.get(uri)
except:
if logg is not None:
logg.write(format_exc(), currentframe(), "Download History Barrage Failed")
return -1
if logg is not None:
if re.ok:
logg.write(f"status = {re.status_code}", currentframe(), "Download History Barrage Result")
else:
logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "Download History Barrage Result2")
re.encoding = 'utf8'
return re.text if re.ok else -1