from email.mime import image
from http import client
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import CommentEvent, ConnectEvent, GiftEvent, ShareEvent, FollowEvent, ViewerCountUpdateEvent
client: TikTokLiveClient = TikTokLiveClient(
unique_id="ad", **(
{
"eneble_extended_gift_info": True
}
)
)
@client.on("connect")
async def on_connect(_: ConnectEvent):
print("Connected to Room ID:", client.room_id)
@client.on("connect")
async def on_connect(event: ConnectEvent):
print(f"{event.user.uniqueId} -> {event.comment}")
@client.on("gift")
async def on_gift(event: GiftEvent):
print(f"{event.user.uniqueId} sent a {event.gift.gift_id}!")
for giftInfo in client.available_gifts:
if giftInfo["id"] == event.gift.gift_id:
print(f"Name: {giftInfo['name']} Imege: {giftInfo['image']['url_list'][0]} Diamond Amount: {giftInfo}['diamond_count']}")
@client.on("like")
async def on_like(event: LikeEvent):
print(f"{event.user.uniqueID} has liked the stream {event.likeCount} times, there is now {event.totalLikeCount} toral likes!")
@client.on("follow")
async def on_follow(event: FollowEvent):
print(f"{event.user.uniqueID} followed the streamer")
@client.on("share")
async def on_share(event: ShareEvent):
print(f"{event.user.uniqueID} shared the streamer!")
@client.on("viewer_count_update")
async def on_connect(event: ViewerCountUpdateEvent):
print("Received a new Viewer count:", event.viewerCount)
if __name__ == '__main__':
# Run the client and block the main thread
# await client.start() to run non-blocking
client.run()