コード例 #1
0
        public void WriteOutput(String outputFile, Movie info, DataFromFile parsedDataFromFile, FullCast cast)
        {
            XmlDocument document = new XmlDocument();

            XmlNode rootNode = document.CreateElement("movie");
            document.AppendChild(rootNode);

            XmlNode movieName = document.CreateElement("name");
            movieName.InnerText = parsedDataFromFile.getName();
            rootNode.AppendChild(movieName);

            XmlNode movieYear = document.CreateElement ("year");
            movieYear.InnerText = parsedDataFromFile.getYear();
            rootNode.AppendChild(movieYear);

            XmlNode movieRuntime = document.CreateElement("runtime");
            movieRuntime.InnerText = info.Runtime;
            rootNode.AppendChild(movieRuntime);

            XmlNode movieSynopsis = document.CreateElement("synopsis");
            movieSynopsis.InnerText = info.Synopsis;
            rootNode.AppendChild(movieSynopsis);

            XmlNode movieCast = document.CreateElement("cast");
            rootNode.AppendChild(movieCast);
            Actor[] actors = cast.Cast;
            foreach (Actor a in actors) {
                XmlNode movieCastActor = document.CreateElement("actor");
                movieCast.AppendChild(movieCastActor);

                XmlNode movieCastName = document.CreateElement("name");
                movieCastName.InnerText = a.Name;
                movieCastActor.AppendChild(movieCastName);

                String[] characters = a.Characters;
                foreach (String s in characters) {
                    XmlNode movieCastCharacter = document.CreateElement("character");
                    movieCastCharacter.InnerText = s;
                    movieCastActor.AppendChild(movieCastCharacter);
                }
            }

            document.Save(outputFile);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: pipt/rotten
        private static void processMovieInfo(Movie info, DataFromFile dataFromFile, String fullPath, ArrayList failedMovies)
        {
            //Check release year
            if (!dataFromFile.getYear().Equals(info.Year)) {
                failedMovies.Add(dataFromFile.getName());
                logger.log("Error - directory year " + dataFromFile.getYear() + " does not equal retrieved year " + info.Year);
                return;
            }

            //Grab full cast data
            String fullCastUrl = null;
            FullCast fullCast = new FullCast();
            info.Links.TryGetValue("cast", out fullCastUrl);

            if (fullCastUrl == null) {
                logger.log("Error - full cast url for " + dataFromFile.getName() + " was null");
            } else {
                String rottenCastJson = dataFetcher.getCastData(fullCastUrl);
                fullCast = dataParser.getCastParsedData(rottenCastJson);
            }

            //Get IMDB data for synopsis
            String imdbNumber = null;
            String imdbJson = null;
            info.Alternate_IDs.TryGetValue("imdb", out imdbNumber);

            if (imdbNumber == null) {
                logger.log("Error - IMDB number for " + dataFromFile.getName() + " was null");
            } else {
                imdbJson = imdbDataFetcher.getData(imdbNumber);
            }

            //Download the movie poster
            String posterUrl = null;
            info.Posters.TryGetValue("original", out posterUrl);
            if (posterUrl == null) {
                logger.log("Error - Poster url for movie " + dataFromFile.getName() + " was null");
            } else {
                saveCover(posterUrl, fullPath, failedMovies, dataFromFile.getName());
            }

            outputWriter.WriteOutput(fullPath + "//Info.xml", info, dataFromFile, fullCast);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: pipt/rotten
        public static void Main(string[] args)
        {
            logger = new Logger(logFile);

            dataFetcher = new GetInfo();
            dataParser = new DataParser();
            imdbDataFetcher = new GetIMDBInfo();
            imdbDataParser = new IMDBDataParser();
            outputWriter = new OutputWriter();

            String[] movieDirectory = GetMovieNames();
            logger.log("Fetched [" + movieDirectory.Length.ToString() + "] movies");

            foreach (String moviePath in movieDirectory) {
                logger.flush();

                String movieName = moviePath.Replace(baseDirectory + "/", "");
                logger.log("Processing [" + movieName + "]");

                //Split out the directory name to get title and year
                DataFromFile dataFromFile = new DataFromFile(movieName);
                logger.log ("Split directory name to name [" + dataFromFile.getName() + "] and year [" + dataFromFile.getYear() + "]");

                //Grab rotten tomatoes data
                String rottenJson = dataFetcher.getData(movieName);
                rottenJson = rottenJson.Trim();
                MovieInfo rottenParsed = dataParser.getParsedData(rottenJson);

                if (rottenParsed == null) {
                    failedMovies.Add(movieName);
                    logger.log("Failed to get rottentomatoes data for movie [" + movieName + "]");
                    continue;
                }

                processMovieInfo(rottenParsed.Movies[0], dataFromFile, moviePath, failedMovies);
            }

            logger.closeLog();
        }