diff --git a/lib/models/bangumi/info.dart b/lib/models/bangumi/info.dart index 3423d1ee..536a1da9 100644 --- a/lib/models/bangumi/info.dart +++ b/lib/models/bangumi/info.dart @@ -80,6 +80,7 @@ class BangumiInfoModel { int? type; UserStatus? userStatus; String? staff; + List
? section; BangumiInfoModel.fromJson(Map json) { activity = json['activity']; @@ -89,8 +90,8 @@ class BangumiInfoModel { bkgCover = json['bkg_cover']; cover = json['cover']; enableVt = json['enableVt']; - episodes = json['episodes'] - .map((e) => EpisodeItem.fromJson(e)) + episodes = (json['episodes'] as List?) + ?.map((e) => EpisodeItem.fromJson(e)) .toList(); evaluate = json['evaluate']; freya = json['freya']; @@ -125,6 +126,22 @@ class BangumiInfoModel { userStatus = UserStatus.fromJson(json['user_status']); } staff = json['staff']; + section = (json['section'] as List?) + ?.map((item) => Section.fromJson(item)) + .toList(); + } +} + +class Section { + Section({ + this.episodes, + }); + List? episodes; + + Section.fromJson(Map json) { + episodes = (json['episodes'] as List?) + ?.map((e) => EpisodeItem.fromJson(e)) + .toList(); } } diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 3e3ed761..3c86ba41 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -426,42 +426,73 @@ class Utils { dynamic seasonId, dynamic epId, }) async { - SmartDialog.showLoading(msg: '资源获取中'); - var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId); - SmartDialog.dismiss(); - if (result['status']) { - if (result['data'].episodes.isEmpty) { - SmartDialog.showToast('资源加载失败'); - return; - } - // epId episode -> progress episode -> first episode - EpisodeItem? episode; - if (epId != null) { - episode = (result['data'].episodes as List).firstWhereOrNull( - (item) { - return item.epId.toString() == epId.toString(); + try { + SmartDialog.showLoading(msg: '资源获取中'); + var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId); + SmartDialog.dismiss(); + if (result['status']) { + BangumiInfoModel data = result['data']; + + // epId episode -> progress episode -> first episode + EpisodeItem? episode; + + if (epId != null) { + if (data.episodes?.isNotEmpty == true) { + episode = data.episodes!.firstWhereOrNull( + (item) { + return item.epId.toString() == epId.toString(); + }, + ); + } + if (episode == null && data.section?.isNotEmpty == true) { + for (Section item in data.section!) { + if (item.episodes?.isNotEmpty == true) { + for (EpisodeItem item in item.episodes!) { + if (item.epId.toString() == epId.toString()) { + // view as normal video + Utils.toDupNamed( + '/video?bvid=${item.bvid}&cid=${item.cid}', + arguments: { + 'pic': item.cover, + 'heroTag': Utils.makeHeroTag(item.cid), + 'videoType': SearchType.video, + }, + ); + return; + } + } + } + } + } + } + + if (data.episodes?.isEmpty == true) { + SmartDialog.showToast('资源加载失败'); + return; + } + + episode ??= data.userStatus?.progress?.lastEpId != null + ? data.episodes!.firstWhereOrNull( + (item) => item.epId == data.userStatus?.progress?.lastEpId, + ) ?? + data.episodes!.first + : data.episodes!.first; + Utils.toDupNamed( + '/video?bvid=${episode.bvid}&cid=${episode.cid}&seasonId=${data.seasonId}&epId=${episode.epId}&type=${data.type}', + arguments: { + 'pic': episode.cover, + 'heroTag': Utils.makeHeroTag(episode.cid), + 'videoType': SearchType.media_bangumi, + 'bangumiItem': data, }, ); + } else { + SmartDialog.showToast(result['msg']); } - episode ??= (result['data'].episodes as List).firstWhereOrNull( - (item) => - item.epId == result['data'].userStatus?.progress?.lastEpId, - ) ?? - result['data'].episodes.first; - dynamic bvid = episode?.bvid; - dynamic cid = episode?.cid; - dynamic pic = episode?.cover; - Utils.toDupNamed( - '/video?bvid=$bvid&cid=$cid&seasonId=${result['data'].seasonId}&epId=${episode?.epId}&type=${result['data'].type}', - arguments: { - 'pic': pic, - 'heroTag': Utils.makeHeroTag(cid), - 'videoType': SearchType.media_bangumi, - 'bangumiItem': result['data'], - }, - ); - } else { - SmartDialog.showToast(result['msg']); + } catch (e) { + SmartDialog.dismiss(); + SmartDialog.showToast('$e'); + debugPrint('$e'); } }