From d512452bc90b4b88416d55cc0c8d7da9e54618bc Mon Sep 17 00:00:00 2001 From: Herwig Birke Date: Thu, 5 Dec 2024 20:40:21 +0100 Subject: [PATCH] more fields --- lib/data/movies.dart | 89 ++++++++++++++++++++++++++ lib/widgets/movies/add/add_screen.dart | 84 ++++++++++++++++++++---- 2 files changed, 162 insertions(+), 11 deletions(-) diff --git a/lib/data/movies.dart b/lib/data/movies.dart index 9b2021a..ef5593c 100644 --- a/lib/data/movies.dart +++ b/lib/data/movies.dart @@ -1,3 +1,6 @@ +import 'package:logger/logger.dart'; +import 'package:multimedia/log_printer.dart'; + class Movie { int movieID; String movieTitle; @@ -7,6 +10,7 @@ class Movie { int state; String resolution; String backdropPath; + String posterPath; String languages; String productionCountries; String productionCompanies; @@ -16,6 +20,18 @@ class Movie { String crew; String genre; String localPath; + String imdbID; + String originalLanguage; + double popularity; + bool adult; + String belongsToCollection; + double budget; + String homepage; + double revenue; + int runtime; + String tagline; + + Logger logger = getLogger(); Movie({ required this.movieID, @@ -26,6 +42,7 @@ class Movie { required this.state, required this.resolution, required this.backdropPath, + required this.posterPath, //NEW STRING required this.languages, required this.productionCountries, required this.productionCompanies, @@ -35,6 +52,16 @@ class Movie { required this.crew, required this.genre, required this.localPath, + required this.imdbID, //NEW STRING + required this.originalLanguage, //NEW STRING + required this.popularity, //NEW FLOAT + required this.adult, //NEW BOOL/INT + required this.belongsToCollection, //NEW STRING + required this.budget, //NEW FLOAT + required this.homepage, //NEW STRING + required this.revenue, //NEW FLOAT + required this.runtime, //NEW INT + required this.tagline, //NEW STRING }); factory Movie.fromJson(Map json) { @@ -48,6 +75,7 @@ class Movie { state: int.parse(json['state']), resolution: json['resolution'] as String, backdropPath: json['backdropPath'] as String, + posterPath: json['posterPath'] as String, languages: json['languages'], productionCountries: json['productionCountries'], productionCompanies: json['productionCompanies'], @@ -57,6 +85,16 @@ class Movie { crew: json['crew'], genre: json['genre'], localPath: json['localpath'], + imdbID: json['imdbid'], + originalLanguage: json['originalLanguage'], + popularity: double.parse(json['popularity']), + adult: int.parse(json['adult']) == 0 ? false : true, + belongsToCollection: json['belongsToCollection'], + budget: double.parse(json['budget']), + homepage: json['homepage'], + revenue: double.parse(json['revenue']), + runtime: int.parse(json['runtime']), + tagline: json['tagline'], ); } return Movie( @@ -68,6 +106,7 @@ class Movie { state: int.parse(json['state']), resolution: json['resolution'] as String, backdropPath: '', + posterPath: '', languages: '', productionCountries: '', productionCompanies: '', @@ -77,6 +116,56 @@ class Movie { crew: '', genre: '', localPath: '', + imdbID: '', + originalLanguage: '', + popularity: 0, + adult: false, + belongsToCollection: '', + budget: 0, + homepage: '', + revenue: 0, + runtime: 0, + tagline: '', + ); + } + + factory Movie.fromJsonDynamic(Map json) { + // dynamic languages = json['languages']; + // dynamic productionCountries = json['productionCountries']; + // dynamic productionCompanies = json['productionCompanies']; + // dynamic cast = json['cast']; + // dynamic crew = json['crew']; + // dynamic genre = json['genre']; + + return Movie( + movieID: json['id'], + movieTitle: json['title'], + originalTitle: json['original_title'], + overview: json['overview'], + releaseDate: DateTime.parse(json['release_date'].toString()), + state: int.tryParse(['status'].toString()) ?? 0, + resolution: '', + backdropPath: json['backdrop_path'], + posterPath: '', + languages: '', + productionCountries: '', + productionCompanies: '', + voteAverage: double.tryParse(['vote_average'].toString()) ?? 0, + voteCount: int.tryParse(['vote_count'].toString()) ?? 0, + cast: '', + crew: '', + genre: '', + localPath: '', + imdbID: '', + originalLanguage: '', + popularity: 0, + adult: false, + belongsToCollection: '', + budget: 0, + homepage: '', + revenue: 0, + runtime: 0, + tagline: '', ); } } diff --git a/lib/widgets/movies/add/add_screen.dart b/lib/widgets/movies/add/add_screen.dart index 5c4a47e..fa5d6e6 100644 --- a/lib/widgets/movies/add/add_screen.dart +++ b/lib/widgets/movies/add/add_screen.dart @@ -232,6 +232,14 @@ class _AddMovieScreenState extends State { return data[field]; } + bool parseBool(dynamic data, String field) { + if (data[field] == Null) { + return false; + } + + return data[field]; + } + Future startSearch() async { if (movieTitleSearch.isEmpty) { return; @@ -299,8 +307,26 @@ class _AddMovieScreenState extends State { String overview = parseString(movie, 'overview'); DateTime releaseDate = parseDate(movie, 'release_date'); String backdropPath = parseString(movie, 'backdrop_path'); + String posterPath = parseString(movie, 'poster_path'); + String languages = ''; //MISSING + String productionCountries = ''; //MISSING + String productionCompanies = ''; //MISSING double voteAverage = parseDouble(movie, 'vote_average'); int voteCount = parseInt(movie, 'vote_count'); + String cast = ''; //MISSING + String crew = ''; //MISSING + String genre = ''; //DIFFERENT; + String localPath = ''; + String imdbID = ''; //MISSING + String originalLanguage = parseString(movie, 'original_language'); + double popularity = parseDouble(movie, 'popularity'); + bool adult = parseBool(movie, 'adult'); + String belongsToCollection = ''; //MISSING + double budget = 0; //MISSING + String homepage = ''; //MISSING + double revenue = 0; //MISSING + int runtime = 0; //MISSING + String tagline = ''; //MISSING if (!movieIDsTmp.contains(movieID)) { movieList.add(Movie( @@ -312,15 +338,26 @@ class _AddMovieScreenState extends State { state: 0, resolution: '', backdropPath: backdropPath, - languages: '', - productionCountries: '', - productionCompanies: '', + posterPath: posterPath, + languages: languages, + productionCountries: productionCountries, + productionCompanies: productionCompanies, voteAverage: voteAverage, voteCount: voteCount, - cast: '', - crew: '', - genre: '', - localPath: '', + cast: cast, + crew: crew, + genre: genre, + localPath: localPath, + imdbID: imdbID, + originalLanguage: originalLanguage, + popularity: popularity, + adult: adult, + belongsToCollection: belongsToCollection, + budget: budget, + homepage: homepage, + revenue: revenue, + runtime: runtime, + tagline: tagline, )); } } @@ -329,19 +366,44 @@ class _AddMovieScreenState extends State { } bool addMovies() { - int cnt = 0; + bool somethingFound = false; + + logger.i('addMovies'); for (int i = 0; i < movieList.length; i++) { Movie movie = movieList[i]; if (movie.state == 1) { - cnt++; + somethingFound = true; + addMovie(movieList[i].movieID); } } - if (cnt == 0) { - return false; + return somethingFound; + } + + Future addMovie(int movieID) async { + logger.i('addMovie'); + + String lang = 'de'; + + if (!searchGerman || searchEnglish) { + lang = 'en'; } + final tmdb = TMDB.TMDB(TMDB.ApiKeys( + 'a33271b9e54cdcb9a80680eaf5522f1b', 'apiReadAccessTokenv4')); + + final Map response = await tmdb.v3.movies.getDetails( + movieID, + language: lang, + appendToResponse: 'credits,external_ids', + ); + + logger.i(response); + Movie movie = Movie.fromJsonDynamic(response); + + logger.i('${movie.movieTitle} (${movie.movieID})'); + return true; } }