Exemplo n.º 1
0
        public ParsData[] Parse(IHtmlDocument document)
        {
            var list  = new List <ParsData>();
            var items = document.QuerySelectorAll("li").Where(item =>
                                                              item.ClassName != null && item.ClassName.Contains("lessons-item"));
            int i = 1;

            foreach (var element in items)
            {
                var imageUrl = element.Children.FirstOrDefault(item =>
                                                               item.HasAttribute("itemprop") && item.Attributes["itemprop"].Value == "thumbnail");

                var videoUrl = element.Children.FirstOrDefault(item =>
                                                               item.HasAttribute("itemprop") && item.Attributes["itemprop"].Value == "url");

                var fileName = element.Children.FirstOrDefault(item =>
                                                               item.HasAttribute("itemprop") && item.Attributes["itemprop"].Value == "name");

                var data = new ParsData()
                {
                    ImageUrl = imageUrl.GetAttribute("href"),
                    WideoUrl = videoUrl.GetAttribute("href"),
                    FileName = $"{i}_{fileName.InnerHtml.Trim()}"
                };
                list.Add(data);
                ++i;
            }

            return(list.ToArray());
        }
Exemplo n.º 2
0
        private void Item_StartLoadClick(object sender, string filePatch)
        {
            MainGrupBox item = (MainGrupBox)sender;
            ParsData    data = (ParsData)item.Tag;

            Debug.WriteLine(data.WideoUrl);

            var    fileName   = Slug.OnlySeparatorFfriendly(data.FileName);
            string currentUrl = getCurrentUrl(filePatch, fileName, data.WideoUrl);

            Debug.WriteLine($"filePatch{filePatch}");
            Debug.WriteLine($"selectedFolder{_selectedFolder}");

            Debug.WriteLine($"currentUrl{currentUrl}");


            if (currentUrl == "")
            {
                item.StartSaveDialog();
                return;
            }

            var mFilleManager = new MainFileManager();

            var a = new EventHandler((s, e) =>
            {
                item.CurrentProgressBarPerceent = mFilleManager.Progres;
                item.LoadSpead = mFilleManager.LoadSpead;
            });

            mFilleManager.ChangedPercent += a;
            mFilleManager.DownloadEnd    += (o, e) => mFilleManager.ChangedPercent -= a;

            try
            {
                mFilleManager.DownloadFile(data.WideoUrl, currentUrl);
            }
            catch (Exception exception)
            {
                _mainMessageService.ShowError(exception.StackTrace);
            }
        }