mod: view pgc section as normal video

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-01-10 15:32:43 +08:00
parent ae88700b96
commit a1bfe1f4ee
2 changed files with 83 additions and 35 deletions

View File

@@ -80,6 +80,7 @@ class BangumiInfoModel {
int? type;
UserStatus? userStatus;
String? staff;
List<Section>? section;
BangumiInfoModel.fromJson(Map<String, dynamic> json) {
activity = json['activity'];
@@ -89,8 +90,8 @@ class BangumiInfoModel {
bkgCover = json['bkg_cover'];
cover = json['cover'];
enableVt = json['enableVt'];
episodes = json['episodes']
.map<EpisodeItem>((e) => EpisodeItem.fromJson(e))
episodes = (json['episodes'] as List?)
?.map<EpisodeItem>((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<EpisodeItem>? episodes;
Section.fromJson(Map<String, dynamic> json) {
episodes = (json['episodes'] as List?)
?.map<EpisodeItem>((e) => EpisodeItem.fromJson(e))
.toList();
}
}

View File

@@ -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');
}
}