bezzad / Downloader

Fast, cross-platform and reliable multipart downloader with asynchronous progress events for .NET applications.
MIT License
1.25k stars 193 forks source link

The file is corrupted or download interrupted after the Tik Tok live link #120

Closed yinghualuowu closed 1 year ago

yinghualuowu commented 1 year ago

Tik Tok(Chinese: Douyin) link : http://pull-flv-l11.douyincdn.com/stage/stream-112064577612546193_or4.flv (expire when not live) use Downloader.Sample, Pause download and open the file,prompt that the file is damaged

private static List<DownloadItem> GetDownloadItems()
{
    List<DownloadItem> downloadList = new List<DownloadItem> {
        new DownloadItem {
            FolderPath = Path.GetTempPath(), Url = "http://pull-flv-l11.douyincdn.com/stage/stream-112064577612546193_or4.flv"
        }
    };
    return downloadList;
}

use nuget package callback DownloadFileCompleted event,But the live stream should be downloaded all the time

Test in WPF demo, on DownloadItemViewModel.cs have two funtion, WebClient in StartDownload() DownloadService in StartServiceDownload()

public void StartDownload()
{
    IsDownloading = true;
    HttpWebRequest request = (HttpWebRequest)FileWebRequest.Create(this.DownloadUrl);
    if (DownloadBytes > 0)
    {
        request.AddRange(DownloadBytes);
    }
    request.BeginGetResponse(ar => 
    {
        var response = request.EndGetResponse(ar);
        if (this.TotalBytes == 0) this.TotalBytes = response.ContentLength;
        using (var writer = new FileStream(this.FileName, FileMode.OpenOrCreate))
        {
            using (var stream = response.GetResponseStream())
            {
                while (IsDownloading)
                {
                    byte[] data = new byte[readBytes];
                    int readNumber = stream.Read(data, 0, data.Length);
                    if (readNumber > 0)
                    {
                        writer.Write(data, 0, readNumber);
                        this.DownloadBytes += readNumber;

                    }
                    if (this.DownloadBytes == this.TotalBytes)
                    {
                        Complete();
                    }
                }
            }
        }
    }, null);
}

DownDemo.zip

yinghualuowu commented 1 year ago

problem did not reappear today,I'll close this issues...