marqetive-lib 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- marqetive/__init__.py +9 -9
- marqetive/core/__init__.py +1 -1
- marqetive/core/account_factory.py +2 -2
- marqetive/core/base_manager.py +4 -4
- marqetive/core/client.py +1 -1
- marqetive/core/registry.py +1 -1
- marqetive/platforms/__init__.py +3 -3
- marqetive/platforms/base.py +3 -3
- marqetive/platforms/exceptions.py +2 -1
- marqetive/platforms/instagram/__init__.py +3 -3
- marqetive/platforms/instagram/client.py +4 -4
- marqetive/platforms/instagram/exceptions.py +1 -1
- marqetive/platforms/instagram/factory.py +5 -5
- marqetive/platforms/instagram/manager.py +4 -4
- marqetive/platforms/instagram/media.py +2 -2
- marqetive/platforms/linkedin/__init__.py +3 -3
- marqetive/platforms/linkedin/client.py +4 -4
- marqetive/platforms/linkedin/exceptions.py +1 -1
- marqetive/platforms/linkedin/factory.py +5 -5
- marqetive/platforms/linkedin/manager.py +4 -4
- marqetive/platforms/linkedin/media.py +4 -4
- marqetive/platforms/models.py +2 -0
- marqetive/platforms/tiktok/__init__.py +7 -0
- marqetive/platforms/tiktok/client.py +277 -0
- marqetive/platforms/tiktok/exceptions.py +180 -0
- marqetive/platforms/tiktok/factory.py +188 -0
- marqetive/platforms/tiktok/manager.py +115 -0
- marqetive/platforms/tiktok/media.py +305 -0
- marqetive/platforms/twitter/__init__.py +3 -3
- marqetive/platforms/twitter/client.py +6 -6
- marqetive/platforms/twitter/exceptions.py +1 -1
- marqetive/platforms/twitter/factory.py +5 -5
- marqetive/platforms/twitter/manager.py +4 -4
- marqetive/platforms/twitter/media.py +4 -4
- marqetive/platforms/twitter/threads.py +2 -2
- marqetive/registry_init.py +4 -4
- marqetive/utils/__init__.py +3 -3
- marqetive/utils/file_handlers.py +1 -1
- marqetive/utils/oauth.py +137 -2
- marqetive/utils/token_validator.py +1 -1
- {marqetive_lib-0.1.0.dist-info → marqetive_lib-0.1.2.dist-info}/METADATA +1 -2
- marqetive_lib-0.1.2.dist-info/RECORD +48 -0
- marqetive_lib-0.1.0.dist-info/RECORD +0 -43
- {marqetive_lib-0.1.0.dist-info → marqetive_lib-0.1.2.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""TikTok-specific exception handling and error code mapping.
|
|
2
|
+
|
|
3
|
+
This module provides error handling for the TikTok API, including HTTP status
|
|
4
|
+
code mapping, TikTok-specific error codes, and user-friendly messages.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from src.marqetive.platforms.exceptions import (
|
|
10
|
+
MediaUploadError,
|
|
11
|
+
PlatformAuthError,
|
|
12
|
+
PlatformError,
|
|
13
|
+
PostNotFoundError,
|
|
14
|
+
RateLimitError,
|
|
15
|
+
ValidationError,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# TikTok API error codes (hypothetical, based on common API patterns)
|
|
20
|
+
# Source: TikTok Developer documentation (assumed)
|
|
21
|
+
class TikTokErrorCode:
|
|
22
|
+
"""TikTok API error codes."""
|
|
23
|
+
|
|
24
|
+
# Authentication & Authorization
|
|
25
|
+
INVALID_ACCESS_TOKEN = 10001
|
|
26
|
+
ACCESS_TOKEN_EXPIRED = 10002
|
|
27
|
+
SCOPE_NOT_AUTHORIZED = 10003
|
|
28
|
+
AUTHENTICATION_FAILED = 10004
|
|
29
|
+
ACCOUNT_NOT_AUTHORIZED = 10005
|
|
30
|
+
|
|
31
|
+
# Rate Limiting
|
|
32
|
+
RATE_LIMIT_EXCEEDED = 20001
|
|
33
|
+
TOO_MANY_REQUESTS = 20002
|
|
34
|
+
|
|
35
|
+
# Resource Not Found
|
|
36
|
+
VIDEO_NOT_FOUND = 30001
|
|
37
|
+
USER_NOT_FOUND = 30002
|
|
38
|
+
COMMENT_NOT_FOUND = 30003
|
|
39
|
+
|
|
40
|
+
# Validation Errors
|
|
41
|
+
INVALID_PARAMETER = 40001
|
|
42
|
+
VIDEO_TOO_LARGE = 40002
|
|
43
|
+
VIDEO_DURATION_INVALID = 40003
|
|
44
|
+
DESCRIPTION_TOO_LONG = 40004
|
|
45
|
+
DUPLICATE_VIDEO = 40005
|
|
46
|
+
INVALID_VIDEO_FORMAT = 40006
|
|
47
|
+
|
|
48
|
+
# Media Upload & Processing
|
|
49
|
+
UPLOAD_FAILED = 50001
|
|
50
|
+
INIT_UPLOAD_FAILED = 50002
|
|
51
|
+
APPEND_CHUNK_FAILED = 50003
|
|
52
|
+
FINALIZE_UPLOAD_FAILED = 50004
|
|
53
|
+
MEDIA_PROCESSING_FAILED = 50005
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# Mapping of error codes to user-friendly messages
|
|
57
|
+
ERROR_MESSAGES: dict[int, str] = {
|
|
58
|
+
# Authentication
|
|
59
|
+
10001: "Invalid access token. Please re-authenticate.",
|
|
60
|
+
10002: "Access token has expired. Please refresh the token.",
|
|
61
|
+
10003: "The application is not authorized for the requested scope.",
|
|
62
|
+
10004: "Authentication failed. Please check your credentials.",
|
|
63
|
+
10005: "The user has not authorized this action for their account.",
|
|
64
|
+
# Rate Limiting
|
|
65
|
+
20001: "Rate limit exceeded. Please wait before making more requests.",
|
|
66
|
+
20002: "Too many requests. You have hit a rate limit.",
|
|
67
|
+
# Resource Not Found
|
|
68
|
+
30001: "The requested video could not be found.",
|
|
69
|
+
30002: "The specified user does not exist.",
|
|
70
|
+
30003: "The specified comment could not be found.",
|
|
71
|
+
# Validation
|
|
72
|
+
40001: "Invalid parameter in request.",
|
|
73
|
+
40002: "Video file size is too large.",
|
|
74
|
+
40003: "Video duration is outside the allowed range.",
|
|
75
|
+
40004: "Video description is too long.",
|
|
76
|
+
40005: "This video appears to be a duplicate of a previous post.",
|
|
77
|
+
40006: "Invalid video format. Please use a supported format like MP4 or MOV.",
|
|
78
|
+
# Media
|
|
79
|
+
50001: "Media upload failed.",
|
|
80
|
+
50005: "Media processing failed after upload.",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def map_tiktok_error(
|
|
85
|
+
status_code: int | None,
|
|
86
|
+
error_code: int | None = None,
|
|
87
|
+
error_message: str | None = None,
|
|
88
|
+
response_data: dict[str, Any] | None = None,
|
|
89
|
+
) -> PlatformError:
|
|
90
|
+
"""Map TikTok API error to the appropriate exception class.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
status_code: HTTP status code.
|
|
94
|
+
error_code: TikTok-specific error code from the response body.
|
|
95
|
+
error_message: Error message from the API.
|
|
96
|
+
response_data: Full response data from the API.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
An appropriate subclass of PlatformError.
|
|
100
|
+
"""
|
|
101
|
+
if response_data and "error" in response_data:
|
|
102
|
+
error_data = response_data["error"]
|
|
103
|
+
if not error_code:
|
|
104
|
+
error_code = error_data.get("code")
|
|
105
|
+
if not error_message:
|
|
106
|
+
error_message = error_data.get("message")
|
|
107
|
+
|
|
108
|
+
friendly_message = ERROR_MESSAGES.get(
|
|
109
|
+
error_code or 0, error_message or "An unknown TikTok API error occurred"
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
# Map to exception types based on error code categories or status code
|
|
113
|
+
if error_code in (10001, 10002, 10003, 10004, 10005) or status_code in (401, 403):
|
|
114
|
+
return PlatformAuthError(
|
|
115
|
+
friendly_message,
|
|
116
|
+
platform="tiktok",
|
|
117
|
+
status_code=status_code,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
if error_code in (20001, 20002) or status_code == 429:
|
|
121
|
+
retry_after = None
|
|
122
|
+
if response_data and response_data.get("extra"):
|
|
123
|
+
retry_after = response_data["extra"].get("log_id") # Placeholder
|
|
124
|
+
return RateLimitError(
|
|
125
|
+
friendly_message,
|
|
126
|
+
platform="tiktok",
|
|
127
|
+
status_code=status_code or 429,
|
|
128
|
+
retry_after=retry_after,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
if error_code in (30001,):
|
|
132
|
+
return PostNotFoundError(
|
|
133
|
+
post_id="", # TikTok might use a different identifier
|
|
134
|
+
platform="tiktok",
|
|
135
|
+
status_code=status_code,
|
|
136
|
+
message=friendly_message,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
if error_code in (40001, 40002, 40003, 40004, 40005, 40006):
|
|
140
|
+
return ValidationError(
|
|
141
|
+
friendly_message,
|
|
142
|
+
platform="tiktok",
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
if error_code in (50001, 50002, 50003, 50004, 50005):
|
|
146
|
+
return MediaUploadError(
|
|
147
|
+
friendly_message,
|
|
148
|
+
platform="tiktok",
|
|
149
|
+
status_code=status_code,
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
# Generic platform error for everything else
|
|
153
|
+
return PlatformError(
|
|
154
|
+
friendly_message,
|
|
155
|
+
platform="tiktok",
|
|
156
|
+
status_code=status_code,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class TikTokAPIError(PlatformError):
|
|
161
|
+
"""TikTok API specific error with detailed information."""
|
|
162
|
+
|
|
163
|
+
def __init__(
|
|
164
|
+
self,
|
|
165
|
+
message: str,
|
|
166
|
+
*,
|
|
167
|
+
status_code: int | None = None,
|
|
168
|
+
error_code: int | None = None,
|
|
169
|
+
response_data: dict[str, Any] | None = None,
|
|
170
|
+
) -> None:
|
|
171
|
+
super().__init__(message, platform="tiktok", status_code=status_code)
|
|
172
|
+
self.error_code = error_code
|
|
173
|
+
self.response_data = response_data
|
|
174
|
+
|
|
175
|
+
def __repr__(self) -> str:
|
|
176
|
+
return (
|
|
177
|
+
f"TikTokAPIError(message={self.message!r}, "
|
|
178
|
+
f"status_code={self.status_code}, "
|
|
179
|
+
f"error_code={self.error_code})"
|
|
180
|
+
)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""TikTok account factory for managing credentials and client creation."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from datetime import datetime, timedelta
|
|
7
|
+
|
|
8
|
+
from src.marqetive.core.account_factory import BaseAccountFactory
|
|
9
|
+
from src.marqetive.platforms.exceptions import PlatformAuthError
|
|
10
|
+
from src.marqetive.platforms.models import AccountStatus, AuthCredentials
|
|
11
|
+
from src.marqetive.platforms.tiktok.client import TikTokClient
|
|
12
|
+
from src.marqetive.utils.oauth import fetch_tiktok_token, refresh_tiktok_token
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TikTokAccountFactory(BaseAccountFactory):
|
|
18
|
+
"""Factory for creating and managing TikTok accounts and clients.
|
|
19
|
+
|
|
20
|
+
This factory handles the instantiation of TikTokClients, manages OAuth
|
|
21
|
+
credentials, and provides a mechanism for token refreshing.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
client_id: str | None = None,
|
|
27
|
+
client_secret: str | None = None,
|
|
28
|
+
on_status_update: Callable[[str, AccountStatus], None] | None = None,
|
|
29
|
+
) -> None:
|
|
30
|
+
"""Initialize TikTok account factory.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
client_id: TikTok App client ID (uses TIKTOK_CLIENT_ID env if None).
|
|
34
|
+
client_secret: TikTok App client secret (uses TIKTOK_CLIENT_SECRET env if None).
|
|
35
|
+
on_status_update: Optional callback when account status changes.
|
|
36
|
+
"""
|
|
37
|
+
super().__init__(on_status_update=on_status_update)
|
|
38
|
+
self.client_id = client_id or os.getenv("TIKTOK_CLIENT_ID")
|
|
39
|
+
self.client_secret = client_secret or os.getenv("TIKTOK_CLIENT_SECRET")
|
|
40
|
+
|
|
41
|
+
if not self.client_id or not self.client_secret:
|
|
42
|
+
logger.warning(
|
|
43
|
+
"TikTok client_id/client_secret not provided. "
|
|
44
|
+
"Token refresh may not work."
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def platform_name(self) -> str:
|
|
49
|
+
"""Get the platform name."""
|
|
50
|
+
return "tiktok"
|
|
51
|
+
|
|
52
|
+
async def get_credentials_from_auth_code(
|
|
53
|
+
self,
|
|
54
|
+
auth_code: str,
|
|
55
|
+
redirect_uri: str,
|
|
56
|
+
code_verifier: str | None = None,
|
|
57
|
+
) -> AuthCredentials:
|
|
58
|
+
"""Get credentials from an authorization code.
|
|
59
|
+
|
|
60
|
+
This method exchanges an authorization code for an access token and
|
|
61
|
+
formats it into the standard AuthCredentials object.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
auth_code: The authorization code received from TikTok.
|
|
65
|
+
redirect_uri: The redirect URI used in the initial auth request.
|
|
66
|
+
code_verifier: The PKCE code verifier, if used.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
An AuthCredentials object for the user.
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
PlatformAuthError: If the token exchange fails.
|
|
73
|
+
"""
|
|
74
|
+
if not self.client_id or not self.client_secret:
|
|
75
|
+
raise PlatformAuthError(
|
|
76
|
+
"TikTok client_id and client_secret are required.",
|
|
77
|
+
platform=self.platform_name,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
token_data = await fetch_tiktok_token(
|
|
81
|
+
code=auth_code,
|
|
82
|
+
client_id=self.client_id,
|
|
83
|
+
client_secret=self.client_secret,
|
|
84
|
+
redirect_uri=redirect_uri,
|
|
85
|
+
code_verifier=code_verifier,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
expires_at = None
|
|
89
|
+
if "expires_in" in token_data:
|
|
90
|
+
expires_at = datetime.now() + timedelta(seconds=token_data["expires_in"])
|
|
91
|
+
|
|
92
|
+
refresh_expires_at = None
|
|
93
|
+
if "refresh_expires_in" in token_data:
|
|
94
|
+
refresh_expires_at = datetime.now() + timedelta(
|
|
95
|
+
seconds=token_data["refresh_expires_in"]
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
credentials = AuthCredentials(
|
|
99
|
+
platform=self.platform_name,
|
|
100
|
+
access_token=token_data["access_token"],
|
|
101
|
+
refresh_token=token_data.get("refresh_token"),
|
|
102
|
+
expires_at=expires_at,
|
|
103
|
+
scope=token_data.get("scope", []),
|
|
104
|
+
additional_data={
|
|
105
|
+
"open_id": token_data["open_id"],
|
|
106
|
+
"token_type": token_data.get("token_type"),
|
|
107
|
+
"refresh_expires_at": refresh_expires_at,
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
return credentials
|
|
111
|
+
|
|
112
|
+
async def refresh_token(self, credentials: AuthCredentials) -> AuthCredentials:
|
|
113
|
+
"""Refresh a TikTok OAuth2 access token.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
credentials: The current credentials containing the refresh token.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
Updated credentials with a new access token.
|
|
120
|
+
|
|
121
|
+
Raises:
|
|
122
|
+
PlatformAuthError: If refresh fails or credentials are missing.
|
|
123
|
+
"""
|
|
124
|
+
if not self.client_id or not self.client_secret:
|
|
125
|
+
raise PlatformAuthError(
|
|
126
|
+
"TikTok client_id and client_secret are required for token refresh.",
|
|
127
|
+
platform=self.platform_name,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
if not credentials.refresh_token:
|
|
131
|
+
raise PlatformAuthError(
|
|
132
|
+
"No refresh token available for TikTok.", platform=self.platform_name
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
logger.info("Refreshing TikTok access token...")
|
|
136
|
+
# This function would call the actual TikTok token refresh endpoint
|
|
137
|
+
return await refresh_tiktok_token(
|
|
138
|
+
credentials, self.client_id, self.client_secret
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
async def create_client(self, credentials: AuthCredentials) -> TikTokClient:
|
|
142
|
+
"""Create a TikTok API client.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
credentials: Valid TikTok authentication credentials.
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
An instance of TikTokClient.
|
|
149
|
+
|
|
150
|
+
Raises:
|
|
151
|
+
PlatformAuthError: If credentials are incomplete or invalid.
|
|
152
|
+
"""
|
|
153
|
+
if not credentials.access_token:
|
|
154
|
+
raise PlatformAuthError(
|
|
155
|
+
"Access token is required for TikTok.", platform=self.platform_name
|
|
156
|
+
)
|
|
157
|
+
if (
|
|
158
|
+
not credentials.additional_data
|
|
159
|
+
or "open_id" not in credentials.additional_data
|
|
160
|
+
):
|
|
161
|
+
raise PlatformAuthError(
|
|
162
|
+
"'open_id' must be provided in additional_data for TikTok.",
|
|
163
|
+
platform=self.platform_name,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
return TikTokClient(credentials=credentials)
|
|
167
|
+
|
|
168
|
+
async def validate_credentials(self, credentials: AuthCredentials) -> bool:
|
|
169
|
+
"""Validate TikTok credentials by making a test API call.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
credentials: The credentials to validate.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
True if the credentials are valid, False otherwise.
|
|
176
|
+
"""
|
|
177
|
+
try:
|
|
178
|
+
client = await self.create_client(credentials)
|
|
179
|
+
async with client:
|
|
180
|
+
return await client.is_authenticated()
|
|
181
|
+
except PlatformAuthError as e:
|
|
182
|
+
logger.warning(f"TikTok credential validation failed: {e}")
|
|
183
|
+
return False
|
|
184
|
+
except Exception as e:
|
|
185
|
+
logger.error(
|
|
186
|
+
f"An unexpected error occurred during TikTok credential validation: {e}"
|
|
187
|
+
)
|
|
188
|
+
return False
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""TikTok post manager for handling video post operations."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from src.marqetive.core.base_manager import BasePostManager
|
|
7
|
+
from src.marqetive.platforms.models import AuthCredentials, Post, PostCreateRequest
|
|
8
|
+
from src.marqetive.platforms.tiktok.client import TikTokClient
|
|
9
|
+
from src.marqetive.platforms.tiktok.factory import TikTokAccountFactory
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TikTokPostManager(BasePostManager):
|
|
15
|
+
"""Manager for TikTok video post operations.
|
|
16
|
+
|
|
17
|
+
This manager coordinates the multi-step process of posting a video to
|
|
18
|
+
TikTok, including media upload, processing, and the final publishing step.
|
|
19
|
+
It provides progress tracking throughout the operation.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
account_factory: TikTokAccountFactory | None = None,
|
|
25
|
+
client_id: str | None = None,
|
|
26
|
+
client_secret: str | None = None,
|
|
27
|
+
) -> None:
|
|
28
|
+
"""Initialize the TikTok post manager.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
account_factory: An instance of TikTokAccountFactory. If not provided,
|
|
32
|
+
a default one will be created.
|
|
33
|
+
client_id: TikTok App client ID (for the default factory).
|
|
34
|
+
client_secret: TikTok App client secret (for the default factory).
|
|
35
|
+
"""
|
|
36
|
+
if account_factory is None:
|
|
37
|
+
account_factory = TikTokAccountFactory(
|
|
38
|
+
client_id=client_id,
|
|
39
|
+
client_secret=client_secret,
|
|
40
|
+
)
|
|
41
|
+
super().__init__(account_factory=account_factory)
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def platform_name(self) -> str:
|
|
45
|
+
"""Get the platform name."""
|
|
46
|
+
return "tiktok"
|
|
47
|
+
|
|
48
|
+
async def _execute_post_impl(
|
|
49
|
+
self,
|
|
50
|
+
client: Any,
|
|
51
|
+
request: PostCreateRequest,
|
|
52
|
+
credentials: AuthCredentials,
|
|
53
|
+
) -> Post:
|
|
54
|
+
"""Execute the TikTok video post creation process.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
client: An authenticated TikTokClient instance.
|
|
58
|
+
request: The post creation request.
|
|
59
|
+
credentials: The credentials used for authentication.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
The created Post object representing the TikTok video.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
TypeError: If the provided client is not a TikTokClient.
|
|
66
|
+
InterruptedError: If the operation is cancelled.
|
|
67
|
+
"""
|
|
68
|
+
if not isinstance(client, TikTokClient):
|
|
69
|
+
raise TypeError(f"Expected TikTokClient, got {type(client)}")
|
|
70
|
+
|
|
71
|
+
# The TikTok posting process is primarily about the video upload.
|
|
72
|
+
# The client's create_post method handles the upload and publish steps.
|
|
73
|
+
# We can wrap it here to provide progress updates.
|
|
74
|
+
|
|
75
|
+
self._progress_tracker.emit_start(
|
|
76
|
+
"execute_post", total=100, message="Starting TikTok post..."
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
if self.is_cancelled():
|
|
80
|
+
raise InterruptedError("Post creation was cancelled before start.")
|
|
81
|
+
|
|
82
|
+
# Media upload progress can be tracked inside the client, but for simplicity,
|
|
83
|
+
# we'll emit high-level progress here.
|
|
84
|
+
self._progress_tracker.emit_progress(
|
|
85
|
+
"execute_post",
|
|
86
|
+
progress=10,
|
|
87
|
+
total=100,
|
|
88
|
+
message="Uploading video to TikTok...",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# The `create_post` method in the client will handle the full flow:
|
|
92
|
+
# 1. Upload media
|
|
93
|
+
# 2. Publish post
|
|
94
|
+
# 3. Fetch final post data
|
|
95
|
+
# A more advanced implementation might involve callbacks from the client
|
|
96
|
+
# to the manager for more granular progress updates.
|
|
97
|
+
post = await client.create_post(request)
|
|
98
|
+
|
|
99
|
+
if self.is_cancelled():
|
|
100
|
+
# If cancellation happened during the client call, we might need cleanup.
|
|
101
|
+
# For now, we just raise.
|
|
102
|
+
raise InterruptedError("Post creation was cancelled during execution.")
|
|
103
|
+
|
|
104
|
+
self._progress_tracker.emit_progress(
|
|
105
|
+
"execute_post",
|
|
106
|
+
progress=90,
|
|
107
|
+
total=100,
|
|
108
|
+
message="Finalizing post...",
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
self._progress_tracker.emit_complete(
|
|
112
|
+
"execute_post", message="TikTok post published successfully!"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
return post
|