From 78ab8ecdde1d3728a1077f4156d5db4e554939e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20S=C3=A1nchez?= Date: Mon, 1 Jun 2026 17:40:53 -0500 Subject: [PATCH 01/18] Feat: Implement search and download client interfaces for TikTok video fetching --- .../Fetchers/Search/ISearchFetcher.cs | 6 ++++ .../Fetchers/Search/SearchFetchResult.cs | 13 +++++++ .../Domain/Abstractions/IDownloadClient.cs | 34 +++++++++++++++++++ .../Domain/Abstractions/ISearchClient.cs | 8 +++++ .../Domain/Abstractions/IVideoClient.cs | 27 +-------------- 5 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 TiktokExplode.Infrastructure/Fetchers/Search/ISearchFetcher.cs create mode 100644 TiktokExplode.Infrastructure/Fetchers/Search/SearchFetchResult.cs create mode 100644 TiktokExplode/Domain/Abstractions/IDownloadClient.cs create mode 100644 TiktokExplode/Domain/Abstractions/ISearchClient.cs diff --git a/TiktokExplode.Infrastructure/Fetchers/Search/ISearchFetcher.cs b/TiktokExplode.Infrastructure/Fetchers/Search/ISearchFetcher.cs new file mode 100644 index 0000000..3e2b964 --- /dev/null +++ b/TiktokExplode.Infrastructure/Fetchers/Search/ISearchFetcher.cs @@ -0,0 +1,6 @@ +namespace TiktokExplode.Infrastructure.Fetchers.Search; + +public interface ISearchFetcher +{ + IAsyncEnumerable FetchSearchAsync(string keyword, CancellationToken cancellationToken = default); +} diff --git a/TiktokExplode.Infrastructure/Fetchers/Search/SearchFetchResult.cs b/TiktokExplode.Infrastructure/Fetchers/Search/SearchFetchResult.cs new file mode 100644 index 0000000..13ed170 --- /dev/null +++ b/TiktokExplode.Infrastructure/Fetchers/Search/SearchFetchResult.cs @@ -0,0 +1,13 @@ +namespace TiktokExplode.Infrastructure.Fetchers.Search; + +public sealed record SearchFetchResult +{ + /// The raw JSON content of the search results returned by TikTok's search API. + public required string JsonContent { get; init; } + + /// + /// Session cookies captured during the page fetch. + /// These are injected into the download client to authenticate CDN video requests. + /// + public required IReadOnlyList Cookies { get; init; } +} diff --git a/TiktokExplode/Domain/Abstractions/IDownloadClient.cs b/TiktokExplode/Domain/Abstractions/IDownloadClient.cs new file mode 100644 index 0000000..287818c --- /dev/null +++ b/TiktokExplode/Domain/Abstractions/IDownloadClient.cs @@ -0,0 +1,34 @@ +using TiktokExplode.Domain.Entities; +using TiktokExplode.Domain.ValueObjects; + +namespace TiktokExplode.Domain.Abstractions; + +/// +/// Defines an interface for downloading TikTok videos, both with and without watermarks. +/// +public interface IDownloadClient : IAsyncDisposable +{ + /// + /// Downloads the video without watermark and returns a with the open stream. + /// The caller is responsible for disposing the returned . + /// + /// The whose download URL will be used. + /// Token to cancel the operation. + /// + /// A containing the open video stream and its exact size in bytes + /// as reported by the CDN Content-Length header. + /// + Task DownloadAsync(Video video, CancellationToken cancellationToken = default); + + /// + /// Downloads the video with TikTok's watermark overlay and returns a with the open stream. + /// The caller is responsible for disposing the returned . + /// + /// The whose watermarked download URL will be used. + /// Token to cancel the operation. + /// + /// A containing the open watermarked video stream and its exact size in bytes + /// as reported by the CDN Content-Length header. + /// + Task DownloadWatermarkedAsync(Video video, CancellationToken cancellationToken = default); +} \ No newline at end of file diff --git a/TiktokExplode/Domain/Abstractions/ISearchClient.cs b/TiktokExplode/Domain/Abstractions/ISearchClient.cs new file mode 100644 index 0000000..f1c03b3 --- /dev/null +++ b/TiktokExplode/Domain/Abstractions/ISearchClient.cs @@ -0,0 +1,8 @@ +using TiktokExplode.Domain.Entities; + +namespace TiktokExplode.Domain.Abstractions; + +public interface ISearchClient : IDownloadClient +{ + IAsyncEnumerable