getPlayList static method
Implementation
static Future<List<Datum>> getPlayList(Datum contentToPlay) async {
List<Datum> convertToDatum(List<ChapterDatum> chapterDatum) {
List<Datum> data = [];
for (ChapterDatum slug in chapterDatum) {
data.add(Datum.fromMap(slug.toMap()));
}
return data;
}
List<Datum> playlist = [];
if (contentToPlay.seriesid != null) {
NetworkHandler.getModules(seriesid: contentToPlay.seriesid)
.then((modulesModel) async {
if ((modulesModel.totalcount ?? 0) > 0) {
List<ModuleDatum> modules = modulesModel.data!;
//Fetch Episodes for all modules
for (ModuleDatum element in modules) {
ChaptersModel chaptersModel = await NetworkHandler.getChapters(
seriesid: contentToPlay.seriesid,
seasonnum: element.seasonnum.toString(),
page: 1,
pagesize: 100);
playlist.addAll(convertToDatum(chaptersModel.data!));
if (element.episodecount! > 100) {
ChaptersModel chaptersModel = await NetworkHandler.getChapters(
seriesid: contentToPlay.seriesid,
seasonnum: element.seasonnum.toString(),
page: 2,
pagesize: 100);
playlist.addAll(convertToDatum(chaptersModel.data!));
}
}
}
});
} else {
try {
ContentModel model = await NetworkHandler.getRelatedContent(
contentid: contentToPlay.objectid);
if ((model.totalcount ?? 0) > 0) {
playlist.addAll(model.data!);
}
} catch (error) {
//do nothing here
}
}
return playlist;
}