Ejemplo n.º 1
0
 public bool PlayStart(ScrapedVideo video)
 {
     this.headerGroupVideoPlayer.ValuesPrimary.Heading = video.Title;
     this.currentPlayingVideo = video;
     UpdateFavouriteButton(DataService.Create().IsFavourite(this.currentPlayingVideo));
     return PlayStart(video.PlayUrl);
 }
 protected override void OnAddItem(ScrapedVideo video, bool select)
 {
     var found = false;
     LogManager.Log("Adding items to Veritcal gallery");
     foreach (Control c in this.tableLayoutPanel.Controls)
     {
         var widget = c as WebViewWidget;
         if (widget != null)
         {
             if (widget.Video.Url == video.Url)
             {
                 widget.SelectView();
                 found = true;
             }
             else
                 widget.DeselectView();
         }
     }
     if (!found)
     {
         var widget = AddItem(video);
         this.tableLayoutPanel.Controls.SetChildIndex(widget, 0);
         if (select)
             widget.SelectView();
     }
 }
Ejemplo n.º 3
0
 public override ScrapedVideo ScrapeVideoDetails(ScrapedVideo video)
 {
     var root = GotoUrl(video.Url);
     var flash = SelectItem(root, "#flash-player-embed");
     if (flash == null)
         return video;
     var flashVars = HttpUtility.UrlDecode(ReadAttribute(SelectItem(root, "#flash-player-embed"), "flashvars"));
     var beg = flashVars.IndexOf("flv_url=") + 8;
     var end = flashVars.IndexOf("&",beg);
     video.PlayUrl = HttpUtility.UrlDecode(flashVars.Substring(beg, end - beg));
     beg = root.InnerHtml.IndexOf("<script>videoPageWriteRelated(") + 30;
     end = root.InnerHtml.IndexOf(");</script>", beg);
     var obj = (JArray)JsonConvert.DeserializeObject(root.InnerHtml.Substring(beg, end - beg));
     foreach (var item in obj)
     {
         foreach (var subItem in item)
         {
             if (subItem["u"] != null)
             {
                 video.RelatedVideos.Add(new ScrapedVideo
                 {
                     Duration = TimeSpan.FromMinutes(Convert.ToInt32(Regex.Replace(subItem["d"].ToString(), "[^0-9.]", ""))),
                     ImageUrl = subItem["i"].ToString(),
                     Url = RootUrl + subItem["u"].ToString(),
                     Title = subItem["t"].ToString(),
                 });
             }
         }
     }
     if (String.IsNullOrEmpty(video.PlayUrl))
         throw new Exception("Unable to get video information");
     video.FullyLoaded = true;
     return video;
 }
Ejemplo n.º 4
0
        public void LoadVideo(ScrapedVideo video)
        {
            if (this.currentRequestedVideo == video && !video.FullyLoaded)
                return;
            Program.SetBusy();
            this.videoPlayerWidget.PlayStop();

            this.currentRequestedVideo = video;
            if (video.FullyLoaded)
                OnScrapVideoDetailsCompleted(video);
            else
                new ScraperService().ScrapVideosDetailsAsync(video, this);
        }
Ejemplo n.º 5
0
 public void ScrapVideosDetailsAsync(ScrapedVideo video, IScraperServiceCallback callback)
 {
     ThreadPool.QueueUserWorkItem(delegate {
         try
         {
             callback.OnScrapVideoDetailsCompleted(new XVideoScraper().ScrapeVideoDetails(video));
         }
         catch (Exception ex)
         {
             callback.OnScrapError(ex);
         }
     });
 }
 private WebViewWidget AddItem(ScrapedVideo video)
 {
     var widget = new WebViewWidget(video, Properties.Resources.TestHtml.Replace("{0}", video.Url).Replace("{1}", video.ImageUrl).
              Replace("{2}", video.Title).Replace("{3}", video.Duration.ToString()));
     widget.Anchor = AnchorStyles.Left | AnchorStyles.Right;
     widget.Width = this.Width;
     this.tableLayoutPanel.Controls.Add(widget);
     Application.DoEvents();
     widget.ViewSelected += delegate(object sender, GalleryItemSelectedEventArgs e)
     {
         OnItemSelected(sender, e);
     };
     return widget;
 }
Ejemplo n.º 7
0
 public WebViewWidget(ScrapedVideo video, string html)
     : this()
 {
     this.SuspendLayout();
     this.pictureBox.Visible = DataService.Create().IsFavourite(video);
     this.video = video;
     this.htmlPanel.Text = html;
     this.htmlPanel.AutoScroll = false;
     this.AutoScroll = false;
     this.htmlPanel.VerticalScroll.Enabled = false;
     this.htmlPanel.HorizontalScroll.Enabled = false;
     this.htmlPanel.VerticalScroll.Visible = false;
     this.htmlPanel.HorizontalScroll.Visible = false;
     this.ResumeLayout();
 }
Ejemplo n.º 8
0
        public override ScrapedVideo ScrapeVideoDetails(ScrapedVideo video)
        {
            var root  = GotoUrl(video.Url);
            var flash = SelectItem(root, "#flash-player-embed");

            if (flash == null)
            {
                return(video);
            }
            var flashVars = HttpUtility.UrlDecode(ReadAttribute(SelectItem(root, "#flash-player-embed"), "flashvars"));
            var beg       = flashVars.IndexOf("flv_url=") + 8;
            var end       = flashVars.IndexOf("&amp;", beg);

            video.PlayUrl = HttpUtility.UrlDecode(flashVars.Substring(beg, end - beg));
            beg           = root.InnerHtml.IndexOf("<script>videoPageWriteRelated(") + 30;
            end           = root.InnerHtml.IndexOf(");</script>", beg);
            var obj = (JArray)JsonConvert.DeserializeObject(root.InnerHtml.Substring(beg, end - beg));

            foreach (var item in obj)
            {
                foreach (var subItem in item)
                {
                    if (subItem["u"] != null)
                    {
                        video.RelatedVideos.Add(new ScrapedVideo
                        {
                            Duration = TimeSpan.FromMinutes(Convert.ToInt32(Regex.Replace(subItem["d"].ToString(), "[^0-9.]", ""))),
                            ImageUrl = subItem["i"].ToString(),
                            Url      = RootUrl + subItem["u"].ToString(),
                            Title    = subItem["t"].ToString(),
                        });
                    }
                }
            }
            if (String.IsNullOrEmpty(video.PlayUrl))
            {
                throw new Exception("Unable to get video information");
            }
            video.FullyLoaded = true;
            return(video);
        }
Ejemplo n.º 9
0
        private List <ScrapedVideo> ScrapThumbnailVideos(HtmlNode root)
        {
            var videos = new List <ScrapedVideo>();
            var items  = SelectItems(root, ".thumbBlock").ToList();

            foreach (var item in items)
            {
                var video = new ScrapedVideo();
                var elem  = SelectItem(item, ".thumb a");
                if (elem == null)
                {
                    elem           = SelectItem(item, "script");
                    elem.InnerHtml = elem.InnerHtml.Replace("castDisplayRandomThumb('", "").Replace("');</script>", "");
                    elem           = SelectItem(item, ".thumb a");
                }

                if (elem == null)
                {
                    Debug.Assert(true);
                }
                if (elem != null)
                {
                    video.Url      = RootUrl + ReadAttribute(elem, "href");
                    video.ImageUrl = ReadAttribute(SelectItem(item, ".thumb a img"), "src");
                    video.Title    = ReadText(SelectItem(item, ".thumbInside p a"));
                    var duration = ReadText(SelectItem(item, ".duration"));
                    var mc       = Regex.Matches(duration, @"\d+");
                    var hour     = duration.Contains("h") ? TimeSpan.FromHours(Convert.ToInt32(mc[0].Value)) : new TimeSpan();
                    var min      = duration.Contains("min") ? TimeSpan.FromMinutes(Convert.ToInt32(
                                                                                       duration.Contains("h") ? mc[1].Value : mc[0].Value)) : new TimeSpan();
                    var sec = duration.Contains("sec") ? TimeSpan.FromSeconds(Convert.ToInt32(mc[mc.Count - 1].Value)) : new TimeSpan();


                    video.Duration = hour + min + sec;
                    videos.Add(video);
                }
            }
            return(videos);
        }
Ejemplo n.º 10
0
 public abstract ScrapedVideo ScrapeVideoDetails(ScrapedVideo video);
Ejemplo n.º 11
0
 public abstract ScrapedVideo ScrapeVideoDetails(ScrapedVideo video);
Ejemplo n.º 12
0
 public void AddItem(ScrapedVideo video, bool select)
 {
     OnAddItem(video, select);
 }
Ejemplo n.º 13
0
 protected virtual void OnAddItem(ScrapedVideo video, bool select)
 {
 }
Ejemplo n.º 14
0
 public GalleryItemSelectedEventArgs(ScrapedVideo video)
 {
     Video = video;
 }
Ejemplo n.º 15
0
        public ScrapedVideo GetPreviousVideo(ScrapedVideo current)
        {
            int index = -1;
            for (var i = 0; i < WidgetContainer.Controls.Count; i++)
            {
                var v = WidgetContainer.Controls[i] as WebViewWidget ;
                if (v != null && v.Video == current)
                {
                    index = i;
                    break;
                }
            }

            if (GetWidgetCount() > 0)
            {
                if (index == -1 || index == 0)
                    return ((WebViewWidget)WidgetContainer.Controls[GetWidgetLastIndex()]).Video;
                else
                    return ((WebViewWidget)WidgetContainer.Controls[GetPreviousWidget(index)]).Video;
            }
            return null;
        }
Ejemplo n.º 16
0
 public void OnScrapVideoDetailsCompleted(ScrapedVideo video)
 {
 }
Ejemplo n.º 17
0
 public void PlayVideo(ScrapedVideo video)
 {
     ChangeView(this.viewerWindow);
     this.viewerWindow.LoadVideo(video);
 }
Ejemplo n.º 18
0
        private List<ScrapedVideo> ScrapThumbnailVideos(HtmlNode root)
        {
            var videos = new List<ScrapedVideo>();
            var items = SelectItems(root, ".thumbBlock").ToList();
            foreach (var item in items)
            {
                var video = new ScrapedVideo();
                var elem = SelectItem(item, ".thumb a");
                if (elem == null)
                {
                    elem = SelectItem(item, "script");
                    elem.InnerHtml = elem.InnerHtml.Replace("castDisplayRandomThumb('", "").Replace("');</script>", "");
                    elem = SelectItem(item, ".thumb a");

                }

                if (elem == null)
                    Debug.Assert(true);
                if (elem != null)
                {
                    video.Url = RootUrl + ReadAttribute(elem, "href");
                    video.ImageUrl = ReadAttribute(SelectItem(item, ".thumb a img"), "src");
                    video.Title = ReadText(SelectItem(item, ".thumbInside p a"));
                    var duration = ReadText(SelectItem(item, ".duration"));
                    var mc = Regex.Matches(duration, @"\d+");
                    var hour = duration.Contains("h") ? TimeSpan.FromHours(Convert.ToInt32(mc[0].Value)) : new TimeSpan();
                    var min = duration.Contains("min") ? TimeSpan.FromMinutes(Convert.ToInt32(
                        duration.Contains("h") ? mc[1].Value : mc[0].Value)) : new TimeSpan();
                    var sec = duration.Contains("sec") ? TimeSpan.FromSeconds(Convert.ToInt32(mc[mc.Count-1].Value)) : new TimeSpan();

                    video.Duration = hour + min + sec;
                    videos.Add(video);
                }
            }
            return videos;
        }
Ejemplo n.º 19
0
        public void OnScrapVideoDetailsCompleted(ScrapedVideo video)
        {
            this.InvokeEx(() =>
            {
                if (this.currentRequestedVideo == video)
                {

                    var played = this.videoPlayerWidget.PlayStart(video);

                    if (played)
                    {
                        this.verticalSingleColumnGalleryWidget1.AddItem(video, true);
                        this.relatedVideoGalleryWidget.ClearItems();
                        this.relatedVideoGalleryWidget.AddItems(new ScrapedPage { Videos = video.RelatedVideos });
                    }
                    else
                    {
                        this.currentRequestedVideo = null;
                    }
                }
                Program.SetIdle();
            });
        }
Ejemplo n.º 20
0
 public ScrapedVideo ScrapVideoDetails(ScrapedVideo video)
 {
     var scraper = new XVideoScraper();
     return scraper.ScrapeVideoDetails(video);
 }