Skip to content

Commit 7101654

Browse files
davidteatherKkordikekorianwillmhowestrislee
authored
6.3.0 - Add Additional Params (#1140)
* Add 'executable_path' field to the 'api.create_sessions()' method (#1136) * Fixed retries loop (#1133) * Add option to select which browser playwright uses (#1129) * add browser selection option to create_sessions method * fix spelling typo --------- Co-authored-by: David Teather <[email protected]> * Update hashtag.py (#1126) TikTok appears to have limited the number of posts that can be returned for a single hashtag search to 35 (e.g. bellingcat/tiktok-hashtag-analysis#28). Similar to how the `User.liked` method works, I set the batch size to 35 videos per request. * add executable path to str * bump ver --------- Co-authored-by: kkordik <[email protected]> Co-authored-by: ekorian <[email protected]> Co-authored-by: Will Howes <[email protected]> Co-authored-by: Tristan Lee <[email protected]>
1 parent 7386b2b commit 7101654

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

.sphinx/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
project = "TikTokAPI"
1717
copyright = "2023, David Teather"
1818
author = "David Teather"
19-
release = "v6.2.2"
19+
release = "v6.3.0"
2020

2121
# -- General configuration ---------------------------------------------------
2222
# https://www.sphinx-doc.org/en/main/usage/configuration.html#general-configuration

CITATION.cff

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ authors:
55
orcid: "https://orcid.org/0000-0002-9467-4676"
66
title: "TikTokAPI"
77
url: "https://github.com/davidteather/tiktok-api"
8-
version: 6.2.2
9-
date-released: 2024-03-11
8+
version: 6.3.0
9+
date-released: 2024-04-12

TikTokApi/api/hashtag.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ async def videos(self, count=30, cursor=0, **kwargs) -> Iterator[Video]:
111111
while found < count:
112112
params = {
113113
"challengeID": self.id,
114-
"count": count,
114+
"count": 35,
115115
"cursor": cursor,
116116
}
117117

TikTokApi/tiktok.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ async def create_sessions(
212212
override_browser_args: list[dict] = None,
213213
cookies: list[dict] = None,
214214
suppress_resource_load_types: list[str] = None,
215+
browser: str = "chromium",
216+
executable_path: str = None
215217
):
216218
"""
217219
Create sessions for use within the TikTokApi class.
@@ -230,6 +232,8 @@ async def create_sessions(
230232
override_browser_args (list[dict]): A list of dictionaries containing arguments to pass to the browser.
231233
cookies (list[dict]): A list of cookies to use for the sessions, you can get these from your cookies after visiting TikTok.
232234
suppress_resource_load_types (list[str]): Types of resources to suppress playwright from loading, excluding more types will make playwright faster.. Types: document, stylesheet, image, media, font, script, textrack, xhr, fetch, eventsource, websocket, manifest, other.
235+
browser (str): specify either firefox or chromium, default is chromium
236+
executable_path (str): Path to the browser executable
233237
234238
Example Usage:
235239
.. code-block:: python
@@ -239,12 +243,19 @@ async def create_sessions(
239243
await api.create_sessions(num_sessions=5, ms_tokens=['msToken1', 'msToken2'])
240244
"""
241245
self.playwright = await async_playwright().start()
242-
if headless and override_browser_args is None:
243-
override_browser_args = ["--headless=new"]
244-
headless = False # managed by the arg
245-
self.browser = await self.playwright.chromium.launch(
246-
headless=headless, args=override_browser_args, proxy=random_choice(proxies)
247-
)
246+
if browser == "chromium":
247+
if headless and override_browser_args is None:
248+
override_browser_args = ["--headless=new"]
249+
headless = False # managed by the arg
250+
self.browser = await self.playwright.chromium.launch(
251+
headless=headless, args=override_browser_args, proxy=random_choice(proxies), executable_path=executable_path
252+
)
253+
elif browser == "firefox":
254+
self.browser = await self.playwright.firefox.launch(
255+
headless=headless, args=override_browser_args, proxy=random_choice(proxies), executable_path=executable_path
256+
)
257+
else:
258+
raise ValueError("Invalid browser argument passed")
248259

249260
await asyncio.gather(
250261
*(
@@ -417,7 +428,7 @@ async def make_request(
417428
signed_url = await self.sign_url(encoded_params, session_index=i)
418429

419430
retry_count = 0
420-
while i < retries:
431+
while retry_count < retries:
421432
retry_count += 1
422433
result = await self.run_fetch_script(
423434
signed_url, headers=headers, session_index=i

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
setuptools.setup(
99
name="TikTokApi",
1010
packages=setuptools.find_packages(),
11-
version="6.2.2",
11+
version="6.3.0",
1212
license="MIT",
1313
description="The Unofficial TikTok API Wrapper in Python 3.",
1414
author="David Teather",

0 commit comments

Comments
 (0)