Skip to content

Feat: Support for retrieving videos and carousels (media) by keyword - TiktokSearchClient#10

Merged
Ts-Pytham merged 18 commits into
masterfrom
feat/search
Jun 12, 2026
Merged

Feat: Support for retrieving videos and carousels (media) by keyword - TiktokSearchClient#10
Ts-Pytham merged 18 commits into
masterfrom
feat/search

Conversation

@Ts-Pytham

Copy link
Copy Markdown
Owner

No description provided.

Ts-Pytham added 14 commits June 1, 2026 17:40
Refactored `TikTokBrowser` constructor for improved readability. Added `GetSearchPageAsync` and `GetSearchNextPageAsync` methods to handle TikTok search requests and pagination. Introduced `CreatePageAsync` for page creation in the browser context.

Implemented `PlaywrightSearchFetcher` to manage TikTok searches, including browser initialization, result fetching, and resource disposal. Added `TikTokSearchParser` to parse search JSON into `Video` objects.

Changed `ParseVideo` in `TikTokVideoParser` from private to internal for broader accessibility. Updated `ISearchClient` to rename `query` parameter to `keyword` for consistency.
Introduced a new `TiktokSearchClient` implementing `ISearchClient`
to enable keyword-based TikTok video searches using Playwright.
Added methods for downloading videos with and without watermarks.

Updated `PlaywrightSearchFetcher` to support `TikTokOptions`
and added retry logic for WAF challenges with linear backoff.
Refactored `FetchSearchAsync` to improve handling of paginated
search results. Added detailed documentation for clarity.

Renamed `SearchVideosAsync` to `SearchAsync` in `ISearchClient`
for simplicity. Updated `TiktokClientExtensions` to reflect
changes in the download client interface.

These changes enhance the architecture for searching and
downloading TikTok videos, improving extensibility and resilience.
Updated README to document ISearchClient integration, including usage examples and service registration details. Adjusted `TiktokExplodeBuilder` to register `ISearchClient` and `ISearchFetcher` when using Playwright. Added warnings about unavailability with HTTP fetcher. Minor adjustments in `TikTokBrowser` and `TiktokSearchClient` for consistency.
Renamed classes, methods, and variables to use the `Tiktok`
naming convention instead of `TikTok` for consistency. Updated
references across the codebase, including constructors, static
methods, and documentation.
Transformed the console app to support two modes: video download by URL and video search by keyword. Added helper methods for fetching, searching, and downloading videos.

Enhanced `TiktokBrowser` to reuse signed URLs for search pagination and improved response handling with JavaScript.

Introduced `GetOptionalNumber<T>` in `JsonNodeExtensions` for flexible numeric parsing. Updated `TikTokVideoParser` to handle precise durations and added support for video music metadata, including title, author, album, and artwork.

Added new tests in `TikTokVideoParserTests` for music metadata and adjusted existing tests for duration changes. Updated fixtures in `TikTokFixtures` to include music-related data.

Made `CreatedAt` optional in `Author.cs` and added a `Music` field in `Video.cs`. Created `MediaDuration` and `VideoMusic` classes to represent music and duration details.

Reorganized project structure in `TiktokExplode.NET.slnx` and adjusted packaging paths in `TiktokExplode.csproj`.
Added validation in `TiktokClient` and `TiktokSearchClient` to ensure download URLs are not null or empty, throwing `TiktokException` when invalid. Introduced `GetOptionalString` in `JsonNodeExtensions` to handle optional JSON fields. Updated `TiktokVideoParser` to handle missing `bitrateInfo` and use safer methods for parsing optional fields. Documented potential exceptions in `IDownloadClient`. Modified `Bitrate` structure to support nullable `FPS` and `RawFormat`, reflecting partial metadata from TikTok.
Refactor the `Video` model to inherit from a new `Media` base class, enabling shared properties for both videos and carousels. Introduce the `Carousel` model and supporting value objects (`CarouselPost`, `CarouselImage`) to handle slideshow posts with full metadata.

Update `TiktokSearchClient` to return `IAsyncEnumerable<Media>` instead of `Video`, allowing the processing of both media types. Modify `TiktokSearchParser` to differentiate between videos and carousels using pattern matching.

Rename and generalize value objects (`VideoStats`, `VideoLanguage`, etc.) to `MediaStats`, `MediaLanguage`, and similar, for broader applicability. Remove obsolete video-specific classes.

Update documentation to reflect API changes, including examples for carousels and a new section on search pagination limitations. Reorganize project structure to align with the new class hierarchy.

Enhance `TiktokBrowser` to handle signed URLs and preserve parameters for carousel data. Add new exceptions and validations for JSON parsing of carousels.
Refactored `TiktokBrowser` to improve robustness in handling TikTok search pages:
- Rewrote `GetSearchPageAsync` to include WAF detection, better error handling, and manual fallback for API responses.
- Added `GetSearchNextPageAsync` to handle pagination and API response validation.
- Removed `_lastSearchApiUrl` and replaced it with direct API response handling.

Updated `PlaywrightSearchFetcher` to use the new `SearchPageResult` class for encapsulating JSON content and Playwright pages. Improved resource management by ensuring pages are closed properly.

Introduced `SearchPageResult` class to structure search results. Updated `TiktokSearchParser` to handle missing `data` arrays gracefully.
- Changed `WaitUntilState` in `TikTokBrowser` to improve load times.
- Refactored `page.WaitForFunctionAsync` for better readability.
- Added error handling for `response.TextAsync` in `TikTokBrowser`.
- Documented and modularized parsing logic in `TiktokSearchParser`.
- Introduced `PlaywrightFixture` for integration test setup.
- Added `PlaywrightSearchFetcherTests` and `TiktokSearchClientTests`.
- Configured integration tests project for .NET 9.0.
- Added `global using` directives for common namespaces.
Updated the `README.md` to reflect the available methods in `TiktokSearchClient`, fixed table formatting, and removed the "Known Limitations" section about pagination. Added unit tests in `TikTokSearchParserTests.cs` to validate the behavior of `TiktokSearchClient` for handling `Video` and `Carousel` results, as well as edge cases like empty or missing data.

Introduced helper methods for creating mock clients and collecting async results. Added JSON fixtures in `TikTokFixtures.cs` to simulate various API responses, including valid videos, carousels, mixed results, and error scenarios. Reusable blocks for authors, music, and stats were added to simplify fixture creation.

Implemented specific tests to ensure correct type identification, full field mapping, handling of invalid entries, and proper exception handling for parsing errors.
…ed in `Video` and `Carousel` to generate TikTok-specific URLs.

XML documentation has been added to the missing classes
Updated the CI pipeline to include integration tests, which run on pull requests targeting the `master` branch.

Renamed the `Build & Test` job to `Build & Unit Tests` for clarity.

Bumped package versions in `.csproj` files:
- `TiktokExplode.All.csproj`: 1.1.1 -> 1.2.0
- `TiktokExplode.Extensions.DependencyInjection.csproj`: 1.0.0 -> 1.1.0
- `TiktokExplode.Infrastructure.csproj`: 1.1.1 -> 1.2.0
- `TiktokExplode.csproj`: 1.1.1 -> 1.2.0
Add support for downloading TikTok carousel images.

- Implement DownloadImageAsync
- Implement DownloadCarouselImagesAsync
- Add progress reporting support
- Rename PromptDownloadAsync
- Add PromptDownloadCarouselAsync
- Generalize media download abstractions
- Improve URL handling and parsers
- Eliminate unnecessary usings
@Ts-Pytham Ts-Pytham added documentation Improvements or additions to documentation Breaking change labels Jun 12, 2026
@Ts-Pytham
Ts-Pytham merged commit beba7ca into master Jun 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking change documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

1 participant