示例#1
0
        private List <Category> GetProgramCategoriesAndVideos(Category parentCategory)
        {
            string          slug      = (parentCategory as RssLink).Url;
            int             articleId = GetWebData <JObject>(string.Format("http://www.svtplay.se/api/title?slug={0}", slug))["articleId"].Value <int>();
            List <Category> cats      = new List <Category>();
            SvtCategory     programs  = new SvtCategory()
            {
                Name             = "Avsnitt",
                Videos           = new List <VideoInfo>(),
                ParentCategory   = parentCategory,
                HasSubCategories = false,
                Url = string.Format("http://www.svtplay.se/api/title_episodes_by_article_id?articleId={0}", articleId)
            };

            cats.Add(programs);
            SvtCategory clips = new SvtCategory()
            {
                Name             = "Klipp",
                Videos           = new List <VideoInfo>(),
                ParentCategory   = parentCategory,
                HasSubCategories = false,
                Url = string.Format("http://www.svtplay.se/api/title_clips_by_title_article_id?articleId={0}", articleId)
            };

            cats.Add(clips);
            RssLink related = new RssLink()
            {
                Name             = "Liknande program",
                ParentCategory   = parentCategory,
                SubCategories    = new List <Category>(),
                HasSubCategories = true
            };

            related.Other = (Func <List <Category> >)(() => GetCategoriesFromArray(related, string.Format("http://www.svtplay.se/api/similar_content_for_title?slug={0}", slug) + "&dummy={0}", 0));
            cats.Add(related);
            foreach (SvtCategory cat in cats.Where(c => !c.HasSubCategories))
            {
                string data = GetWebData <string>(cat.Url);
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    cat.Videos = GetVideos(JArray.Parse(data));
                }
                else
                {
                    cat.Videos = new List <VideoInfo>();
                }
            }
            if (programs.Videos.Count == 0)
            {
                cats.Remove(programs);
            }
            if (clips.Videos.Count == 0)
            {
                cats.Remove(clips);
            }
            return(cats);
        }
        public override List<SearchResultItem> Search(string query, string category = null)
        {
            List<SearchResultItem> searchResultItems = new List<SearchResultItem>();
            List<Category> categories = new List<Category>();
            JObject json = GetWebData<JObject>(string.Format("http://www.svtplay.se/api/search_page?q={0}", HttpUtility.UrlEncode(query)));
            if (json["categories"] != null && json["categories"].Type == JTokenType.Array)
            {
                Category genres = new Category()
                {
                    Name = "Genrer",
                    HasSubCategories = true,
                    SubCategoriesDiscovered = true,
                    SubCategories = new List<Category>()
                };
                foreach (JToken item in json["categories"].Value<JArray>())
                {
                    genres.SubCategories.Add(new RssLink()
                    {
                        Name = item["name"].Value<string>(),
                        Url = item["urlPart"].Value<string>().Replace("genre/", "").Replace("/", ""),
                        Thumb = item["posterImageUrl"].Value<string>(),
                        HasSubCategories = true,
                        SubCategories = new List<Category>()
                    });

                }
                genres.SubCategories.ForEach(c => c.Other = (Func<List<Category>>)(() => GetTagCategories(c)));
                if (genres.SubCategories.Count > 0)
                    categories.Add(genres);
            }
            if (json["titles"] != null && json["titles"].Type == JTokenType.Array)
            {
                Category titles = new Category()
                {
                    Name = "Program",
                    HasSubCategories = true,
                    SubCategoriesDiscovered = true,
                    SubCategories = new List<Category>()
                };
                foreach (JToken item in json["titles"].Value<JArray>())
                {
                    titles.SubCategories.Add(new RssLink()
                    {
                        Name = item["programTitle"].Value<string>(),
                        Url = item["contentUrl"].Value<string>().Replace("/", ""),
                        Thumb = item["image"].Value<string>().Replace("{format}", "medium"),
                        Description = item["description"].Value<string>(),
                        HasSubCategories = true,
                        SubCategories = new List<Category>()
                    });

                }
                titles.SubCategories.ForEach(t => t.Other = (Func<List<Category>>)(() => GetProgramCategoriesAndVideos(t)));
                if (titles.SubCategories.Count > 0)
                    categories.Add(titles);
            }
            
            List<SvtCategory> videoCategories = new List<SvtCategory>();
            SvtCategory episodes = new SvtCategory()
            {
                Name = "Avsnitt",
                Videos = new List<VideoInfo>(),
                HasSubCategories = false,
                Url = "episodes"
            };
            videoCategories.Add(episodes);
            SvtCategory live = new SvtCategory()
            {
                Name = "Livesändningar",
                Videos = new List<VideoInfo>(),
                HasSubCategories = false,
                Url = "live"
            };
            videoCategories.Add(live);
            SvtCategory clips = new SvtCategory()
            {
                Name = "Klipp",
                Videos = new List<VideoInfo>(),
                HasSubCategories = false,
                Url = "clips"
            };
            videoCategories.Add(clips);
            SvtCategory openArchive = new SvtCategory()
            {
                Name = "Öppet arkiv",
                Videos = new List<VideoInfo>(),
                HasSubCategories = false,
                Url = "openArchive"
            };
            videoCategories.Add(openArchive);
            videoCategories.ForEach((cat) => ((SvtCategory)cat).Videos = GetVideos(json[cat.Url].Value<JArray>()));
            if (episodes.Videos.Count == 0)
                videoCategories.Remove(episodes);
            if (clips.Videos.Count == 0)
                videoCategories.Remove(clips);
            if (live.Videos.Count == 0)
                videoCategories.Remove(live);
            if (openArchive.Videos.Count == 0)
                videoCategories.Remove(openArchive);
            categories.AddRange(videoCategories);
            categories.ForEach(c => searchResultItems.Add(c));
            return searchResultItems;
        }
        private List<Category> GetTagCategories(Category parentCategory)
        {
            JArray jArray;
            string data;
            List<Category> cats = new List<Category>();

            Category contents = new Category()
            {
                Name = "Program A-Ö",
                ParentCategory = parentCategory,
                SubCategories = new List<Category>(),
                HasSubCategories = true,
                SubCategoriesDiscovered = true
            };
            if ((parentCategory as RssLink).Url == "oppetarkiv")
            {
                data = GetWebData("http://www.oppetarkiv.se/program");
                Regex r = new Regex(@"<a\s+class=""svtoa-anchor-list-link""\s+href=""(?<url>[^""]*).*?>(?<title>[^<]*)", RegexOptions.Singleline);
                foreach (Match m in r.Matches(data))
                {
                    if (m.Success)
                    {
                        RssLink programCategoriesAndVideos = new RssLink()
                        {
                            Name = HttpUtility.HtmlDecode(m.Groups["title"].Value),
                            Url = string.Concat("http://www.oppetarkiv.se", m.Groups["url"].Value, "?sida={0}&sort=tid_stigande&embed=true"),
                            HasSubCategories = false,
                            ParentCategory = parentCategory
                        };
                        programCategoriesAndVideos.Other = (Func<List<Category>>)(() => GetProgramCategoriesAndVideos(programCategoriesAndVideos));
                        cats.Add(programCategoriesAndVideos);
                    }
                }
            }
            else
            {
                string progData = GetWebData<string>(string.Concat("http://www.svtplay.se/api/cluster_titles_and_episodes/?cluster=", (parentCategory as RssLink).Url));
                jArray = JArray.Parse(progData);
                foreach (JToken token in jArray)
                {
                    RssLink genreCategory;
                    bool isVideoEpisode = token["contentType"] != null && token["contentType"].Type == JTokenType.String && token["contentType"].Value<string>() == "videoEpisod";
                    if (!isVideoEpisode)
                        genreCategory = new RssLink();
                    else
                        genreCategory = new SvtCategory();
                    genreCategory.ParentCategory = contents;
                    genreCategory.Name = token["programTitle"].Value<string>();
                    if (token["description"] != null && token["description"].Type != JTokenType.Null)
                        genreCategory.Description = token["description"].Value<string>();
                    if (token["poster"] != null && token["poster"].Type != JTokenType.Null)
                        genreCategory.Thumb = token["poster"].Value<string>().Replace("{format}", "medium");
                    genreCategory.HasSubCategories = !isVideoEpisode;
                    if (!isVideoEpisode)
                        genreCategory.Url = token["contentUrl"].Value<string>().Replace("/", "");
                    else if (genreCategory is SvtCategory)
                        (genreCategory as SvtCategory).Videos = GetVideos(new JArray() { token });
                    if (!isVideoEpisode)
                        genreCategory.Other = (Func<List<Category>>)(() => GetProgramCategoriesAndVideos(genreCategory));
                    contents.SubCategories.Add(genreCategory);
                }
                cats.Add(contents);
                data = GetWebData<string>(string.Concat("http://www.svtplay.se/api/cluster_popular?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory popular = new SvtCategory()
                        {
                            Name = "Populärt",
                            ParentCategory = parentCategory,
                            Videos = GetVideos(jArray)
                        };
                        cats.Add(popular);
                    }
                }
                data = GetWebData<string>(string.Concat("http://www.svtplay.se/api/cluster_latest?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory latest = new SvtCategory()
                        {
                            Name = "Senaste program",
                            ParentCategory = parentCategory,
                            Videos = GetVideos(jArray)
                        };
                        cats.Add(latest);
                    }
                }
                data = GetWebData<string>(string.Concat("http://www.svtplay.se/api/cluster_last_chance?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory lastChance = new SvtCategory()
                        {
                            Name = "Sista chansen",
                            ParentCategory = parentCategory,
                            Videos = GetVideos(jArray)
                        };
                        cats.Add(lastChance);
                    }
                }
                data = GetWebData<string>(string.Concat("http://www.svtplay.se/api/cluster_clips?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory clips = new SvtCategory()
                        {
                            Name = "Senaste klipp",
                            ParentCategory = parentCategory,
                            Videos = GetVideos(jArray)
                        };
                        cats.Add(clips);
                    }
                }
            }
            return cats;
        }
 private List<Category> GetProgramCategoriesAndVideos(Category parentCategory)
 {
     List<Category> cats = new List<Category>();
     SvtCategory programs = new SvtCategory()
     {
         Name = "Avsnitt",
         Videos = new List<VideoInfo>(),
         ParentCategory = parentCategory,
         HasSubCategories = false,
         Url = "episodes"
     };
     cats.Add(programs);
     SvtCategory clips = new SvtCategory()
     {
         Name = "Klipp",
         Videos = new List<VideoInfo>(),
         ParentCategory = parentCategory,
         HasSubCategories = false,
         Url = "clipsResult"
     };
     cats.Add(clips);
     SvtCategory related = new SvtCategory()
     {
         Name = "Liknande program",
         Videos = new List<VideoInfo>(),
         ParentCategory = parentCategory,
         HasSubCategories = false,
         Url = "videosInSameCategory"
     };
     cats.Add(related);
     JToken json = GetWebData<JObject>(string.Format("http://www.svtplay.se/api/title_page?title={0}", (parentCategory as RssLink).Url))["relatedVideos"];
     foreach (SvtCategory cat in cats)
     {
         JToken jCat = json[cat.Url];
         JArray jVideos = null;
         if (jCat.Type == JTokenType.Array)
             jVideos = jCat.Value<JArray>();
         else if (jCat["entries"] != null && jCat["entries"].Type != JTokenType.Null && jCat["entries"].Type == JTokenType.Array)
             jVideos = jCat["entries"].Value<JArray>();
         cat.Videos = GetVideos(jVideos);
     }
     if (programs.Videos.Count == 0)
         cats.Remove(programs);
     if (clips.Videos.Count == 0)
         cats.Remove(clips);
     if (related.Videos.Count == 0)
         cats.Remove(related);
     return cats;
 }
示例#5
0
        public override List <SearchResultItem> Search(string query, string category = null)
        {
            List <SearchResultItem> searchResultItems = new List <SearchResultItem>();
            List <Category>         categories        = new List <Category>();
            JObject json = GetWebData <JObject>(string.Format("https://www.svtplay.se/api/search?q={0}", HttpUtility.UrlEncode(query)));

            if (json["categories"] != null && json["categories"].Type == JTokenType.Array)
            {
                Category genres = new Category()
                {
                    Name                    = "Genrer",
                    HasSubCategories        = true,
                    SubCategoriesDiscovered = true,
                    SubCategories           = new List <Category>()
                };
                foreach (JToken item in json["categories"].Value <JArray>())
                {
                    genres.SubCategories.Add(new RssLink()
                    {
                        Name             = item["name"].Value <string>(),
                        Url              = item["contentUrl"].Value <string>().Replace("genre/", "").Replace("/", ""),
                        Thumb            = item["thumbnailImage"] != null && item["thumbnailImage"].Type != JTokenType.Null ? item["thumbnailImage"].Value <string>() : "",
                        HasSubCategories = true,
                        SubCategories    = new List <Category>()
                    });
                }
                genres.SubCategories.ForEach(c => c.Other = (Func <List <Category> >)(() => GetTagCategories(c)));
                if (genres.SubCategories.Count > 0)
                {
                    categories.Add(genres);
                }
            }
            if (json["videosAndTitles"] != null && json["videosAndTitles"].Type == JTokenType.Array)
            {
                Category titles = new Category()
                {
                    Name                    = "Program",
                    HasSubCategories        = true,
                    SubCategoriesDiscovered = true,
                    SubCategories           = new List <Category>()
                };
                foreach (JToken item in json["videosAndTitles"].Value <JArray>().Where(i => i["titleType"] == null))
                {
                    titles.SubCategories.Add(new RssLink()
                    {
                        Name             = item["programTitle"].Value <string>(),
                        Url              = item["contentUrl"].Value <string>().Replace("/", ""),
                        Thumb            = item["poster"] != null && item["poster"].Type != JTokenType.Null ? item["poster"].Value <string>().Replace("{format}", "medium") : "",
                        Description      = item["description"].Value <string>(),
                        HasSubCategories = true,
                        SubCategories    = new List <Category>()
                    });
                }
                titles.SubCategories.ForEach(t => t.Other = (Func <List <Category> >)(() => GetProgramCategoriesAndVideos(t)));
                if (titles.SubCategories.Count > 0)
                {
                    categories.Add(titles);
                }
                SvtCategory videos = new SvtCategory()
                {
                    Name             = "Videos",
                    HasSubCategories = false
                };
                JArray filtered = new JArray();
                foreach (JToken to in json["videosAndTitles"].Value <JArray>().Where(t => t["titleType"] != null))
                {
                    filtered.Add(to);
                }
                videos.Videos = GetVideos(filtered);
                if (videos.Videos.Count > 0)
                {
                    categories.Add(videos);
                }
            }
            if (json["openArchive"] != null && json["openArchive"].Type == JTokenType.Array)
            {
                SvtCategory openArchive = new SvtCategory()
                {
                    Name             = "Öppet arkiv",
                    HasSubCategories = false
                };
                openArchive.Videos = GetVideos(json["openArchive"].Value <JArray>());
                if (openArchive.Videos.Count > 0)
                {
                    categories.Add(openArchive);
                }
            }
            categories.ForEach(c => searchResultItems.Add(c));
            return(searchResultItems);
        }
示例#6
0
        private List <Category> GetTagCategories(Category parentCategory)
        {
            JArray          jArray;
            string          data;
            List <Category> cats = new List <Category>();

            Category contents = new Category()
            {
                Name                    = "Program A-Ö",
                ParentCategory          = parentCategory,
                SubCategories           = new List <Category>(),
                HasSubCategories        = true,
                SubCategoriesDiscovered = true
            };

            if ((parentCategory as RssLink).Url == "oppetarkiv")
            {
                data = GetWebData("http://www.oppetarkiv.se/program");
                Regex r = new Regex(@"<a\s+class=""svtoa-anchor-list-link""\s+href=""(?<url>[^""]*).*?>(?<title>[^<]*)", RegexOptions.Singleline);
                foreach (Match m in r.Matches(data))
                {
                    if (m.Success)
                    {
                        RssLink programCategoriesAndVideos = new RssLink()
                        {
                            Name             = HttpUtility.HtmlDecode(m.Groups["title"].Value),
                            Url              = string.Concat("http://www.oppetarkiv.se", m.Groups["url"].Value, "?sida={0}&sort=tid_stigande&embed=true"),
                            HasSubCategories = false,
                            ParentCategory   = parentCategory
                        };
                        programCategoriesAndVideos.Other = (Func <List <Category> >)(() => GetProgramCategoriesAndVideos(programCategoriesAndVideos));
                        cats.Add(programCategoriesAndVideos);
                    }
                }
            }
            else
            {
                string progData = GetWebData <string>(string.Concat("http://www.svtplay.se/api/cluster_titles_and_episodes/?cluster=", (parentCategory as RssLink).Url));
                jArray = JArray.Parse(progData);
                foreach (JToken token in jArray)
                {
                    RssLink genreCategory;
                    bool    isVideoEpisode = token["contentType"] != null && token["contentType"].Type == JTokenType.String && token["contentType"].Value <string>() == "videoEpisod";
                    if (!isVideoEpisode)
                    {
                        genreCategory = new RssLink();
                    }
                    else
                    {
                        genreCategory = new SvtCategory();
                    }
                    genreCategory.ParentCategory = contents;
                    genreCategory.Name           = token["programTitle"].Value <string>();
                    if (token["description"] != null && token["description"].Type != JTokenType.Null)
                    {
                        genreCategory.Description = token["description"].Value <string>();
                    }
                    if (token["poster"] != null && token["poster"].Type != JTokenType.Null)
                    {
                        genreCategory.Thumb = token["poster"].Value <string>().Replace("{format}", "medium");
                    }
                    genreCategory.HasSubCategories = !isVideoEpisode;
                    if (!isVideoEpisode)
                    {
                        genreCategory.Url = token["contentUrl"].Value <string>().Replace("/", "");
                    }
                    else if (genreCategory is SvtCategory)
                    {
                        (genreCategory as SvtCategory).Videos = GetVideos(new JArray()
                        {
                            token
                        });
                    }
                    if (!isVideoEpisode)
                    {
                        genreCategory.Other = (Func <List <Category> >)(() => GetProgramCategoriesAndVideos(genreCategory));
                    }
                    contents.SubCategories.Add(genreCategory);
                }
                cats.Add(contents);
                data = GetWebData <string>(string.Concat("http://www.svtplay.se/api/cluster_popular?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory popular = new SvtCategory()
                        {
                            Name                    = "Populärt",
                            ParentCategory          = parentCategory,
                            HasSubCategories        = true,
                            SubCategories           = new List <Category>(),
                            SubCategoriesDiscovered = true
                        };
                        foreach (JToken token in jArray)
                        {
                            RssLink popSubCategory;
                            bool    isVideoEpisode = token["contentType"] != null && token["contentType"].Type == JTokenType.String && token["contentType"].Value <string>() == "videoEpisod";
                            if (!isVideoEpisode)
                            {
                                popSubCategory = new RssLink();
                            }
                            else
                            {
                                popSubCategory = new SvtCategory();
                            }
                            popSubCategory.ParentCategory = popular;
                            popSubCategory.Name           = token["programTitle"].Value <string>();
                            if (token["description"] != null && token["description"].Type != JTokenType.Null)
                            {
                                popSubCategory.Description = token["description"].Value <string>();
                            }
                            if (token["poster"] != null && token["poster"].Type != JTokenType.Null)
                            {
                                popSubCategory.Thumb = token["poster"].Value <string>().Replace("{format}", "medium");
                            }
                            popSubCategory.HasSubCategories = !isVideoEpisode;
                            if (!isVideoEpisode)
                            {
                                popSubCategory.Url = token["contentUrl"].Value <string>().Replace("/", "");
                            }
                            else if (popSubCategory is SvtCategory)
                            {
                                (popSubCategory as SvtCategory).Videos = GetVideos(new JArray()
                                {
                                    token
                                });
                            }
                            if (!isVideoEpisode)
                            {
                                popSubCategory.Other = (Func <List <Category> >)(() => GetProgramCategoriesAndVideos(popSubCategory));
                            }
                            popular.SubCategories.Add(popSubCategory);
                        }
                        cats.Add(popular);
                    }
                }
                data = GetWebData <string>(string.Concat("http://www.svtplay.se/api/cluster_latest?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory latest = new SvtCategory()
                        {
                            Name           = "Senaste program",
                            ParentCategory = parentCategory,
                            Videos         = GetVideos(jArray)
                        };
                        cats.Add(latest);
                    }
                }
                data = GetWebData <string>(string.Concat("http://www.svtplay.se/api/cluster_last_chance?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory lastChance = new SvtCategory()
                        {
                            Name           = "Sista chansen",
                            ParentCategory = parentCategory,
                            Videos         = GetVideos(jArray)
                        };
                        cats.Add(lastChance);
                    }
                }
                data = GetWebData <string>(string.Concat("http://www.svtplay.se/api/cluster_clips?cluster=", (parentCategory as RssLink).Url));
                if (data.StartsWith("[") && data.EndsWith("]"))
                {
                    jArray = JArray.Parse(data);
                    if (jArray.Count > 0)
                    {
                        SvtCategory clips = new SvtCategory()
                        {
                            Name           = "Senaste klipp",
                            ParentCategory = parentCategory,
                            Videos         = GetVideos(jArray)
                        };
                        cats.Add(clips);
                    }
                }
            }
            return(cats);
        }
示例#7
0
        private List <Category> GetCategoriesFromArray(Category parentCategory, string url, int page)
        {
            JArray  array;
            JObject json = null;
            string  data = GetWebData <string>(string.Format(url, page));

            if (data.StartsWith("[") && data.EndsWith("]"))
            {
                array = JArray.Parse(data);
            }
            else
            {
                json  = JObject.Parse(data);
                array = json["data"].Value <JArray>();
            }
            List <Category> cats = new List <Category>();

            foreach (JToken token in array)
            {
                RssLink popSubCategory;
                bool    isVideoEpisode = token["contentType"] != null && token["contentType"].Type == JTokenType.String && token["contentType"].Value <string>() == "videoEpisod";
                if (!isVideoEpisode)
                {
                    popSubCategory = new RssLink();
                }
                else
                {
                    popSubCategory = new SvtCategory();
                }
                popSubCategory.ParentCategory = parentCategory;
                popSubCategory.Name           = token["programTitle"].Value <string>();
                if (token["description"] != null && token["description"].Type != JTokenType.Null)
                {
                    popSubCategory.Description = token["description"].Value <string>();
                }
                if (token["poster"] != null && token["poster"].Type != JTokenType.Null)
                {
                    popSubCategory.Thumb = token["poster"].Value <string>().Replace("{format}", "medium");
                }
                popSubCategory.HasSubCategories = !isVideoEpisode;
                if (!isVideoEpisode)
                {
                    popSubCategory.Url = token["contentUrl"].Value <string>().Replace("/", "");
                }
                else if (popSubCategory is SvtCategory)
                {
                    (popSubCategory as SvtCategory).Videos = GetVideos(new JArray()
                    {
                        token
                    });
                }
                if (!isVideoEpisode)
                {
                    popSubCategory.Other = (Func <List <Category> >)(() => GetProgramCategoriesAndVideos(popSubCategory));
                }
                cats.Add(popSubCategory);
            }
            if (json != null && json["totalPages"] != null && json["totalPages"].Type == JTokenType.Integer && json["totalPages"].Value <int>() > page)
            {
                NextPageCategory next = new NextPageCategory()
                {
                    ParentCategory = parentCategory
                };
                next.Other = (Func <List <Category> >)(() => GetCategoriesFromArray(parentCategory, url, page + 1));
                cats.Add(next);
            }
            return(cats);
        }
示例#8
0
        public override List <SearchResultItem> Search(string query, string category = null)
        {
            List <SearchResultItem> searchResultItems = new List <SearchResultItem>();
            List <Category>         categories        = new List <Category>();
            JObject json = GetWebData <JObject>(string.Format("http://www.svtplay.se/api/search?q={0}", HttpUtility.UrlEncode(query)));

            if (json["categories"] != null && json["categories"].Type == JTokenType.Array)
            {
                Category genres = new Category()
                {
                    Name                    = "Genrer",
                    HasSubCategories        = true,
                    SubCategoriesDiscovered = true,
                    SubCategories           = new List <Category>()
                };
                foreach (JToken item in json["categories"].Value <JArray>())
                {
                    genres.SubCategories.Add(new RssLink()
                    {
                        Name             = item["name"].Value <string>(),
                        Url              = item["contentUrl"].Value <string>().Replace("genre/", "").Replace("/", ""),
                        Thumb            = item["thumbnailImage"] != null && item["thumbnailImage"].Type != JTokenType.Null ? item["thumbnailImage"].Value <string>() : "",
                        HasSubCategories = true,
                        SubCategories    = new List <Category>()
                    });
                }
                genres.SubCategories.ForEach(c => c.Other = (Func <List <Category> >)(() => GetTagCategories(c)));
                if (genres.SubCategories.Count > 0)
                {
                    categories.Add(genres);
                }
            }
            if (json["titles"] != null && json["titles"].Type == JTokenType.Array)
            {
                Category titles = new Category()
                {
                    Name                    = "Program",
                    HasSubCategories        = true,
                    SubCategoriesDiscovered = true,
                    SubCategories           = new List <Category>()
                };
                foreach (JToken item in json["titles"].Value <JArray>())
                {
                    titles.SubCategories.Add(new RssLink()
                    {
                        Name             = item["programTitle"].Value <string>(),
                        Url              = item["contentUrl"].Value <string>().Replace("/", ""),
                        Thumb            = item["poster"] != null && item["poster"].Type != JTokenType.Null ? item["poster"].Value <string>().Replace("{format}", "medium") : "",
                        Description      = item["description"].Value <string>(),
                        HasSubCategories = true,
                        SubCategories    = new List <Category>()
                    });
                }
                titles.SubCategories.ForEach(t => t.Other = (Func <List <Category> >)(() => GetProgramCategoriesAndVideos(t)));
                if (titles.SubCategories.Count > 0)
                {
                    categories.Add(titles);
                }
            }

            List <SvtCategory> videoCategories = new List <SvtCategory>();
            SvtCategory        episodes        = new SvtCategory()
            {
                Name             = "Avsnitt",
                Videos           = new List <VideoInfo>(),
                HasSubCategories = false,
                Url = "episodes"
            };

            videoCategories.Add(episodes);
            SvtCategory live = new SvtCategory()
            {
                Name             = "Livesändningar",
                Videos           = new List <VideoInfo>(),
                HasSubCategories = false,
                Url = "live"
            };

            videoCategories.Add(live);
            SvtCategory clips = new SvtCategory()
            {
                Name             = "Klipp",
                Videos           = new List <VideoInfo>(),
                HasSubCategories = false,
                Url = "clips"
            };

            videoCategories.Add(clips);
            SvtCategory openArchive = new SvtCategory()
            {
                Name             = "Öppet arkiv",
                Videos           = new List <VideoInfo>(),
                HasSubCategories = false,
                Url = "openArchive"
            };

            videoCategories.Add(openArchive);
            videoCategories.ForEach((cat) => ((SvtCategory)cat).Videos = GetVideos(json[cat.Url].Value <JArray>()));
            if (episodes.Videos.Count == 0)
            {
                videoCategories.Remove(episodes);
            }
            if (clips.Videos.Count == 0)
            {
                videoCategories.Remove(clips);
            }
            if (live.Videos.Count == 0)
            {
                videoCategories.Remove(live);
            }
            if (openArchive.Videos.Count == 0)
            {
                videoCategories.Remove(openArchive);
            }
            categories.AddRange(videoCategories);
            categories.ForEach(c => searchResultItems.Add(c));
            return(searchResultItems);
        }