Refactor code structure for improved readability and maintainability

This commit is contained in:
MaddoScientisto 2026-02-21 10:40:12 +01:00
commit 4f488bae45
78 changed files with 3309 additions and 1570 deletions

View file

@ -0,0 +1,50 @@
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace TwitchArchive.Core.Services
{
public class DownloaderService : IDownloaderService
{
private readonly IProcessRunner _runner;
public DownloaderService(IProcessRunner runner)
{
_runner = runner;
}
public async Task<bool> DownloadVodAsync(TwitchArchive.Core.Api.VodInfo vod, string outputPath, CancellationToken ct = default)
{
try
{
var bin = "TwitchDownloaderCLI"; // expect to be on PATH or configured elsewhere
Directory.CreateDirectory(Path.GetDirectoryName(outputPath) ?? ".");
var args = $"videodownload -u https://www.twitch.tv/videos/{(vod.Id.StartsWith("v") ? vod.Id.Substring(1) : vod.Id)} -q best -t 10 --ffmpeg-path ffmpeg --collision Rename -o \"{outputPath}\"";
var res = await _runner.RunAsync(new ProcessRunOptions { FileName = bin, Arguments = args, RedirectOutput = true }, ct).ConfigureAwait(false);
return res.ExitCode == 0;
}
catch
{
return false;
}
}
public async Task<bool> DownloadChatJsonAsync(string vodId, string jsonPath, CancellationToken ct = default)
{
try
{
var bin = "TwitchDownloaderCLI";
Directory.CreateDirectory(Path.GetDirectoryName(jsonPath) ?? ".");
if (vodId.StartsWith("v")) vodId = vodId.Substring(1);
var args = $"chatdownload --id {vodId} --embed-images --collision Rename -o \"{jsonPath}\"";
var res = await _runner.RunAsync(new ProcessRunOptions { FileName = bin, Arguments = args, RedirectOutput = true }, ct).ConfigureAwait(false);
return res.ExitCode == 0 && File.Exists(jsonPath);
}
catch
{
return false;
}
}
}
}