コード例 #1
0
        /// <summary>
        /// Search video for Imdb
        /// </summary>
        /// <param name="parameters">Search parameters</param>
        /// <returns>Returns an instance of VideSearchResponse which contains video search result or error information </returns>
        public VideoSearchResponse SearchVideo(VideoSearchRequest parameters)
        {
            if (parameters == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(parameters.SearchQuery))
            {
                return(null);
            }

            string query = parameters.SearchQuery.Replace(" ", "+");
            VideoSearchResponse response = new VideoSearchResponse();

            this.RunSafely(() =>
            {
                RestOptions arguments                     = new RestOptions();
                arguments.Url                             = string.Format("{0}{1}", IMDB_API_URL, query);
                arguments.Method                          = RestMethod.Get;
                RestClient rest                           = new RestClient(arguments);
                ImdbResponseItemProxy restResult          = rest.MakeReqeust <ImdbResponseItemProxy>();
                IImdbVideoResponseAdapter imdbDataADapter = new ImdbAdapter();
                VideoItemCollection viodeItems            = imdbDataADapter.ToVideoItemCollection(restResult);
                response.Success(viodeItems);
            }, (ex) =>
            {
                response.Error("IMDBVideoProvider_SearchVideo", ex.Message, false);
            });
            return(response);
        }
コード例 #2
0
        /// <summary>
        /// Search video for Imdb
        /// </summary>
        /// <param name="parameters">Search parameters</param>
        /// <returns>Returns an instance of VideSearchResponse which contains video search result or error information </returns>
        public VideoSearchResponse SearchVideo(VideoSearchRequest parameters)
        {
            if (parameters == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(parameters.SearchQuery))
            {
                return(null);
            }

            VideoSearchResponse response = new VideoSearchResponse();

            this.RunSafely(() =>
            {
                var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                {
                    ApiKey = YOUTUBE_API_URL
                });

                SearchResource.ListRequest searchListRequest = youtubeService.Search.List(YOUTUBE_SEARCH_SNIPPET);
                searchListRequest.Q                   = parameters.SearchQuery;
                searchListRequest.MaxResults          = parameters.MaxResult;
                searchListRequest.VideoType           = SearchResource.ListRequest.VideoTypeEnum.Movie;
                searchListRequest.Type                = YOUTUBE_SEARCH_TYPE;
                SearchListResponse searchListResponse = searchListRequest.Execute();

                VideoItem temp                    = null;
                VideoItemCollection items         = new VideoItemCollection();
                YouTubeAdapter youTubeDataADapter = new YouTubeAdapter();
                if (searchListResponse != null)
                {
                    foreach (SearchResult eachItemFromYouTubeService in searchListResponse.Items)
                    {
                        temp = youTubeDataADapter.ToVideoItem(eachItemFromYouTubeService);
                        items.Add(temp);
                    }
                }

                response.Success(items);
            }, (ex) =>
            {
                response.Error("YoutubeVideoProvider_SearchVideo", ex.Message, false);
            });
            return(response);
        }