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.
47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using OpenQA.Selenium.Chrome;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Beam.Abstractions;
|
|
using Beam.Downloaders;
|
|
using Beam.Models;
|
|
using Beam.Stealth.Strategies;
|
|
|
|
namespace Beam.Stealth {
|
|
using File = System.IO.File;
|
|
|
|
public class StealthUnitDownloader<OutType> : UnitDownloader<OutType> {
|
|
public StealthConfig Config { get; }
|
|
public StealthAsyncManipulator Manipulator { get; }
|
|
private ILogger? Logger => Config.Logger;
|
|
|
|
private IDownloadStrategy _downloadStrategy { get; }
|
|
|
|
public StealthUnitDownloader(UnitDownloaderOptions<OutType> options, StealthConfig config, StealthAsyncManipulator manipulator) : base(options) {
|
|
Config = config;
|
|
Manipulator = manipulator;
|
|
|
|
_downloadStrategy = options.Target switch {
|
|
DownloadTarget.URL or DownloadTarget.InURL => new PageDownloadStrategy(),
|
|
DownloadTarget.Complex => new WaitingDownloadStrategy(),
|
|
_ => throw new NotSupportedException() // TODO add an exception message
|
|
};
|
|
}
|
|
|
|
protected override async Task DownloadToStream(string url, int bufferSize, Stream destinationStream,
|
|
IProgress<IDownloadReport> progress, CancellationToken ct) {
|
|
var driver = Config.Driver;
|
|
await driver.Navigate().GoToUrlAsync(url);
|
|
await Manipulator(driver);
|
|
|
|
await _downloadStrategy.DownloadToStream(url, bufferSize, destinationStream, progress, Config, Logger, ct);
|
|
}
|
|
|
|
|
|
}
|
|
}
|