예제 #1
0
        private List <DrakenVideo> GetVideos(DrakenCategorySelector selector = DrakenCategorySelector.none, string categoryNameSelector = null, uint size = 1024, string query = "", bool cache = true)
        {
            string             url    = string.Format(drakenVideosUrl, query, size);
            JObject            data   = ExtendedWebCache.Instance.GetWebData <JObject>(url, cache: cache);
            List <DrakenVideo> videos = new List <DrakenVideo>();

            foreach (JToken vt in data["hits"].Value <JArray>())
            {
                DrakenVideo video = new DrakenVideo();
                video.Airdate     = vt["year_of_release"].Value <string>();
                video.Countries   = vt["countries_of_origin_list"].Value <string>().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToList();
                video.Directors   = vt["director_list"].Value <string>().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToList();
                video.Genres      = vt["genre_list"].Value <string>().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToList();
                video.Keywords    = vt["keyword_list"].Value <string>().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToList();
                video.Languages   = vt["spoken_language_list"].Value <string>().Split(',').Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToList();
                video.Description = string.Format("{0} | {1} | {2}\n{3}", string.Join(", ", video.Genres), string.Join(", ", video.Directors), string.Join(", ", video.Countries), vt["summary"].Value <string>());
                video.Recommended = vt["recommended"] != null && vt["recommended"].Type == JTokenType.Boolean && vt["recommended"].Value <bool>();
                video.Thumb       = vt["image_background"].Value <string>();
                if (video.Thumb.StartsWith("//"))
                {
                    video.Thumb = "http:" + video.Thumb;
                }
                video.Title = vt["title"].Value <string>();
                string trailerPovider = (vt["trailer_provider"] == null || vt["trailer_provider"].Type != JTokenType.String) ? string.Empty : vt["trailer_provider"].Value <string>();
                if (trailerPovider == "vimeo")
                {
                    video.TrailerUrl = string.Format(vimeoVideoUrl, vt["trailer_id"].Value <string>());
                }
                else if (trailerPovider == "youtube")
                {
                    video.TrailerUrl = string.Format(youtubeVideoUrl, vt["trailer_id"].Value <string>());
                }
                else
                {
                    video.HasDetails = false;
                }
                video.VideoUrl = string.Format(drakenVideoUrl, vt["search_title"].Value <string>());
                videos.Add(video);
            }
            if (selector == DrakenCategorySelector.recommended)
            {
                videos = videos.Where(v => v.Recommended).ToList();
            }
            else if (selector != DrakenCategorySelector.none && !string.IsNullOrWhiteSpace(categoryNameSelector))
            {
                videos = videos.Where(v => v.getListFromSelector(selector).Any(t => t == categoryNameSelector)).ToList();
            }
            return(videos);
        }
예제 #2
0
            public List <string> getListFromSelector(DrakenCategorySelector selector)
            {
                List <string> list;

                switch (selector)
                {
                case DrakenCategorySelector.countries_of_origin_list:
                    list = Countries;
                    break;

                case DrakenCategorySelector.director_list:
                    list = Directors;
                    break;

                case DrakenCategorySelector.genre_list:
                    list = Genres;
                    break;

                case DrakenCategorySelector.keyword_list:
                    list = Keywords;
                    break;

                case DrakenCategorySelector.spoken_language_list:
                    list = Languages;
                    break;

                case DrakenCategorySelector.year_of_release:
                    list = new List <string>()
                    {
                        Airdate
                    };
                    break;

                default:
                    list = new List <string>();
                    break;
                }
                return(list);
            }