Sending updating status from IIS server (c#) back to Angular Client

Discussão em 'Angular' iniciado por D052057, Fevereiro 24, 2025.

  1. D052057

    D052057 Guest

    I have an Angular client tries to download video from a website thru a IIS server (c#). The download process is working now (I am using youtubeDLSharp Dll to do it). Things I don't know how to do it is to send data (like how much progress and text info) back to the Angular Client while the youtubeDLSharp processes. Here is the code in window exe platform:

    public MainWindow()
    {
    this.YoutubeDL = new YoutubeDL() { YoutubeDLPath = "yt-dlp.exe" };
    this.DataContext = this;
    InitializeComponent();
    progress = new Progress<DownloadProgress>((p) => showProgress(p));
    output = new Progress<string>((s) => txtOutput.AppendText(s + Environment.NewLine));
    }


    download process:


    if (AudioOnly)
    {
    result = await YoutubeDL.RunAudioDownload(
    url, AudioConversionFormat.Mp3, progress: progress,
    output: output, overrideOptions: custom
    );
    }
    else
    {

    result = await YoutubeDL.RunVideoDownload(
    url,
    progress: progress,
    output: output,
    overrideOptions: custom
    );

    }
    if (result.Success)
    {
    MessageBox.Show($"Successfully downloaded \"{url}\" to:\n\"{result.Data}\".", "YoutubeDLSharp");
    }
    private void showProgress(DownloadProgress p)
    {
    txtState.Text = p.State.ToString();
    progDownload.Value = p.Progress;
    txtProgress.Text = $"speed: {p.DownloadSpeed} | left: {p.ETA}";
    }



    The "process" and "output" are the info I need to send them back to the Angular client app. Here is my working code:

    [HttpGet("download")]
    public async Task<ActionResult> Download()
    {
    YoutubeDL youtubeDL = new()
    {
    YoutubeDLPath = @"yt-dlp.exe",
    FFmpegPath = @"ffmpeg.exe",
    OutputFolder = @"d:\medias\videos\animals",
    };
    var url = @"https://www.xxxxxxxxx.com/watch?v=xxxxxxxxxx";
    var result = await youtubeDL.RunVideoDownload(url);
    return Ok(result);
    }
    `


    Can this be done? Thanks.

    Continue reading...

Compartilhe esta Página