Skip to content

Commit

Permalink
Fix TikTokLiveLegacy imports
Browse files Browse the repository at this point in the history
  • Loading branch information
isaackogan committed Feb 22, 2024
1 parent b9c0f66 commit df46661
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Isaac Kogan
Copyright (c) 2024 Isaac Kogan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 2 additions & 5 deletions TikTokLive/client/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import asyncio
import logging
import os
import urllib.parse
from asyncio import AbstractEventLoop, Task, CancelledError
from logging import Logger
from typing import Optional, Type, AsyncIterator, Dict, Any, Tuple, Union, Callable, TypeVar, List, Awaitable
from typing import Optional, Type, AsyncIterator, Dict, Any, Tuple, Union, Callable, List

from httpx import Proxy
from pyee import AsyncIOEventEmitter
Expand All @@ -16,14 +15,12 @@
from TikTokLive.client.web.web_client import WebcastWebClient
from TikTokLive.client.web.web_settings import WebDefaults
from TikTokLive.client.ws.ws_client import WebcastWSClient
from TikTokLive.events import Event
from TikTokLive.events import Event, EventHandler
from TikTokLive.events.custom_events import UnknownEvent, ConnectEvent, FollowEvent, ShareEvent, LiveEndEvent, \
DisconnectEvent
from TikTokLive.events.proto_events import EVENT_MAPPINGS, ProtoEvent, ControlEvent
from TikTokLive.proto import WebcastResponse, WebcastResponseMessage, ControlAction

EventHandler = TypeVar("EventHandler", bound=Callable[[Event], Union[None, Awaitable[None]]])


class TikTokLiveClient(AsyncIOEventEmitter):

Expand Down
4 changes: 3 additions & 1 deletion TikTokLive/events/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Type, Union
from typing import Type, Union, TypeVar, Callable, Awaitable

from .custom_events import *
from ..client.logger import TikTokLiveLogHandler
Expand All @@ -13,3 +13,5 @@
"Failed to load the proto events class! "
"Ignore this if merging from an empty/nonexistent file."
)

EventHandler = TypeVar("EventHandler", bound=Callable[[Event], Union[None, Awaitable[None]]])
5 changes: 5 additions & 0 deletions TikTokLive/events/base.py → TikTokLive/events/base_event.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from asyncio import Event
from typing import TypeVar, Callable, Union, Awaitable


class BaseEvent:

@property
Expand All @@ -8,3 +12,4 @@ def type(self) -> str:
def get_type(cls) -> str:
return cls.__name__


2 changes: 1 addition & 1 deletion TikTokLive/events/custom_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from typing import Type, Union, Optional

from TikTokLive.events.base import BaseEvent
from TikTokLive.events.base_event import BaseEvent
from TikTokLive.events.proto_events import SocialEvent, ControlEvent
from TikTokLive.proto import WebcastResponseMessage

Expand Down
2 changes: 1 addition & 1 deletion TikTokLive/events/proto_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from TikTokLive.proto.tiktok_proto import *
from TikTokLive.proto.custom_proto import *
from .base import BaseEvent
from .base_event import BaseEvent
from typing import Type, Union, Dict
from typing import Union

Expand Down
2 changes: 1 addition & 1 deletion TikTokLiveBuild/events/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import betterproto

from TikTokLive.client.logger import TikTokLiveLogHandler, LogLevel
from TikTokLive.events.base import BaseEvent
from TikTokLive.events.base_event import BaseEvent
from TikTokLive.proto import ExtendedUser
from TikTokLive.proto.tiktok_proto import User

Expand Down
10 changes: 5 additions & 5 deletions TikTokLiveLegacy/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import websockets
from ffmpy import FFmpeg, FFRuntimeError

from TikTokLive.client import config, wsclient
from TikTokLive.client.httpx import TikTokHTTPClient
from TikTokLive.client.wsclient import WebcastWebsocketConnection, WebcastConnect
from TikTokLive.types import AlreadyConnecting, AlreadyConnected, LiveNotFound, \
from TikTokLiveLegacy.client import config, wsclient
from TikTokLiveLegacy.client.httpx import TikTokHTTPClient
from TikTokLiveLegacy.client.wsclient import WebcastWebsocketConnection, WebcastConnect
from TikTokLiveLegacy.types import AlreadyConnecting, AlreadyConnected, LiveNotFound, \
FailedFetchRoomInfo, FailedFetchGifts, \
FFmpegWrapper, AlreadyDownloadingStream, DownloadProcessNotFound, NotDownloadingStream, \
InitialCursorMissing, VideoQuality, WebsocketConnectionFailed, GiftDetailed, FailedParseGift
from TikTokLive.utilities import validate_and_normalize_unique_id
from TikTokLiveLegacy.utilities import validate_and_normalize_unique_id


class WebcastPushConnection:
Expand Down
10 changes: 3 additions & 7 deletions TikTokLiveLegacy/client/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import httpx
from httpx import Cookies

from TikTokLive.client import config
from TikTokLive.proto.utilities import deserialize_message
from TikTokLive.types import SignatureRateLimitReached
from TikTokLiveLegacy.client import config
from TikTokLiveLegacy.proto.utilities import deserialize_message
from TikTokLiveLegacy.types import SignatureRateLimitReached


class TikTokHTTPClient:
Expand Down Expand Up @@ -97,10 +97,6 @@ async def __httpx_get_bytes(self, url: str, params: dict = None, sign_api: bool

async with httpx.AsyncClient(trust_env=self.trust_env, proxies=self.proxies, cookies=self.cookies, verify=self.ssl_context) as client:
response: httpx.Response = await client.get(url, headers=self.headers, timeout=self.timeout)
if sign_api:
print(response.url)

print(response.headers.keys())

# If requesting the sign api
if sign_api:
Expand Down
4 changes: 2 additions & 2 deletions TikTokLiveLegacy/client/wsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from websockets.exceptions import ConnectionClosedOK
from websockets.legacy.client import WebSocketClientProtocol, Connect

from TikTokLive.proto.tiktok_schema_pb2 import WebcastWebsocketAck
from TikTokLive.proto.utilities import serialize_message, deserialize_websocket_message
from TikTokLiveLegacy.proto.tiktok_schema_pb2 import WebcastWebsocketAck
from TikTokLiveLegacy.proto.utilities import serialize_message, deserialize_websocket_message


class WebcastWebsocketConnection(WebSocketClientProtocol):
Expand Down
2 changes: 1 addition & 1 deletion TikTokLiveLegacy/proto/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from google.protobuf import json_format
from protobuf_to_dict import protobuf_to_dict

from TikTokLive.proto import tiktok_schema_pb2 as tiktok_schema
from TikTokLiveLegacy.proto import tiktok_schema_pb2 as tiktok_schema


def deserialize_message(proto_name: str, obj: bytes) -> dict:
Expand Down
4 changes: 2 additions & 2 deletions TikTokLiveLegacy/types/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from mashumaro import DataClassDictMixin, pass_through

from TikTokLive.types import User, Gift, Emote, TreasureBoxData, ExtraRankData, LinkUser, BattleArmy, TopViewer, \
from TikTokLiveLegacy.types import User, Gift, Emote, TreasureBoxData, ExtraRankData, LinkUser, BattleArmy, TopViewer, \
ChatImage, ValueLabel
from TikTokLive.types.utilities import LiveEvent, alias
from TikTokLiveLegacy.types.utilities import LiveEvent, alias


class AbstractEvent(DataClassDictMixin):
Expand Down
4 changes: 2 additions & 2 deletions TikTokLiveLegacy/types/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from ffmpy import FFmpeg
from mashumaro import DataClassDictMixin, pass_through

from TikTokLive.types import utilities
from TikTokLive.types.utilities import alias
from TikTokLiveLegacy.types import utilities
from TikTokLiveLegacy.types.utilities import alias


class AbstractObject(DataClassDictMixin):
Expand Down
2 changes: 1 addition & 1 deletion TikTokLiveLegacy/utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import re

from TikTokLive.types import FailedParseUserHTML
from TikTokLiveLegacy.types import FailedParseUserHTML


def get_room_id_from_main_page_html(main_page_html: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"ffmpy>=0.3.0",
"websockets_proxy>=0.1.0",
"betterproto>=2.0.0b6",
"async-timeout>=4.0.3"
"async-timeout>=4.0.3",

# Legacy-only requirements (to be removed)
"mashumaro>=3.5", # JSON Deserialization
Expand Down

0 comments on commit df46661

Please sign in to comment.