f52aa6123b
Replaces generic RawType with ByteDocument in downloaders and context classes, simplifying type usage. Adds builder classes for FailurePredicateOptions, FragmentOptions, SkipPredicateOptions, and UnitDownloaderOptions to improve configuration flexibility. Introduces DownloadTarget enum and SkipPredicate delegate for more granular download control. Refactors Fluent API interfaces and implementations to remove RawType generics and streamline usage. Adds Playwright and Stealth download strategies for extensibility.
38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using Beam.Models;
|
|
|
|
namespace Beam.Downloaders;
|
|
|
|
public record class UnitDownloaderOptions<OutType> {
|
|
public HttpClient Client { get; init; } = new();
|
|
|
|
public DownloadTarget Target { get; init; } = DownloadTarget.URL;
|
|
|
|
public SkipPredicateOptions<OutType>? SkipPredicateOptions { get; init; }
|
|
public FailurePredicateOptions<ByteDocument>? FailurePredicateOptions { get; init; }
|
|
public FragmentOptions? FragmentOptions { get; init; }
|
|
public required AsyncTransformer<ByteDocument, OutType> AsyncTransformer { get; init; }
|
|
|
|
/// <summary>
|
|
/// The location where the download is stored.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If not defined, <c>UnitDownloader.TryDownload()</c> downloads to memory.
|
|
/// </remarks>
|
|
public string? DownloadFolder { get; init; } = null;
|
|
public int BufferSize { get; init; } = 80 * 1024; // 80kb
|
|
|
|
public string GetFileNameForDownload(string url, byte[] additionalData) {
|
|
byte[] bytes = [..Encoding.UTF8.GetBytes(url), ..additionalData];
|
|
var name = Convert.ToBase64String(System.IO.Hashing.XxHash64.Hash(bytes));
|
|
return name.Replace('+', '-').Replace('/', '_').Replace('=', ' ').Trim();
|
|
}
|
|
}
|
|
|
|
// ---------- UnitDownloaderOptions Builder ----------
|
|
|
|
// ---------- FailurePredicateOptions Builder ----------
|
|
|
|
// ---------- FragmentOptions Builder ---------- |