Skip to content

Commit aa0437b

Browse files
authored
Merge pull request #623 from Ikaros-521/owner
新增平台 tiktok的接入(支持数据有:弹幕,礼物,入场)
2 parents 2703e07 + 567dc7a commit aa0437b

File tree

6 files changed

+982
-14
lines changed

6 files changed

+982
-14
lines changed

data/tiktok礼物价格表.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"玫瑰": 1,
3+
"TikTok": 1,
4+
"手指爱心": 5,
5+
"甜筒": 1,
6+
"罗莎": 10,
7+
"甜甜圈": 30,
8+
"香水": 20
9+
}

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ faster_whisper
7171
httpx==0.25.2
7272
Pillow==10.1.0
7373
pygtrans
74-
jieba
74+
jieba
75+
gradio==4.16.0
76+
TikTokLive

requirements_common.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ google-generativeai==0.3.1
152152
colorlog==6.8.0
153153
faster_whisper==0.10.0
154154
pygtrans==1.5.3
155-
jieba==0.42.1
155+
jieba==0.42.1
156+
gradio==4.16.0
157+
TikTokLive==5.0.8

tests/test_tiktok/tiktok.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
from TikTokLive import TikTokLiveClient
2-
from TikTokLive.types.events import CommentEvent, ConnectEvent, DisconnectEvent, JoinEvent
2+
from TikTokLive.types.events import CommentEvent, ConnectEvent, DisconnectEvent, JoinEvent, GiftEvent
3+
from TikTokLive.types.errors import LiveNotFound
34

4-
proxies = {
5-
"http://": "http://127.0.0.1:10809",
6-
"https://": "http://127.0.0.1:10809"
7-
}
5+
# proxies = {
6+
# "http://": "http://127.0.0.1:10809",
7+
# "https://": "http://127.0.0.1:10809"
8+
# }
89

9-
# Instantiate the client with the user's username
10-
client: TikTokLiveClient = TikTokLiveClient(unique_id="@markus864", proxies=proxies)
10+
proxies = None
11+
12+
13+
# 代理软件开启TUN模式进行代理,由于库的ws不走传入的代理参数,只能靠代理软件全代理了
14+
client: TikTokLiveClient = TikTokLiveClient(unique_id="@blacktiebreaks", proxies=proxies)
1115

1216

1317
# Define how you want to handle specific events via decorator
@@ -24,14 +28,39 @@ async def on_join(event: JoinEvent):
2428
print(f"@{event.user.unique_id} joined the stream!")
2529

2630
# Notice no decorator?
31+
@client.on("comment")
2732
async def on_comment(event: CommentEvent):
2833
print(f"{event.user.nickname} -> {event.comment}")
2934

35+
@client.on("gift")
36+
async def on_gift(event: GiftEvent):
37+
"""
38+
This is an example for the "gift" event to show you how to read gift data properly.
39+
40+
Important Note:
41+
42+
Gifts of type 1 can have streaks, so we need to check that the streak has ended
43+
If the gift type isn't 1, it can't repeat. Therefore, we can go straight to printing
44+
45+
"""
46+
47+
# Streakable gift & streak is over
48+
if event.gift.streakable and not event.gift.streaking:
49+
print(f"{event.user.unique_id} sent {event.gift.count}x \"{event.gift.info.name}\"")
50+
51+
# Non-streakable gift
52+
elif not event.gift.streakable:
53+
print(f"{event.user.unique_id} sent \"{event.gift.info.name}\"")
3054

3155
# Define handling an event via a "callback"
32-
client.add_listener("comment", on_comment)
56+
# client.add_listener("comment", on_comment)
3357

3458
if __name__ == '__main__':
3559
# Run the client and block the main thread
3660
# await client.start() to run non-blocking
37-
client.run()
61+
try:
62+
client.run()
63+
64+
except LiveNotFound:
65+
print(f"User `@{client.unique_id}` seems to be offline, retrying after 1 minute...")
66+

0 commit comments

Comments
 (0)