more fields

This commit is contained in:
2024-12-05 20:40:21 +01:00
parent 67aca796d9
commit d512452bc9
2 changed files with 162 additions and 11 deletions
+89
View File
@@ -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<String, dynamic> 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<dynamic, dynamic> 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: '',
);
}
}
+73 -11
View File
@@ -232,6 +232,14 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
return data[field];
}
bool parseBool(dynamic data, String field) {
if (data[field] == Null) {
return false;
}
return data[field];
}
Future<void> startSearch() async {
if (movieTitleSearch.isEmpty) {
return;
@@ -299,8 +307,26 @@ class _AddMovieScreenState extends State<AddMovieScreen> {
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<AddMovieScreen> {
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<AddMovieScreen> {
}
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<bool> 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;
}
}