From df46661e6ecf74f42c3fc7351f6032d1418c48ab Mon Sep 17 00:00:00 2001 From: isaackogan Date: Thu, 22 Feb 2024 10:44:33 -0500 Subject: [PATCH] Fix TikTokLiveLegacy imports --- LICENSE | 2 +- TikTokLive/client/client.py | 7 ++----- TikTokLive/events/__init__.py | 4 +++- TikTokLive/events/{base.py => base_event.py} | 5 +++++ TikTokLive/events/custom_events.py | 2 +- TikTokLive/events/proto_events.py | 2 +- TikTokLiveBuild/events/overrides.py | 2 +- TikTokLiveLegacy/client/base.py | 10 +++++----- TikTokLiveLegacy/client/httpx.py | 10 +++------- TikTokLiveLegacy/client/wsclient.py | 4 ++-- TikTokLiveLegacy/proto/utilities.py | 2 +- TikTokLiveLegacy/types/events.py | 4 ++-- TikTokLiveLegacy/types/objects.py | 4 ++-- TikTokLiveLegacy/utilities.py | 2 +- setup.py | 2 +- 15 files changed, 31 insertions(+), 31 deletions(-) rename TikTokLive/events/{base.py => base_event.py} (66%) diff --git a/LICENSE b/LICENSE index 78fd6f7..e95822f 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/TikTokLive/client/client.py b/TikTokLive/client/client.py index c9a877f..6102d50 100644 --- a/TikTokLive/client/client.py +++ b/TikTokLive/client/client.py @@ -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 @@ -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): diff --git a/TikTokLive/events/__init__.py b/TikTokLive/events/__init__.py index 2a09e1a..d47ff12 100644 --- a/TikTokLive/events/__init__.py +++ b/TikTokLive/events/__init__.py @@ -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 @@ -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]]]) diff --git a/TikTokLive/events/base.py b/TikTokLive/events/base_event.py similarity index 66% rename from TikTokLive/events/base.py rename to TikTokLive/events/base_event.py index 507ccf3..cfbde0b 100644 --- a/TikTokLive/events/base.py +++ b/TikTokLive/events/base_event.py @@ -1,3 +1,7 @@ +from asyncio import Event +from typing import TypeVar, Callable, Union, Awaitable + + class BaseEvent: @property @@ -8,3 +12,4 @@ def type(self) -> str: def get_type(cls) -> str: return cls.__name__ + diff --git a/TikTokLive/events/custom_events.py b/TikTokLive/events/custom_events.py index 32c04e2..b4a2472 100644 --- a/TikTokLive/events/custom_events.py +++ b/TikTokLive/events/custom_events.py @@ -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 diff --git a/TikTokLive/events/proto_events.py b/TikTokLive/events/proto_events.py index 4a55091..58d577a 100644 --- a/TikTokLive/events/proto_events.py +++ b/TikTokLive/events/proto_events.py @@ -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 diff --git a/TikTokLiveBuild/events/overrides.py b/TikTokLiveBuild/events/overrides.py index ad1a7b5..62b48eb 100644 --- a/TikTokLiveBuild/events/overrides.py +++ b/TikTokLiveBuild/events/overrides.py @@ -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 diff --git a/TikTokLiveLegacy/client/base.py b/TikTokLiveLegacy/client/base.py index 5b67a7b..c4daf82 100644 --- a/TikTokLiveLegacy/client/base.py +++ b/TikTokLiveLegacy/client/base.py @@ -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: diff --git a/TikTokLiveLegacy/client/httpx.py b/TikTokLiveLegacy/client/httpx.py index d0391ef..e9e8763 100644 --- a/TikTokLiveLegacy/client/httpx.py +++ b/TikTokLiveLegacy/client/httpx.py @@ -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: @@ -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: diff --git a/TikTokLiveLegacy/client/wsclient.py b/TikTokLiveLegacy/client/wsclient.py index 0109f83..89d23ba 100644 --- a/TikTokLiveLegacy/client/wsclient.py +++ b/TikTokLiveLegacy/client/wsclient.py @@ -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): diff --git a/TikTokLiveLegacy/proto/utilities.py b/TikTokLiveLegacy/proto/utilities.py index 497b753..15d5a81 100644 --- a/TikTokLiveLegacy/proto/utilities.py +++ b/TikTokLiveLegacy/proto/utilities.py @@ -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: diff --git a/TikTokLiveLegacy/types/events.py b/TikTokLiveLegacy/types/events.py index e0cd99f..171d5d2 100644 --- a/TikTokLiveLegacy/types/events.py +++ b/TikTokLiveLegacy/types/events.py @@ -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): diff --git a/TikTokLiveLegacy/types/objects.py b/TikTokLiveLegacy/types/objects.py index cb98530..57df8af 100644 --- a/TikTokLiveLegacy/types/objects.py +++ b/TikTokLiveLegacy/types/objects.py @@ -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): diff --git a/TikTokLiveLegacy/utilities.py b/TikTokLiveLegacy/utilities.py index a5a8947..d17ac8b 100644 --- a/TikTokLiveLegacy/utilities.py +++ b/TikTokLiveLegacy/utilities.py @@ -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: diff --git a/setup.py b/setup.py index e73d71b..9e79f2f 100644 --- a/setup.py +++ b/setup.py @@ -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