You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
321 lines
9.2 KiB
Dart
321 lines
9.2 KiB
Dart
import 'package:logger/logger.dart';
|
|
import 'package:multimedia/log_printer.dart';
|
|
|
|
int getInt(Map<dynamic, dynamic> json, String key) {
|
|
if (json.containsKey(key)) {
|
|
return json[key] + 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
bool getBool(Map<dynamic, dynamic> json, String key) {
|
|
if (json.containsKey(key)) {
|
|
return json[key];
|
|
}
|
|
return false;
|
|
}
|
|
|
|
double getDouble(Map<dynamic, dynamic> json, String key) {
|
|
if (json.containsKey(key)) {
|
|
return json[key] + 0.0;
|
|
}
|
|
return 0.0;
|
|
}
|
|
|
|
String getString(Map<dynamic, dynamic> json, String key) {
|
|
if (json.containsKey(key)) {
|
|
if (json[key] == null) {
|
|
return '';
|
|
}
|
|
return json[key];
|
|
}
|
|
return '';
|
|
}
|
|
|
|
DateTime getDateTime(Map<dynamic, dynamic> json, String key) {
|
|
if (json.containsKey(key)) {
|
|
return DateTime.parse(json[key].toString());
|
|
}
|
|
return DateTime(1900);
|
|
}
|
|
|
|
class Movie {
|
|
int movieID;
|
|
String movieTitle;
|
|
String originalTitle;
|
|
String overview;
|
|
DateTime releaseDate;
|
|
int state;
|
|
String resolution;
|
|
String backdropPath;
|
|
String posterPath;
|
|
String languages;
|
|
String productionCountries;
|
|
String productionCompanies;
|
|
double voteAverage;
|
|
int voteCount;
|
|
String cast;
|
|
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,
|
|
required this.movieTitle,
|
|
required this.originalTitle,
|
|
required this.overview,
|
|
required this.releaseDate,
|
|
required this.state,
|
|
required this.resolution,
|
|
required this.backdropPath,
|
|
required this.posterPath, //NEW STRING
|
|
required this.languages,
|
|
required this.productionCountries,
|
|
required this.productionCompanies,
|
|
required this.voteAverage,
|
|
required this.voteCount,
|
|
required this.cast,
|
|
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) {
|
|
if (json.containsKey('backdropPath')) {
|
|
return Movie(
|
|
movieID: int.parse(json['movieID']),
|
|
movieTitle: json['movieTitle'] as String,
|
|
originalTitle: json['originalTitle'] as String,
|
|
overview: json['overview'] as String,
|
|
releaseDate: DateTime.parse(json['releaseDate']),
|
|
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'],
|
|
voteAverage: double.parse(json['voteAverage']),
|
|
voteCount: int.parse(json['voteCount']),
|
|
cast: json['cast'],
|
|
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(
|
|
movieID: int.parse(json['movieID']),
|
|
movieTitle: json['movieTitle'] as String,
|
|
originalTitle: '',
|
|
overview: json['overview'] as String,
|
|
releaseDate: DateTime.parse(json['releaseDate']),
|
|
state: int.parse(json['state']),
|
|
resolution: json['resolution'] as String,
|
|
backdropPath: '',
|
|
posterPath: '',
|
|
languages: '',
|
|
productionCountries: '',
|
|
productionCompanies: '',
|
|
voteAverage: 0,
|
|
voteCount: 0,
|
|
cast: '',
|
|
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) {
|
|
int movieID = getInt(json, 'id');
|
|
String movieTitle = getString(json, 'title');
|
|
String originalTitle = getString(json, 'original_title');
|
|
String overview = getString(json, 'overview');
|
|
DateTime releaseDate = getDateTime(json, 'release_date');
|
|
int state = 1;
|
|
String resolution = '';
|
|
String backdropPath = getString(json, 'backdrop_path');
|
|
String posterPath = getString(json, 'poster_path');
|
|
double voteAverage = getDouble(json, 'vote_average');
|
|
int voteCount = getInt(json, 'vote_count');
|
|
String localPath = '';
|
|
dynamic externalIDs = json['external_ids'];
|
|
String imdbID = getString(externalIDs, 'imdb_id');
|
|
double popularity = getDouble(json, 'popularity');
|
|
String originalLanguage = getString(json, 'original_language');
|
|
int adult = getBool(json, 'adult') == true ? 1 : 0;
|
|
double budget = getDouble(json, 'budget');
|
|
String homepage = getString(json, 'homepage');
|
|
double revenue = getDouble(json, 'revenue');
|
|
int runtime = getInt(json, 'runtime');
|
|
String tagline = getString(json, 'tagline');
|
|
|
|
dynamic languages = json['spoken_languages'];
|
|
dynamic productionCountries = json['production_countries'];
|
|
dynamic productionCompanies = json['production_companies'];
|
|
dynamic credits = json['credits'];
|
|
dynamic genres = json['genres'];
|
|
dynamic casts = credits['cast'];
|
|
dynamic crews = credits['crew'];
|
|
String belongsToCollection = '';
|
|
|
|
String languageList = '';
|
|
String castList = '';
|
|
String crewList = '';
|
|
String genreList = '';
|
|
String productionCompaniesList = '';
|
|
String productionCountriesList = '';
|
|
bool first;
|
|
|
|
if (json.containsKey('belongsToCollection')) {
|
|
belongsToCollection = json['belongsToCollection'];
|
|
}
|
|
|
|
first = true;
|
|
for (var i = 0; i < languages.length; i++) {
|
|
dynamic language = languages[i];
|
|
String languageName = language['name'];
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
languageList = languageList + ',';
|
|
}
|
|
languageList = languageName;
|
|
}
|
|
|
|
first = true;
|
|
for (var i = 0; i < casts.length; i++) {
|
|
dynamic cast = casts[i];
|
|
String castName = cast['name'];
|
|
String castChar = cast['character'];
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
castList = castList + '|';
|
|
}
|
|
castList = castList + castName + ',' + castChar;
|
|
}
|
|
|
|
first = true;
|
|
for (var i = 0; i < crews.length; i++) {
|
|
dynamic crew = crews[i];
|
|
String crewName = crew['name'];
|
|
String crewDepartment = crew['department'];
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
crewList = crewList + '|';
|
|
}
|
|
crewList = crewList + crewName + ',' + crewDepartment;
|
|
}
|
|
|
|
first = true;
|
|
for (var i = 0; i < productionCountries.length; i++) {
|
|
dynamic productionCountry = productionCountries[i];
|
|
String name = productionCountry['name'];
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
productionCountriesList = productionCountriesList + ',';
|
|
}
|
|
productionCountriesList = productionCountriesList + name;
|
|
}
|
|
|
|
first = true;
|
|
for (var i = 0; i < productionCompanies.length; i++) {
|
|
dynamic productionCompany = productionCompanies[i];
|
|
String name = productionCompany['name'];
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
productionCountriesList = productionCompaniesList + ',';
|
|
}
|
|
productionCompaniesList = productionCompaniesList + name;
|
|
}
|
|
|
|
first = true;
|
|
for (var i = 0; i < genres.length; i++) {
|
|
dynamic genre = genres[i];
|
|
String genreName = genre['name'];
|
|
if (first) {
|
|
first = false;
|
|
} else {
|
|
genreList = genreList + ',';
|
|
}
|
|
genreList = genreList + genreName;
|
|
}
|
|
|
|
return Movie(
|
|
movieID: movieID,
|
|
movieTitle: movieTitle,
|
|
originalTitle: originalTitle,
|
|
overview: overview,
|
|
releaseDate: releaseDate,
|
|
state: state,
|
|
resolution: resolution,
|
|
backdropPath: backdropPath,
|
|
posterPath: posterPath,
|
|
languages: languageList,
|
|
productionCountries: productionCountriesList,
|
|
productionCompanies: productionCompaniesList,
|
|
voteAverage: voteAverage,
|
|
voteCount: voteCount,
|
|
cast: castList,
|
|
crew: crewList,
|
|
genre: genreList,
|
|
localPath: localPath,
|
|
imdbID: imdbID,
|
|
originalLanguage: originalLanguage,
|
|
popularity: popularity,
|
|
adult: adult == 1,
|
|
belongsToCollection: belongsToCollection,
|
|
budget: budget,
|
|
homepage: homepage,
|
|
revenue: revenue,
|
|
runtime: runtime,
|
|
tagline: tagline,
|
|
);
|
|
}
|
|
}
|