Esempio n. 1
0
        private OmdbMovieDetails GetMovieDetails(string imdbID)
        {
            var url = String.Format("http://www.omdbapi.com/?i={0}", imdbID);

            var json = GetHtmlFromUrl(url);

            OmdbMovieDetails omdbMovieDetails = JsonConvert.DeserializeObject <OmdbMovieDetails>(json);

            return(omdbMovieDetails);
        }
Esempio n. 2
0
        public XmlMovieElement GetMovieDetailsByImdbId(string imdbID)
        {
            // call the OmdbAPI
            OmdbMovieDetails omdbMovieDetails = GetMovieDetails(imdbID);

            XmlMovieElement ImdbDetails = new XmlMovieElement();

            ImdbDetails.Title             = String.Format("{0} ({1})", omdbMovieDetails.Title, omdbMovieDetails.Year);
            ImdbDetails.ImdbContentRating = omdbMovieDetails.Rated;
            ImdbDetails.ImdbLink          = String.Format(ConfigurationManager.AppSettings["ImdbContent"], omdbMovieDetails.imdbID);
            ImdbDetails.ImdbRating        = omdbMovieDetails.imdbRating;

            if (!omdbMovieDetails.Poster.Contains("N/A"))
            {
                var posterFilename = ImdbDetails.Title;
                // safen filename
                Array.ForEach(Path.GetInvalidFileNameChars(),
                              c => posterFilename = posterFilename.Replace(c.ToString(), String.Empty));

                var posterUrl = omdbMovieDetails.Poster;

                var posterSavePath = String.Format(@"{0}\{1}{2}",
                                                   ConfigurationManager.AppSettings["PosterBaseUrl"],
                                                   posterFilename,
                                                   Path.GetExtension(posterUrl));

                Image           posterImage    = null;
                HttpWebRequest  httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(posterUrl);
                HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Stream          stream         = httpWebReponse.GetResponseStream();
                posterImage = Image.FromStream(stream);

                // save poster image
                posterImage.Save(posterSavePath);
                posterImage.Dispose();

                ImdbDetails.ImdbPoster = Path.GetFileName(posterSavePath);
            }
            return(ImdbDetails);
        }