Skip to content

Commit

Permalink
6.3.0 - Add Additional Params (#1140)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
5 people committed Apr 12, 2024
1 parent 7386b2b commit 7101654
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
project = "TikTokAPI"
copyright = "2023, David Teather"
author = "David Teather"
release = "v6.2.2"
release = "v6.3.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/main/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors:
orcid: "https://orcid.org/0000-0002-9467-4676"
title: "TikTokAPI"
url: "https://github.com/davidteather/tiktok-api"
version: 6.2.2
date-released: 2024-03-11
version: 6.3.0
date-released: 2024-04-12
2 changes: 1 addition & 1 deletion TikTokApi/api/hashtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def videos(self, count=30, cursor=0, **kwargs) -> Iterator[Video]:
while found < count:
params = {
"challengeID": self.id,
"count": count,
"count": 35,
"cursor": cursor,
}

Expand Down
25 changes: 18 additions & 7 deletions TikTokApi/tiktok.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ async def create_sessions(
override_browser_args: list[dict] = None,
cookies: list[dict] = None,
suppress_resource_load_types: list[str] = None,
browser: str = "chromium",
executable_path: str = None
):
"""
Create sessions for use within the TikTokApi class.
Expand All @@ -230,6 +232,8 @@ async def create_sessions(
override_browser_args (list[dict]): A list of dictionaries containing arguments to pass to the browser.
cookies (list[dict]): A list of cookies to use for the sessions, you can get these from your cookies after visiting TikTok.
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.
browser (str): specify either firefox or chromium, default is chromium
executable_path (str): Path to the browser executable
Example Usage:
.. code-block:: python
Expand All @@ -239,12 +243,19 @@ async def create_sessions(
await api.create_sessions(num_sessions=5, ms_tokens=['msToken1', 'msToken2'])
"""
self.playwright = await async_playwright().start()
if headless and override_browser_args is None:
override_browser_args = ["--headless=new"]
headless = False # managed by the arg
self.browser = await self.playwright.chromium.launch(
headless=headless, args=override_browser_args, proxy=random_choice(proxies)
)
if browser == "chromium":
if headless and override_browser_args is None:
override_browser_args = ["--headless=new"]
headless = False # managed by the arg
self.browser = await self.playwright.chromium.launch(
headless=headless, args=override_browser_args, proxy=random_choice(proxies), executable_path=executable_path
)
elif browser == "firefox":
self.browser = await self.playwright.firefox.launch(
headless=headless, args=override_browser_args, proxy=random_choice(proxies), executable_path=executable_path
)
else:
raise ValueError("Invalid browser argument passed")

await asyncio.gather(
*(
Expand Down Expand Up @@ -417,7 +428,7 @@ async def make_request(
signed_url = await self.sign_url(encoded_params, session_index=i)

retry_count = 0
while i < retries:
while retry_count < retries:
retry_count += 1
result = await self.run_fetch_script(
signed_url, headers=headers, session_index=i
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setuptools.setup(
name="TikTokApi",
packages=setuptools.find_packages(),
version="6.2.2",
version="6.3.0",
license="MIT",
description="The Unofficial TikTok API Wrapper in Python 3.",
author="David Teather",
Expand Down

0 comments on commit 7101654

Please sign in to comment.