Exemplo n.º 1
0
        private async Task DownloadFileAsync(MediaFileInfo mediaFileInfo)
        {
            using (var client = new WebClient())
            {
                client.DownloadProgressChanged += (sender, e) =>
                {
                    if (_bar == null)
                    {
                        //var options = new ProgressBarOptions()
                        //{
                        //    DisplayTimeInRealTime = false,
                        //    CollapseWhenFinished = true,
                        //    ProgressBarOnBottom = false,
                        //    ProgressCharacter = '*',

                        //};
                        _bar = new ProgressBar(e.TotalBytesToReceive);
                    }

                    if (CurrentPercent < e.ProgressPercentage)
                    {
                        CurrentPercent = e.ProgressPercentage;
                        var dataR = (e.BytesReceived / 1024m / 1024m).ToString("0.00");
                        var dataT = (e.TotalBytesToReceive / 1024m / 1024m).ToString("0.00");
                        _bar.Tick(e.BytesReceived, $"{_videoPage.Title} {dataR}MB /{dataT}MB");
                    }

                    //Console.WriteLine($"{_videoPage.Title} {e.ProgressPercentage}% {e.BytesReceived} {e.TotalBytesToReceive}");
                };
                string enumName = Enum.GetName(typeof(MediaFileType), mediaFileInfo.Type);

                await client.DownloadFileTaskAsync(new Uri(mediaFileInfo.FileUri), $@"{folder}{_videoPage.FileName}_{enumName}.{mediaFileInfo.Suffix}");
            }
        }
Exemplo n.º 2
0
        public void LoadMediaFileInfos()
        {
            try
            {
                using (var client = new WebClient())
                {
                    MediaFileInfos = MediaFileInfos ?? new List <MediaFileInfo>();
                    string htmlString   = client.DownloadString(Uri);
                    var    htmlDocument = new HtmlDocument();
                    htmlDocument.LoadHtml(htmlString);
                    var lis = htmlDocument.DocumentNode.ChildNodes.QuerySelectorAll("ul.download li");

                    foreach (var li in lis)
                    {
                        var file = new MediaFileInfo()
                        {
                            FileUri      = GetMediaFileUri(li),
                            FileSize     = GetMediaFileSize(li),
                            Type         = GetMediaFileType(li),
                            FileSizeUnit = GetMediaFileSizeUnit(li)
                        };
                        lock (syncRoot)
                        {
                            MediaFileInfos.Add(file);
                        }
                    }
                }
                BestQuality?.Print();
            }
            catch (Exception ex)
            {
                Console.WriteLine("//-------------------------Exception");
                Console.WriteLine($"Title: {Title}");
                Console.WriteLine($"Url: {Uri}");
                Console.WriteLine(ex.Message);
                Console.WriteLine("//-------------------------Exception End");
            }
        }