/** * Updates a movie object with some more details. Fields must be the following (in this order): * * <ol> * <li><code>c03</code> (tagline) * <li><code>c01</code> (plot) * <li><code>c04</code> (number of votes) * <li><code>c18</code> (studio) * <li><code>c12</code> (parental rating) * <li><code>c19</code> (trailer) * </ol> * * @param response * @param movie * @return Updated movie object */ private Movie parseMovieDetails(String response, Movie movie) { String[] fields = response.split("<field>"); try { movie.tagline = Connection.trim(fields[1]); movie.plot = Connection.trim(fields[2]); movie.numVotes = Connection.trimInt(fields[3]); movie.studio = Connection.trim(fields[4]); movie.rated = Connection.trim(fields[5]); movie.trailerUrl = Connection.trim(fields[6]); } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); System.err.println("response = " + response); e.printStackTrace(); } return movie; }
/** * Converts query response from HTTP API to a list of Actor objects with roles attached. Each row * must return the following columns in the following order: * * <ol> * <li><code>idActor</code> * <li><code>strActor</code> * <li><code>strRole</code> * </ol> * * @param response * @return List of Actors */ public static ArrayList<Actor> parseActorRoles(String response) { ArrayList<Actor> actors = new ArrayList<Actor>(); String[] fields = response.split("<field>"); try { for (int row = 1; row < fields.length; row += 3) { actors.add( new Actor( Connection.trimInt(fields[row]), Connection.trim(fields[row + 1]), Connection.trim(fields[row + 2]))); } } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); System.err.println("response = " + response); e.printStackTrace(); } return actors; }
/** * Converts query response from HTTP API to a list of Movie objects. Each row must return the * following attributes in the following order: * * <ol> * <li><code>idMovie</code> * <li><code>c00</code> (title) * <li><code>c07</code> (year) * <li><code>strPath</code> * <li><code>strFileName</code> * <li><code>c15</code> (director) * <li><code>c11</code> (runtime) * <li><code>c14</code> (genres) * <li><code>c05</code> (rating) * </ol> * * @param response * @return List of movies */ private ArrayList<Movie> parseMovies(String response) { ArrayList<Movie> movies = new ArrayList<Movie>(); String[] fields = response.split("<field>"); try { for (int row = 1; row < fields.length; row += 10) { movies.add( new Movie( // int id, String title, int year, String path, String filename, String // director, String runtime, String genres, Double rating, int numWatched Connection.trimInt(fields[row]), Connection.trim(fields[row + 1]), Connection.trimInt(fields[row + 2]), Connection.trim(fields[row + 3]), Connection.trim(fields[row + 4]), Connection.trim(fields[row + 5]), Connection.trim(fields[row + 6]), Connection.trim(fields[row + 7]), Connection.trimDouble(fields[row + 8]), Connection.trimInt(fields[row + 9]))); } } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); System.err.println("response = " + response); e.printStackTrace(); } return movies; }
/** * Converts query response from HTTP API to a list of Genre objects. Each row must return the * following columns in the following order: * * <ol> * <li><code>idGenre</code> * <li><code>strGenre</code> * </ol> * * @param response * @return List of Genres */ public static ArrayList<Genre> parseGenres(String response) { ArrayList<Genre> genres = new ArrayList<Genre>(); String[] fields = response.split("<field>"); try { for (int row = 1; row < fields.length; row += 2) { genres.add(new Genre(Connection.trimInt(fields[row]), Connection.trim(fields[row + 1]))); } } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); System.err.println("response = " + response); e.printStackTrace(); } return genres; }