Ejemplo n.º 1
0
        /// <summary>
        /// Gets the details.
        /// </summary>
        /// <param name="video">The movie.</param>
        /// <returns>Movie.</returns>
        public TVideo GetDetails <TVideo>(TVideo video)
            where TVideo : Video, new()
        {
            if (video.DetailsRetrieved)
            {
                return(video);
            }

            var videoType  = typeof(TVideo);
            var searchPath = videoType.GetCustomAttribute <SearchPathAttribute>()?.Path;

            if (string.IsNullOrWhiteSpace(searchPath))
            {
                throw new Exception($@"The video type {videoType.Name} does not have a search path.");
            }

            var requestQueries = new RequestQueryCollection {
                this.APIRequestQuery
            };
            var request  = RequestManager.CreateRequest(RequestMethod.GET, $@"{searchPath}/{video.ID}", requestQueries);
            var response = RequestManager.GetResponse <TVideo>(request);

            response.DetailsRetrieved = true;

            var responseAsMovie = response as Movie;

            if (responseAsMovie != null)
            {
                request = RequestManager.CreateRequest(RequestMethod.GET, $@"{searchPath}/{video.ID}/release_dates", requestQueries);
                var releaseDatesResponse = RequestManager.GetResponse <ReleaseDateResponse>(request);
                responseAsMovie.RegionReleaseDates = releaseDatesResponse.RegionReleaseDates;
            }
            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Searches the specified movie name.
        /// </summary>
        /// <typeparam name="TVideo">The type of the t video type.</typeparam>
        /// <param name="movieName">Name of the movie.</param>
        /// <returns>List&lt;TVideoType&gt;.</returns>
        public VideoCollection <TVideo> Search <TVideo>(string movieName)
            where TVideo : Video, new()
        {
            var videoType  = typeof(TVideo);
            var searchPath = videoType.GetCustomAttribute <SearchPathAttribute>()?.Path;

            if (string.IsNullOrWhiteSpace(searchPath))
            {
                throw new Exception($@"The video type {videoType.Name} does not have a search path.");
            }

            var videos     = new VideoCollection <TVideo>();
            var pageNumber = 1;

            while (true)
            {
                var requestQueries = new RequestQueryCollection {
                    this.APIRequestQuery,
                    new RequestQuery(@"query", movieName),
                    new RequestQuery(@"page", pageNumber.ToString()),
                    new RequestQuery(@"include_adult", bool.TrueString.ToLower())
                };

                var request  = RequestManager.CreateRequest(RequestMethod.GET, $@"search/{searchPath}", requestQueries);
                var response = RequestManager.GetResponse <SearchResponse <TVideo> >(request);
                videos.AddRange(response.Results);
                if (pageNumber >= response.TotalPages || response.Results.Count == 0)
                {
                    break;
                }
                pageNumber++;
            }
            return(videos);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the request.
        /// </summary>
        /// <param name="requestMethod">The request method.</param>
        /// <param name="path">The path.</param>
        /// <param name="requestQueries">The request queries.</param>
        /// <returns>HttpWebRequest.</returns>
        private static HttpWebRequest CreateRequest(RequestMethod requestMethod, string path, RequestQueryCollection requestQueries)
        {
            if (string.IsNullOrWhiteSpace(requestQueries[REQUEST_QUERY_NAME_API_KEY]?.QueryValue))
            {
                throw new VideoScraperException(null, @"The API key cannot be blank.");
            }

            var uriBuilder = new UriBuilder();

            uriBuilder.Scheme = URL_SCHEME;
            uriBuilder.Host   = $@"{URL_HOST}/{URL_VERSION}";
            uriBuilder.Path   = path;
            uriBuilder.Query  = requestQueries?.ToString();

            var request = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri);

            request.ContentType = @"application/json";
            request.Method      = requestMethod.ToString();

            return(request);
        }