98 lines
2.6 KiB
Dart
98 lines
2.6 KiB
Dart
import '../../../core/status.dart';
|
|
import 'episode_model.dart';
|
|
import 'series_exporter_stub.dart'
|
|
if (dart.library.html) 'series_exporter_web.dart'
|
|
if (dart.library.io) 'series_exporter_io.dart';
|
|
|
|
SeriesExporter createSeriesExporter() => getSeriesExporter();
|
|
|
|
class SeriesExportRow {
|
|
final String title;
|
|
final int? year;
|
|
final String? seriesStatus;
|
|
final bool? cliffhanger;
|
|
final String? resolution;
|
|
final String? downloadPath;
|
|
final int seasons;
|
|
final int episodesInit;
|
|
final int episodesProgress;
|
|
final int episodesDone;
|
|
final Map<int, Map<int, ItemStatus>>? episodesBySeason; // optional per-episode status
|
|
|
|
int get episodesTotal => episodesInit + episodesProgress + episodesDone;
|
|
|
|
SeriesExportRow({
|
|
required this.title,
|
|
required this.year,
|
|
required this.seriesStatus,
|
|
required this.cliffhanger,
|
|
required this.resolution,
|
|
required this.downloadPath,
|
|
required this.seasons,
|
|
required this.episodesInit,
|
|
required this.episodesProgress,
|
|
required this.episodesDone,
|
|
this.episodesBySeason,
|
|
});
|
|
|
|
factory SeriesExportRow.fromGroup(Map<int, List<EpisodeItem>> bySeason,
|
|
{bool includeEpisodeStatus = false}) {
|
|
String title = '';
|
|
int? year;
|
|
String? status;
|
|
bool? cliff;
|
|
String? resolution;
|
|
String? download;
|
|
int init = 0, prog = 0, done = 0;
|
|
final perSeason = <int, Map<int, ItemStatus>>{};
|
|
for (final eps in bySeason.values) {
|
|
for (final e in eps) {
|
|
title = e.showName;
|
|
year ??= e.firstAirYear;
|
|
status ??= e.showStatus;
|
|
cliff ??= e.showCliffhanger;
|
|
resolution ??= e.resolution;
|
|
download ??= e.downloadPath;
|
|
if (includeEpisodeStatus) {
|
|
perSeason.putIfAbsent(e.seasonNumber, () => {})[e.episodeNumber] = e.status;
|
|
}
|
|
switch (e.status) {
|
|
case ItemStatus.Init:
|
|
init++;
|
|
break;
|
|
case ItemStatus.Progress:
|
|
prog++;
|
|
break;
|
|
case ItemStatus.Done:
|
|
done++;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return SeriesExportRow(
|
|
title: title,
|
|
year: year,
|
|
seriesStatus: status,
|
|
cliffhanger: cliff,
|
|
resolution: resolution,
|
|
downloadPath: download,
|
|
seasons: bySeason.length,
|
|
episodesInit: init,
|
|
episodesProgress: prog,
|
|
episodesDone: done,
|
|
episodesBySeason: includeEpisodeStatus ? perSeason : null,
|
|
);
|
|
}
|
|
}
|
|
|
|
abstract class SeriesExporter {
|
|
Future<String?> chooseSavePath({required bool asXlsx, ItemStatus? filter});
|
|
|
|
Future<String?> exportSeries(
|
|
List<SeriesExportRow> rows, {
|
|
required bool asXlsx,
|
|
ItemStatus? filter,
|
|
String? path,
|
|
});
|
|
}
|