Beispiel #1
0
        public override int DiscoverSubCategories(Category parentCategory)
        {
            parentCategory.SubCategories = new List <Category>();

            string url = (parentCategory as RssLink).Url;

            HtmlDocument document = GetWebData <HtmlDocument>(url);

            if (document != null)
            {
                switch ((MuchMusic)parentCategory.Other)
                {
                case MuchMusic.Main:
                {
                    // main subcategories
                    string             xPath   = string.Format(mainCategoriesXpathFormat, parentCategory.Name);
                    HtmlNodeCollection anchors = document.DocumentNode.SelectNodes(xPath);
                    if (anchors != null)
                    {
                        foreach (HtmlNode anchor in anchors)
                        {
                            // skip some shows
                            if (skippedShowsRegex.Match(anchor.InnerText).Success)
                            {
                                continue;
                            }

                            parentCategory.SubCategories.Add(new RssLink()
                                {
                                    ParentCategory   = parentCategory,
                                    Name             = HttpUtility.HtmlDecode(anchor.InnerText),
                                    Url              = anchor.GetAttributeValue(@"href", string.Empty),
                                    HasSubCategories = true,
                                    Other            = MuchMusic.None
                                });
                        }
                    }
                    break;
                }

                case MuchMusic.None:
                {
                    HtmlNode showLogo = document.DocumentNode.SelectSingleNode(@"//div[@id = 'ShowInfo']/div[@id = 'ShowLogo']");
                    if (showLogo == null)
                    {
                        MuchMusic subcategoryType = MuchMusic.None;

                        HtmlNode subnav = document.DocumentNode.SelectSingleNode(@"//li[@id = 'episodesubnav']/a");

                        if (subnav != null && !url.EndsWith(@"/episodes/"))
                        {
                            // billyonthestreet
                            url = string.Format(@"{0}{1}", baseUrl, subnav.GetAttributeValue(@"href", string.Empty));
                            // follow subnavigation link
                            document = GetWebData <HtmlDocument>(url);
                        }

                        HtmlNode episodesAjax = document.DocumentNode.SelectSingleNode(@"//div[@id = 'EpisodesAjax']");
                        HtmlNode showInfo     = document.DocumentNode.SelectSingleNode(@"//div[@id = 'SecondaryContent']/div[@id = 'ShowInfo']");
                        HtmlNode nextVideo    = document.DocumentNode.SelectSingleNode(@"//div[@id = 'Episodes']/a[@id = 'NextVideo']");

                        if (nextVideo != null)
                        {
                            // mydatewith
                            subcategoryType = MuchMusic.EpisodesInFlatCarousel;
                        }
                        else if (episodesAjax != null || showInfo != null)
                        {
                            subcategoryType = MuchMusic.EpisodesWithAjax;
                            if (url.EndsWith(@"/episodes/"))
                            {
                                url = url.Replace(@"/episodes/", @"/ajax/loadepisodes.aspx?videoindex=0");
                            }
                        }
                        else
                        {
                            // degrassi
                            subcategoryType = MuchMusic.EpisodesInDottedCarousel;
                        }

                        parentCategory.SubCategories.Add(new RssLink()
                            {
                                ParentCategory   = parentCategory,
                                Name             = @"Episodes",
                                Url              = url,
                                Other            = subcategoryType,
                                HasSubCategories = false
                            });
                    }
                    else
                    {
                        // punkd
                        HtmlNodeCollection items = document.DocumentNode.SelectNodes(@"//div[@id = 'MainFeed']/ul/li[a]");
                        if (items != null)
                        {
                            foreach (HtmlNode item in items)
                            {
                                HtmlNode anchor          = item.SelectSingleNode(@"./a");
                                HtmlNode titleNode       = item.SelectSingleNode(@"./dl/dt");
                                HtmlNode descriptionNode = item.SelectSingleNode(@"./dl/dd");
                                parentCategory.SubCategories.Add(new RssLink()
                                    {
                                        ParentCategory   = parentCategory,
                                        Name             = titleNode.InnerText,
                                        Description      = descriptionNode.InnerText,
                                        Url              = string.Format(@"{0}{1}", url, anchor.GetAttributeValue(@"href", string.Empty)),
                                        Other            = MuchMusic.EpisodesPunkd,
                                        HasSubCategories = false
                                    });
                            }
                        }
                    }
                    break;
                }

                default:
                    throw new NotImplementedException(string.Format(@"Much Music Type: {0} has not been implemented", (MuchMusic)parentCategory.Other));
                }
            }

            parentCategory.SubCategoriesDiscovered = true;
            return(parentCategory.SubCategories.Count);
        }
Beispiel #2
0
        private List <VideoInfo> getVideoListForSinglePage(Category category, string url)
        {
            List <VideoInfo> result = new List <VideoInfo>();

            nextPageUrl     = string.Empty;
            currentCategory = category;
            MuchMusic type = category.Other != null ? (MuchMusic)category.Other : MuchMusic.None;

            HtmlDocument document = GetWebData <HtmlDocument>(url);

            if (document != null)
            {
                string xpath = string.Empty;
                switch (type)
                {
                case MuchMusic.EpisodesPunkd:
                    xpath = @"//ul/li[dl[dd[@class = 'Description']]]";
                    break;

                case MuchMusic.EpisodesInFlatCarousel:
                    xpath = @"//div[@id = 'EpisodesAjax']//ul/li[a]";
                    break;

                case MuchMusic.EpisodesInDottedCarousel:
                    xpath = @"//div[@id = 'EpisodesInner']//ul/li[a]";
                    break;

                default:
                    xpath = @"//ul/li[a]";
                    break;
                }
                HtmlNodeCollection items = document.DocumentNode.SelectNodes(xpath);

                if (items != null)
                {
                    foreach (HtmlNode item in items)
                    {
                        HtmlNode titleNode, descriptionNode;
                        HtmlNode img    = item.SelectSingleNode(@"./img");
                        HtmlNode anchor = item.SelectSingleNode(@"./a");

                        switch (type)
                        {
                        case MuchMusic.EpisodesPunkd:
                            img             = item.SelectSingleNode(@"./a/img");
                            titleNode       = item.SelectSingleNode(@"./dl/dt/a");
                            descriptionNode = item.SelectSingleNode(@"./dl/dd[@class = 'Description']");
                            break;

                        case MuchMusic.EpisodesInDottedCarousel:
                            titleNode       = item.SelectSingleNode(@"./dl/dt");
                            descriptionNode = item.SelectSingleNode(@"./dl/dd");
                            break;

                        case MuchMusic.EpisodesInFlatCarousel:
                            titleNode       = anchor.SelectSingleNode(@"./div/p");
                            descriptionNode = null;
                            break;

                        default:
                            if (img != null)
                            {
                                titleNode       = item.SelectSingleNode(@"./dl/dt");
                                descriptionNode = item.SelectSingleNode(@"./dl/dd");
                            }
                            else
                            {
                                titleNode       = anchor.SelectSingleNode(@"./dl/dt");
                                descriptionNode = anchor.SelectSingleNode(@"./dl/dd");
                                img             = anchor.SelectSingleNode(@"(./img)[2]");
                            }
                            break;
                        }

                        string imageUrl = img.GetAttributeValue(@"src", string.Empty);
                        if (imageUrl.Contains("imgurl="))
                        {
                            string[] urlParts = imageUrl.Split(new string[] { "imgurl=" }, StringSplitOptions.None);
                            imageUrl = urlParts[1];
                        }
                        string title = titleNode == null?item.SelectSingleNode(@"./a[@class = 'moreepstitle']").InnerText : titleNode.InnerText;

                        string description = descriptionNode == null ? string.Empty : descriptionNode.InnerText;
                        string videoUrl;
                        if (type.Equals(MuchMusic.EpisodesPunkd))
                        {
                            string href = anchor.GetAttributeValue(@"href", string.Empty);
                            videoUrl = new Uri(new Uri(url), href).AbsoluteUri;
                        }
                        else
                        {
                            videoUrl = string.Format(@"{0}{1}", baseUrl, anchor.GetAttributeValue(@"href", string.Empty));
                        }
                        result.Add(new VideoInfo()
                        {
                            VideoUrl    = videoUrl,
                            Title       = title,
                            Description = description,
                            Thumb       = imageUrl
                        });
                    }
                }

                double listItemCount = (double)document.CreateNavigator().Evaluate(@"count(//ul/li)");
                if (type != MuchMusic.EpisodesInDottedCarousel &&
                    type != MuchMusic.EpisodesPunkd &&
                    listItemCount == (NUM_EPISODES_PER_AJAX_REQUEST + 1))
                {
                    UriBuilder          builder    = new UriBuilder(url);
                    NameValueCollection parameters = HttpUtility.ParseQueryString(builder.Query);
                    int nextPageNumber             = int.Parse(parameters["videoindex"]) + NUM_EPISODES_PER_AJAX_REQUEST;
                    parameters["videoindex"] = Convert.ToString(nextPageNumber);
                    builder.Query            = parameters.ToString();
                    nextPageUrl = builder.Uri.ToString();
                }
            }
            return(result);
        }