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.

64 lines
1.7 KiB
Dart

import '../../../core/status.dart';
class EpisodeItem {
final int id;
final int episodeNumber;
final int seasonNumber;
final String showName;
final String? name;
final ItemStatus status;
final String? resolution;
final int? firstAirYear;
final String? showJson;
final String? showStatus;
final bool? showCliffhanger;
final String? posterPath;
final int? showId;
final String? downloadPath;
EpisodeItem({
required this.id,
required this.episodeNumber,
required this.seasonNumber,
required this.showName,
this.name,
required this.status,
this.resolution,
this.firstAirYear,
this.showJson,
this.showStatus,
this.showCliffhanger,
this.posterPath,
this.showId,
this.downloadPath,
});
factory EpisodeItem.fromJson(Map<String, dynamic> j) => EpisodeItem(
id: j['id'] as int,
episodeNumber: j['episode_number'] as int,
seasonNumber: j['season_number'] as int,
showName: j['show_name'] as String,
name: j['name'] as String?,
status: statusFromString(j['status'] as String?),
resolution: j['resolution'] as String?,
firstAirYear: j['first_air_year'] as int?,
showJson: j['show_json'] as String?,
showStatus: j['show_status'] as String?,
showCliffhanger: _parseBool(j['show_cliffhanger']),
posterPath: j['poster_path'] as String?,
showId: (j['show_id'] as num?)?.toInt(),
downloadPath: j['download_path'] as String?,
);
static bool? _parseBool(dynamic v) {
if (v == null) return null;
if (v is bool) return v;
if (v is num) return v != 0;
if (v is String) {
final s = v.toLowerCase();
return s == '1' || s == 'true' || s == 'yes';
}
return null;
}
}