lay295 / TwitchDownloader

Twitch VOD/Clip Downloader - Chat Download/Render/Replay
MIT License
2.64k stars 260 forks source link

Video downloader builder #893

Open ScrubN opened 9 months ago

ScrubN commented 9 months ago

Checklist

Write your feature request here

The idea is to replace the current video downloader with an abstract VideoDownloaderBuilder of sorts. The goal is to reduce duplicate code and early return statements that would be necessary for implementing some features that change the current logic flow. This would also make destination file type checking come naturally and enable CLI filename templates to be generated during a video info fetching stage.

Example API:

async Task BtnDownloadVideo_OnClick()
{
    var builder = new VideoDownloaderBuilder(videoDownloadOptions, progressHandler)
       .GetVideoInfo()
       .DownloadVideoParts()
       .CombineVideoParts()
       .TranscodeToMp4();

    var downloader = builder.ToDownloader();
    await downloader.RunAsync();
}

Something of this sort would allow us to swap out entire steps without having to touch some existing code and risk breaking it.

i.e. the kick downloader can be reduced to a 1-method change, since the only meaningful difference between it and the twitch video downloader is the video info step:

async Task BtnDownloadVideo_OnClick()
{
    var builder = new VideoDownloaderBuilder(videoDownloadOptions, progressHandler)
       .GetKickVideoInfo()
       .DownloadVideoParts()
       .CombineVideoParts()
       .TranscodeToMp4();

    var downloader = builder.ToDownloader();
    await downloader.RunAsync();
}

Or changing the file output is made easier too, without needing to bloat the downloader with early-return logic if a step is not needed.

i.e. making the output a TS file could be:

async Task BtnDownloadVideo_OnClick()
{
    var builder = new VideoDownloaderBuilder(videoDownloadOptions, progressHandler)
       .GetVideoInfo()
       .DownloadVideoParts()
       .CombineVideoParts()
       .CopyToDestination();

    var downloader = builder.ToDownloader();
    await downloader.RunAsync();
}
ScrubN commented 9 months ago

This could also be incorporated into a UI element somewhere, allowing users see a visual tree of the steps the downloader is going to perform.

ScrubN commented 9 months ago

After more thought, the video info should be passed into the builder so we aren't making duplicate requests. It might not seem like a problem, but twitch seems to be A-B testing some API changes and since we don't have a consistent device ID we can get different responses in the UI and the downloader.