Skip to content

Commit

Permalink
Merge pull request #623 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
新增平台 tiktok的接入(支持数据有:弹幕,礼物,入场)
  • Loading branch information
Ikaros-521 authored Feb 7, 2024
2 parents 2703e07 + 567dc7a commit aa0437b
Show file tree
Hide file tree
Showing 6 changed files with 982 additions and 14 deletions.
9 changes: 9 additions & 0 deletions data/tiktok礼物价格表.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"玫瑰": 1,
"TikTok": 1,
"手指爱心": 5,
"甜筒": 1,
"罗莎": 10,
"甜甜圈": 30,
"香水": 20
}
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ faster_whisper
httpx==0.25.2
Pillow==10.1.0
pygtrans
jieba
jieba
gradio==4.16.0
TikTokLive
4 changes: 3 additions & 1 deletion requirements_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,6 @@ google-generativeai==0.3.1
colorlog==6.8.0
faster_whisper==0.10.0
pygtrans==1.5.3
jieba==0.42.1
jieba==0.42.1
gradio==4.16.0
TikTokLive==5.0.8
47 changes: 38 additions & 9 deletions tests/test_tiktok/tiktok.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import CommentEvent, ConnectEvent, DisconnectEvent, JoinEvent
from TikTokLive.types.events import CommentEvent, ConnectEvent, DisconnectEvent, JoinEvent, GiftEvent
from TikTokLive.types.errors import LiveNotFound

proxies = {
"http://": "http://127.0.0.1:10809",
"https://": "http://127.0.0.1:10809"
}
# proxies = {
# "http://": "http://127.0.0.1:10809",
# "https://": "http://127.0.0.1:10809"
# }

# Instantiate the client with the user's username
client: TikTokLiveClient = TikTokLiveClient(unique_id="@markus864", proxies=proxies)
proxies = None


# 代理软件开启TUN模式进行代理,由于库的ws不走传入的代理参数,只能靠代理软件全代理了
client: TikTokLiveClient = TikTokLiveClient(unique_id="@blacktiebreaks", proxies=proxies)


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

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

@client.on("gift")
async def on_gift(event: GiftEvent):
"""
This is an example for the "gift" event to show you how to read gift data properly.
Important Note:
Gifts of type 1 can have streaks, so we need to check that the streak has ended
If the gift type isn't 1, it can't repeat. Therefore, we can go straight to printing
"""

# Streakable gift & streak is over
if event.gift.streakable and not event.gift.streaking:
print(f"{event.user.unique_id} sent {event.gift.count}x \"{event.gift.info.name}\"")

# Non-streakable gift
elif not event.gift.streakable:
print(f"{event.user.unique_id} sent \"{event.gift.info.name}\"")

# Define handling an event via a "callback"
client.add_listener("comment", on_comment)
# client.add_listener("comment", on_comment)

if __name__ == '__main__':
# Run the client and block the main thread
# await client.start() to run non-blocking
client.run()
try:
client.run()

except LiveNotFound:
print(f"User `@{client.unique_id}` seems to be offline, retrying after 1 minute...")

Loading

0 comments on commit aa0437b

Please sign in to comment.