Ejemplo n.º 1
0
        /// <summary>
        /// Compsosites a query, loads and parses the response
        /// </summary>
        /// <param name="title"></param>
        /// <returns>Obhect of type MovieInfo containing information about a particular movie</returns>
        /// <exception cref="MovieService.FailedToLoadMovieDBException">Throws exception when the query result file 
        /// fails to load</exception>
        /// <exception cref="MovieService.TitleNotFoundException">Throws exception when Omdb returns a false reponse 
        /// (the movie title does not exist in the database)</exception>
        public MovieInfo GetMovieInfo(string title)
        {
            string Url = baseUrl + "t=" + title;
            XDocument XDoc = null;
            MovieInfo Result = new MovieInfo();

            try
            {
                XDoc = XDocument.Load(Url);
            }
            catch(Exception)
            {
                throw new FailedToLoadMovieDBException("Error loading file. Please make sure you are connected to the intenet");
            }
            string response = XDoc.Descendants("root").Attributes("response").First().Value;
            if (XDoc != null && response == "True")
            {
                var MoviesQuery = from Root in XDoc.Root.Descendants("movie")
                                  select new
                                  {
                                      Title = Root.Attribute("title").Value,
                                      Year = Root.Attribute("year").Value,
                                      Rated = Root.Attribute("rated").Value,
                                      Released = Root.Attribute("released").Value,
                                      Runtime = Root.Attribute("runtime").Value,
                                      Genre = Root.Attribute("genre").Value,
                                      Director = Root.Attribute("director").Value,
                                      Writer = Root.Attribute("writer").Value,
                                      Actors = Root.Attribute("actors").Value,
                                      Plot = Root.Attribute("plot").Value,
                                      Language = Root.Attribute("language").Value,
                                      Country = Root.Attribute("country").Value,
                                      Awards = Root.Attribute("awards").Value,
                                      Rating = Root.Attribute("imdbRating").Value
                                  };
                var Movies = MoviesQuery.ToList();
                foreach (var Movie in Movies)
                {
                    Result.Title = Movie.Title;
                    Result.Year = Movie.Year;
                    Result.Rated = Movie.Rated;
                    Result.Released = Movie.Released;
                    Result.RunTime = Movie.Runtime;
                    Result.Genre = Movie.Genre;
                    Result.Director = Movie.Director;
                    Result.Writer = Movie.Writer;
                    Result.Actors = Movie.Actors;
                    Result.Plot = Movie.Plot;
                    Result.Language = Movie.Language;
                    Result.Country = Movie.Country;
                    Result.Awards = Movie.Awards;
                    Result.Rating = Movie.Rating;
                }
            }
            else
            {
                throw new TitleNotFoundException("Sorry, never heard of the movie " + title);
            }
            return Result;
        }
Ejemplo n.º 2
0
 public void OmdbGetMovieInfoTest()
 {
     OmdbService Service = OmdbService.Service;
     title = "The matrix";
     MovieInfo Expected = new MovieInfo();
     Expected.Title = "The Matrix";
     Expected.Year = "1999";
     Expected.Rated = "R";
     Expected.Released = "31 Mar 1999";
     Expected.RunTime = "136 min";
     Expected.Genre = "Action, Sci-Fi";
     Expected.Director = "Andy Wachowski, Lana Wachowski";
     Expected.Writer = "Andy Wachowski, Lana Wachowski";
     Expected.Actors = "Keanu Reeves, Laurence Fishburne, Carrie-Anne Moss, Hugo Weaving";
     Expected.Plot = "A computer hacker learns from mysterious rebels about the true nature of his reality and his role in the war against its controllers.";
     Expected.Language = "English";
     Expected.Country = "USA, Australia";
     Expected.Awards = "Won 4 Oscars. Another 33 wins & 40 nominations.";
     Expected.Rating = "8.7";
     MovieInfo Actual = Service.GetMovieInfo(title);
     Assert.AreEqual(Expected, Actual);
 }
Ejemplo n.º 3
0
 public void TmdbGetMovieInfoTest()
 {
     TmdbService Service = TmdbService.Service;
     title = "Batman Begins";
     MovieInfo Expected = new MovieInfo();
     Expected.Actors = "Missing data";
     Expected.Awards = "Missing data";
     Expected.Country = "Missing data";
     Expected.Director = "Missing data";
     Expected.Genre = " Action, Crime, Drama, ";
     Expected.Language = "en";
     Expected.Plot = "Driven by tragedy, billionaire Bruce Wayne dedicates his life to uncovering and defeating the corruption that plagues his home, Gotham City.  Unable to work within the system, he instead creates a new identity, a symbol of fear for the criminal underworld - The Batman.";
     Expected.Rated = "Missing data";
     Expected.Rating = "Missing data";
     Expected.Released = "2005-06-15";
     Expected.RunTime = "140";
     Expected.Title = "Batman Begins";
     Expected.Writer = "Missing data";
     Expected.Year = "Missing data";
     MovieInfo Actual = Service.GetMovieInfo(title);
     Assert.AreEqual(Expected, Actual);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Compsosites a query, loads and parses the response
 /// </summary>
 /// <param name="title"></param>
 /// <returns>Object of type MovieInfo containing information from selected movie</returns>
 /// <exception cref="MovieService.TitleNotFoundException">Throws exception when the query fails</exception>
 public MovieInfo GetMovieInfo(string title)
 {
     SearchResult Result = SearchMovie(title);
     MovieInfo MovieInfo = new MovieInfo();
     if (Result.Id.Count < 1)
     {
         throw new TitleNotFoundException("Title not found");
     }
     string Url = baseUrl + "movie/" + Result.Id[0] + "?api_key=" + apiKey;
     using (WebClient wc = new WebClient())
     {
         JObject Info = new JObject();
         try
         {
             var Json = wc.DownloadString(Url);
             Info = JObject.Parse(Json);
         }
         catch
         {
             throw new FailedToLoadMovieDBException("Error loading file. Please make sure you are connected to the intenet");
         }
         JArray Genres = new JArray();
         Genres = (JArray)Info["genres"];
         MovieInfo.Genre = " ";
         foreach (var EachGenre in Genres)
         {
             MovieInfo.Genre += (string)EachGenre["name"];
             MovieInfo.Genre += ", ";
         }
         MovieInfo.Language = (string)Info["original_language"];
         MovieInfo.Plot = (string)Info["overview"];
         MovieInfo.Released = (string)Info["release_date"];
         MovieInfo.RunTime = (string)Info["runtime"];
         MovieInfo.Title = (string)Info["original_title"];
         MovieInfo.Year = null;
         MovieInfo.Rated = null;
         MovieInfo.Director = null;
         MovieInfo.Writer = null;
         MovieInfo.Actors = null;
         MovieInfo.Country = null;
         MovieInfo.Awards = null;
         MovieInfo.Rating = null;
     }
     return MovieInfo;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Compsosites a query, loads and parses the response
        /// </summary>
        /// <param name="title"></param>
        /// <returns>Obhect of type MovieInfo containing information about a particular movie</returns>
        /// <exception cref="MovieService.FailedToLoadMovieDBException">Throws exception when the query result file
        /// fails to load</exception>
        /// <exception cref="MovieService.TitleNotFoundException">Throws exception when Omdb returns a false reponse
        /// (the movie title does not exist in the database)</exception>
        public MovieInfo GetMovieInfo(string title)
        {
            string    Url    = baseUrl + "t=" + title;
            XDocument XDoc   = null;
            MovieInfo Result = new MovieInfo();

            try
            {
                XDoc = XDocument.Load(Url);
            }
            catch (Exception)
            {
                throw new FailedToLoadMovieDBException("Error loading file. Please make sure you are connected to the intenet");
            }
            string response = XDoc.Descendants("root").Attributes("response").First().Value;

            if (XDoc != null && response == "True")
            {
                var MoviesQuery = from Root in XDoc.Root.Descendants("movie")
                                  select new
                {
                    Title    = Root.Attribute("title").Value,
                    Year     = Root.Attribute("year").Value,
                    Rated    = Root.Attribute("rated").Value,
                    Released = Root.Attribute("released").Value,
                    Runtime  = Root.Attribute("runtime").Value,
                    Genre    = Root.Attribute("genre").Value,
                    Director = Root.Attribute("director").Value,
                    Writer   = Root.Attribute("writer").Value,
                    Actors   = Root.Attribute("actors").Value,
                    Plot     = Root.Attribute("plot").Value,
                    Language = Root.Attribute("language").Value,
                    Country  = Root.Attribute("country").Value,
                    Awards   = Root.Attribute("awards").Value,
                    Rating   = Root.Attribute("imdbRating").Value
                };
                var Movies = MoviesQuery.ToList();
                foreach (var Movie in Movies)
                {
                    Result.Title    = Movie.Title;
                    Result.Year     = Movie.Year;
                    Result.Rated    = Movie.Rated;
                    Result.Released = Movie.Released;
                    Result.RunTime  = Movie.Runtime;
                    Result.Genre    = Movie.Genre;
                    Result.Director = Movie.Director;
                    Result.Writer   = Movie.Writer;
                    Result.Actors   = Movie.Actors;
                    Result.Plot     = Movie.Plot;
                    Result.Language = Movie.Language;
                    Result.Country  = Movie.Country;
                    Result.Awards   = Movie.Awards;
                    Result.Rating   = Movie.Rating;
                }
            }
            else
            {
                throw new TitleNotFoundException("Sorry, never heard of the movie " + title);
            }
            return(Result);
        }