This project is a fork of https://github.com/isaackogan A python library to connect to and read events from TikTok's LIVE service
In my project i don't use a termal printer, just customize a image and put the terminal in front of.
Triggered when the connection gets disconnected. You can call start() to have reconnect . Note that you should wait a little bit before attempting a reconnect to to avoid being rate-limited.
@client.on("disconnect")
async def on_disconnect(event: DisconnectEvent):
print("Disconnected")Triggered every time someone likes the stream.
@client.on("like")
async def on_like(event: LikeEvent):
print("Someone liked the stream!")Triggered every time a new person joins the stream.
@client.on("join")
async def on_join(event: JoinEvent):
print("Someone joined the stream!")Triggered every time a gift arrives. Extra information can be gleamed off the available_gifts client attribute.
NOTE: Users have the capability to send gifts in a streak. This increases the
data.gift.repeat_countvalue until the user terminates the streak. During this time new gift events are triggered again and again with an increaseddata.gift.repeat_countvalue. It should be noted that after the end of the streak, another gift event is triggered, which signals the end of the streak viadata.gift.repeat_end:1. This applies only to gifts withdata.gift.gift_type:1. This means that even if the user sends agift_type:1gift only once, you will receive the event twice. Once withrepeat_end:0and once withrepeat_end:1. Therefore, the event should be handled as follows in one of TWO ways:
@client.on("gift")
async def on_gift(event: GiftEvent):
# If it's type 1 and the streak is over
if event.gift.gift_type == 1:
if event.gift.repeat_end == 1:
print(f"{event.user.uniqueId} sent {event.gift.repeat_count}x \"{event.gift.extended_gift.name}\"")
# It's not type 1, which means it can't have a streak & is automatically over
elif event.gift.gift_type != 1:
print(f"{event.user.uniqueId} sent \"{event.gift.extended_gift.name}\"")@client.on("gift")
async def on_gift(event: GiftEvent):
# If it's type 1 and the streak is over
if event.gift.streakable:
if not event.gift.streaking:
print(f"{event.user.uniqueId} sent {event.gift.repeat_count}x \"{event.gift.extended_gift.name}\"")
# It's not type 1, which means it can't have a streak & is automatically over
else:
print(f"{event.user.uniqueId} sent \"{event.gift.extended_gift.name}\"")Triggered every time someone follows the streamer.
@client.on("follow")
async def on_follow(event: FollowEvent):
print("Someone followed the streamer!")Triggered every time someone shares the stream.
@client.on("share")
async def on_share(event: ShareEvent):
print("Someone shared the streamer!")Triggered every time the viewer count is updated. This event also updates the cached viewer count by default.
@client.on("viewer_count_update")
async def on_connect(event: ViewerCountUpdateEvent):
print("Received a new viewer count:", event.viewCount)Triggered every time someone comments on the live
@client.on("comment")
async def on_connect(event: CommentEvent):
print(f"{event.user.nickname} -> {event.comment}")Triggered when the live stream gets terminated by the host.
@client.on("live_end")
async def on_connect(event: LiveEndEvent):
print(f"Livestream ended :(")Triggered when an unknown event is received that is not yet handled by this client
@client.on("live_end")
async def on_connect(event: UnknownEvent):
print(event.as_dict, "<- This is my data as a dict!")Triggered when there is an error in the client or in error handlers.
If this handler is not present in the code, an internal default handler will log errors in the console. If a handler is added, all error handling (including logging) is up to the individual.
Warning: If you listen for the error event and do not log errors, you will not see when an error occurs.
@client.on("error")
async def on_connect(error: Exception):
# Handle the error
if isinstance(error, SomeRandomError):
print("Handle Some Error")
return
# Otherwise, log the error
client._log_error(error)