Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Commit ee29afd

Browse files
authored
feat: add live info (#43)
1 parent 165cf50 commit ee29afd

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

bilitool/feed/bili_live_list.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2025 bilitool
2+
3+
import requests
4+
5+
class BiliLiveList:
6+
def __init__(self, headers):
7+
self.headers = headers
8+
9+
def get_live_info(self, room) -> dict:
10+
"""Get the live info of the room"""
11+
12+
url = "https://api.live.bilibili.com/room/v1/Room/get_info?room_id={room}".format(
13+
room=room
14+
)
15+
response = requests.get(url=url, headers=self.headers)
16+
if response.status_code != 200:
17+
raise Exception('HTTP ERROR')
18+
response_json = response.json().get("data")
19+
if response.json().get("code") != 0:
20+
raise Exception(response.json().get("message"))
21+
return response_json
22+

tests/test_feed.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
import unittest
44
from bilitool.feed.bili_video_list import BiliVideoList
5+
from bilitool.feed.bili_live_list import BiliLiveList
56

67
class TestBiliList(unittest.TestCase):
8+
def setUp(self):
9+
self.headers = {
10+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/63.0.3239.108"
11+
}
12+
713
def test_get_bili_video_list(self):
814
bili = BiliVideoList()
915
bili.print_video_list_info(bili.get_bili_video_list(50, 'not_pubed'))
1016

1117
def test_print_video_info_via_bvid(self):
1218
bili = BiliVideoList()
13-
bili.print_video_info_via_bvid('BV1pCr6YcEgD')
19+
bili.print_video_info_via_bvid('BV1pCr6YcEgD')
20+
21+
def test_get_live_info(self):
22+
bili = BiliLiveList(self.headers)
23+
print(bili.get_live_info(25538755))

0 commit comments

Comments
 (0)