Exemple #1
0
        public override List <VideoInfo> GetVideos(Category category)
        {
            List <VideoInfo> videos = new List <VideoInfo>();

            currentCategory = category as YleCategory;
            HasNextPage     = false;
            if (currentCategory.IsSeries)
            {
                string  urlFormat = "https://programs-cdn.api.yle.fi/v1/episodes/{0}.json?availability=ondemand&limit=100&order=episode.hash%3Aasc%2Cpublication.starttime%3Aasc%2Ctitle.fi%3Aasc&app_id={1}&app_key={2}&offset={3}";
                JObject json      = GetWebData <JObject>(string.Format(urlFormat, currentCategory.Url, appInfo.AppId, appInfo.AppKey, currentSeriesVideoOffset));
                if (json["data"] != null && json["data"].Count() > 0)
                {
                    foreach (JToken data in json["data"])
                    {
                        VideoInfo video = GetVideoInfoFromJsonData(data, currentCategory.IsSeries);
                        if (video != null)
                        {
                            videos.Add(video);
                        }
                    }
                }
                int count = json["meta"]["count"].Value <int>();
                HasNextPage = count > currentSeriesVideoOffset + 100;
                if (HasNextPage)
                {
                    currentSeriesVideoOffset += 100;
                }
                else
                {
                    currentSeriesVideoOffset = 0;
                }
            }
            else
            {
                currentSeriesVideoOffset = 0;
                string    urlFormat = "http://arenan.yle.fi/api/programs/v1/id/{0}.json?app_id={1}&app_key={2}";
                JObject   json      = GetWebData <JObject>(string.Format(urlFormat, currentCategory.Url, appInfo.AppId, appInfo.AppKey));
                VideoInfo video     = GetVideoInfoFromJsonData(json["data"], currentCategory.IsSeries);
                if (video != null)
                {
                    videos.Add(video);
                }
            }
            return(videos);
        }
Exemple #2
0
        private void GetGenrePrograms(Category parentCategory, string apiUrl, int offset, int limit = 100, string sortOrder = "a-o")
        {
            string url = string.Format("{0}?o={1}&app_id={2}&app_key={3}&client=yle-areena-web&language={4}&v=5&offset={5}&limit={6}&filter.region={7}",
                                       apiUrl,
                                       sortOrder,
                                       appInfo.AppId,
                                       appInfo.AppKey,
                                       ApiLanguage,
                                       offset,
                                       limit,
                                       ApiRegion);
            List <Category> programs     = new List <Category>();
            JObject         json         = GetWebData <JObject>(url);
            int             noOfpackages = 0;

            foreach (JToken programToken in json["data"].Value <JArray>())
            {
                string type = programToken["pointer"]["type"].Value <string>();
                if (type != "package")
                {
                    YleCategory program = new YleCategory();
                    program.IsSeries       = type == "series";
                    program.Name           = programToken["title"].Value <string>();
                    program.Url            = programToken["labels"].First(t => t["type"].Value <string>() == "itemId")["raw"].Value <string>();
                    program.Description    = programToken["description"].Value <string>();
                    program.Thumb          = string.Format(imageFormat, programToken["image"]["id"].Value <string>());
                    program.ParentCategory = parentCategory;
                    programs.Add(program);
                }
                else
                {
                    noOfpackages++;
                }
            }
            if (programs.Count + noOfpackages >= limit)
            {
                NextPageCategory next = new NextPageCategory();
                next.Url            = apiUrl;
                next.Other          = (offset + limit).ToString();
                next.ParentCategory = parentCategory;
                programs.Add(next);
            }
            parentCategory.SubCategories.AddRange(programs);
        }
Exemple #3
0
        public override List <SearchResultItem> Search(string query, string category = null)
        {
            List <SearchResultItem> results = new List <SearchResultItem>();
            JObject json = GetWebData <JObject>(string.Format("https://areena.api.yle.fi/v1/ui/search?app_id=areena_web_personal_prod&app_key=6c64d890124735033c50099ca25dd2fe&client=yle-areena-web&language={0}&v=4&episodes=false&packages=false&query={1}&service=tv&limit=100", ApiLanguage, HttpUtility.UrlEncode(query)));

            foreach (JToken programToken in json["data"].Value <JArray>())
            {
                string      type    = programToken["pointer"]["type"].Value <string>();
                YleCategory program = new YleCategory();
                program.IsSeries    = type == "series";
                program.Name        = programToken["title"].Value <string>();
                program.Description = programToken["description"] != null ? programToken["description"].Value <string>() : "";
                program.Url         = programToken["pointer"]["uri"].Value <string>().Replace("yleareena://items/", "");
                program.Thumb       = programToken["image"] != null?string.Format(imageFormat, programToken["image"]["id"].Value <string>()) : "";

                results.Add(program);
            }
            return(results);
        }