TikTokLive.client.web.routes package

Submodules

TikTokLive.client.web.routes.download_video module

exception TikTokLive.client.web.routes.download_video.DuplicateDownloadError

Bases: RuntimeError

Thrown when attempting to start a duplicate download on a video you are already downloading

class TikTokLive.client.web.routes.download_video.VideoFetchFormat(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

TikTok-supported video recording formats

CMAF = 'cmaf'
FLV = 'flv'
HLS = 'hls'
class TikTokLive.client.web.routes.download_video.VideoFetchQuality(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Video quality selection for stream downloads

HD = 'hd'

High definition (540p, vbrate-1,000,000)

LD = 'ld'

Low definition (480p, vbrate-500,000)

ORIGIN = 'origin'

Original definition (N/A, vbrate-N/A)

SD = 'sd'

Standard definition (480p, vbrate-800,000)

UHD = 'uhd'

Ultra-high definition (720p, vbrate-1,000,000)

class TikTokLive.client.web.routes.download_video.VideoFetchRoute(web: TikTokHTTPClient)

Bases: ClientRoute

TikTok route to record the livestream video in real-time

property ffmpeg: FFmpeg | None

Return a copy of the FFmpeg class, which is only defined while recording

Returns:

Copy of the class or None

property is_recording: bool

Check if the route is currently in use to record the Live

Returns:

Recording status

start(**kwargs) None

Alias for calling the class itself, starts a recording

Parameters:

kwargs – Kwargs to pass to __call__

Returns:

None

stop() None

Stop a livestream recording if it is ongoing

Returns:

None

TikTokLive.client.web.routes.gift_list module

exception TikTokLive.client.web.routes.gift_list.FailedFetchGiftListError

Bases: RuntimeError

Thrown when a request to the gift list endpoint fails

class TikTokLive.client.web.routes.gift_list.GiftListRoute(web: TikTokHTTPClient)

Bases: ClientRoute

Retrieve the gift list from TikTok

TikTokLive.client.web.routes.image_download module

class TikTokLive.client.web.routes.image_download.ImageFetchRoute(web: TikTokHTTPClient)

Bases: ClientRoute

Fetch an image from the TikTok CDN

TikTokLive.client.web.routes.is_live module

class TikTokLive.client.web.routes.is_live.FetchIsLiveRoute(web: TikTokHTTPClient)

Bases: ClientRoute

Check if a given user is alive through their unique_id or room_id

async fetch_is_live_room_ids(*room_ids: int) List[bool]

Check whether a list of room_id’s are currently live

Parameters:

room_ids – The room_id’s to check

Returns:

Whether they are alive, in the order they were sent

async fetch_is_live_unique_id(unique_id: str) bool

Check whether a given user is live

Parameters:

unique_id – The unique_id of the user

Returns:

Whether they are live

Raises:

InvalidLiveUser

exception TikTokLive.client.web.routes.is_live.InvalidFetchIsLiveRequest

Bases: RuntimeError

Thrown when the user fails to specify either a room ID or unique ID

exception TikTokLive.client.web.routes.is_live.MissingRoomIdInResponse

Bases: RuntimeError

Thrown when no entries are returned from the Room ID live method. This occurs when passing a nonexistent Room ID or when being detected by TikTok.

TikTokLive.client.web.routes.room_id_api module

class TikTokLive.client.web.routes.room_id_api.RoomIdAPIRoute(web: TikTokHTTPClient)

Bases: ClientRoute

Route to retrieve the room ID for a user

async classmethod fetch_user_room_data(web: TikTokHTTPClient, unique_id: str) dict

Fetch user room from the API (not the same as room info)

Parameters:
  • web – The TikTokHTTPClient client to use

  • unique_id – The user to check

Returns:

The user’s room info

classmethod parse_room_id(data: dict) str

Parse the room ID from livestream API response

Parameters:

data – The data to parse

Returns:

The user’s room id

Raises:

UserOfflineError if the user is offline

Raises:

FailedParseRoomIdError if the user data does not exist

TikTokLive.client.web.routes.room_id_live_html module

exception TikTokLive.client.web.routes.room_id_live_html.FailedParseRoomIdError

Bases: RuntimeError

Thrown when the Room ID cannot be parsed

class TikTokLive.client.web.routes.room_id_live_html.RoomIdLiveHTMLRoute(web: TikTokHTTPClient)

Bases: ClientRoute

Route to retrieve the room ID for a user

SIGI_PATTERN: Pattern = re.compile('<script id="SIGI_STATE" type="application/json">(.*?)</script>')
classmethod parse_room_id(html: str) str

Parse the room ID from livestream HTML

Parameters:

html – The HTML to parse from https://tiktok.com/@<unique_id>/live

Returns:

The user’s room id

Raises:

UserOfflineError if the user is offline

Raises:

FailedParseRoomIdError if the user does not exist

TikTokLive.client.web.routes.room_info module

exception TikTokLive.client.web.routes.room_info.FailedFetchRoomInfoError

Bases: RuntimeError

Thrown if Room info request fails

class TikTokLive.client.web.routes.room_info.FetchRoomInfoRoomIdRoute(web: TikTokHTTPClient)

Bases: ClientRoute

Retrieve the room info payload of a livestream room

exception TikTokLive.client.web.routes.room_info.InvalidFetchRoomInfoPayload

Bases: RuntimeError

TikTokLive.client.web.routes.sign_fetch module

exception TikTokLive.client.web.routes.sign_fetch.SignAPIError(reason: ErrorReason, *args: str)

Bases: RuntimeError

Thrown when a fetch to the Sign API fails for one reason or another

class ErrorReason(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Possible failure reasons

CONNECT_ERROR = 2
EMPTY_COOKIES = 5
EMPTY_PAYLOAD = 3
RATE_LIMIT = 1
SIGN_NOT_200 = 4
class TikTokLive.client.web.routes.sign_fetch.SignFetchRoute(web: TikTokHTTPClient, sign_api_key: str | None)

Bases: ClientRoute

Call the signature server to receive the TikTok websocket URL

exception TikTokLive.client.web.routes.sign_fetch.SignatureRateLimitError(retry_after: int, reset_time: int, *args)

Bases: SignAPIError

Thrown when a user hits the Sign API limit

property reset_time: int

The unix timestamp for when the client can request again

property retry_after: int

How long to wait until the next attempt

Module contents