refa video params

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-08-04 16:40:20 +08:00
parent 26ccb92b44
commit cf84a92808
33 changed files with 341 additions and 374 deletions

View File

@@ -45,7 +45,6 @@ import 'package:PiliPlus/plugin/pl_player/models/heart_beat_type.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_status.dart';
import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/duration_util.dart';
import 'package:PiliPlus/utils/id_utils.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
@@ -68,25 +67,27 @@ import 'package:media_kit/media_kit.dart';
class VideoDetailController extends GetxController
with GetTickerProviderStateMixin {
/// 路由传参
String bvid = Get.parameters['bvid']!;
late int aid = IdUtils.bv2av(bvid);
final RxInt cid = int.parse(Get.parameters['cid']!).obs;
final heroTag = Get.arguments['heroTag'];
final RxString cover = ''.obs;
late final Map args;
late String bvid;
late int aid;
late final RxInt cid;
int? epId;
int? seasonId;
int? pgcType;
late final String heroTag;
late final RxString cover;
// 视频类型 默认投稿视频
final pgcApi = Get.arguments['pgcApi'];
final VideoType videoType = Get.arguments['videoType'] ?? VideoType.ugc;
late final VideoType videoType;
late final isUgc = videoType == VideoType.ugc;
VideoType get _actualVideoType {
if (videoType == VideoType.pgc) {
if (!Accounts.get(AccountType.video).isLogin) {
return VideoType.ugc;
}
} else if (pgcApi == true) {
return VideoType.pgc;
}
return videoType;
}
VideoType? _actualVideoType;
// 页面来源 稍后再看 收藏夹
late bool isPlayAll;
late SourceType sourceType;
late bool _mediaDesc = false;
late final RxList<MediaListItemModel> mediaList = <MediaListItemModel>[].obs;
late String watchLaterTitle;
/// tabs相关配置
late TabController tabCtr;
@@ -247,52 +248,42 @@ class VideoDetailController extends GetxController
imageStatus = false;
}
// 页面来源 稍后再看 收藏夹
SourceType sourceType = Get.arguments['sourceType'] ?? SourceType.normal;
late bool _mediaDesc = false;
late final RxList<MediaListItemModel> mediaList = <MediaListItemModel>[].obs;
late String watchLaterTitle = '';
bool get isPlayAll => sourceType != SourceType.normal;
late dynamic epId = Get.parameters['epId'];
late dynamic seasonId = Get.parameters['seasonId'];
late dynamic subType = Get.parameters['type'];
@override
void onInit() {
super.onInit();
var keys = Get.arguments.keys.toList();
if (keys.isNotEmpty) {
if (keys.contains('pic')) {
cover.value = Get.arguments['pic'] ?? '';
} else if (keys.contains('videoItem')) {
var args = Get.arguments['videoItem'];
try {
if (args.cover != null && args.cover != '') {
cover.value = args.cover;
}
} catch (_) {
try {
if (args.pic != null && args.pic != '') {
cover.value = args.pic;
}
} catch (_) {}
}
args = Get.arguments;
videoType = args['videoType'];
if (videoType == VideoType.pgc) {
if (!Accounts.get(AccountType.video).isLogin) {
_actualVideoType = VideoType.ugc;
}
} else if (args['pgcApi'] == true) {
_actualVideoType = VideoType.pgc;
}
bvid = args['bvid'];
aid = args['aid'];
cid = RxInt(args['cid']);
epId = args['epId'];
seasonId = args['seasonId'];
pgcType = args['pgcType'];
heroTag = args['heroTag'];
cover = RxString(args['cover'] ?? '');
sourceType = args['sourceType'] ?? SourceType.normal;
isPlayAll = sourceType != SourceType.normal;
if (isPlayAll) {
watchLaterTitle = Get.arguments['favTitle'];
_mediaDesc = Get.arguments['desc'];
watchLaterTitle = args['favTitle'];
_mediaDesc = args['desc'];
getMediaList();
}
bool defaultShowComment = Pref.defaultShowComment;
tabCtr = TabController(
length: 2,
vsync: this,
initialIndex: defaultShowComment ? 1 : 0,
initialIndex: Pref.defaultShowComment ? 1 : 0,
);
autoPlay.value = Pref.autoPlayEnable;
if (autoPlay.value) isShowCover.value = false;
@@ -305,21 +296,20 @@ class VideoDetailController extends GetxController
bool isReverse = false,
bool isLoadPrevious = false,
}) async {
if (!isReverse &&
Get.arguments['count'] != null &&
mediaList.length >= Get.arguments['count']) {
final count = args['count'];
if (!isReverse && count != null && mediaList.length >= count) {
return;
}
var res = await UserHttp.getMediaList(
type: Get.arguments['mediaType'] ?? sourceType.mediaType,
bizId: Get.arguments['mediaId'] ?? -1,
type: args['mediaType'] ?? sourceType.mediaType,
bizId: args['mediaId'] ?? -1,
ps: 20,
direction: isLoadPrevious ? true : false,
oid: isReverse
? null
: mediaList.isEmpty
? Get.arguments['isContinuePlaying'] == true
? Get.arguments['oid']
? args['isContinuePlaying'] == true
? args['oid']
: null
: isLoadPrevious
? mediaList.first.aid
@@ -332,9 +322,8 @@ class VideoDetailController extends GetxController
? mediaList.first.type
: mediaList.last.type,
desc: _mediaDesc,
sortField: Get.arguments['sortField'] ?? 1,
withCurrent:
mediaList.isEmpty && Get.arguments['isContinuePlaying'] == true
sortField: args['sortField'] ?? 1,
withCurrent: mediaList.isEmpty && args['isContinuePlaying'] == true
? true
: false,
);
@@ -376,20 +365,19 @@ class VideoDetailController extends GetxController
},
panelTitle: watchLaterTitle,
getBvId: () => bvid,
count: Get.arguments['count'],
count: args['count'],
loadMoreMedia: getMediaList,
desc: _mediaDesc,
onReverse: () {
_mediaDesc = !_mediaDesc;
getMediaList(isReverse: true);
},
loadPrevious: Get.arguments['isContinuePlaying'] == true
loadPrevious: args['isContinuePlaying'] == true
? () => getMediaList(isLoadPrevious: true)
: null,
onDelete:
sourceType == SourceType.watchLater ||
(sourceType == SourceType.fav &&
Get.arguments?['isOwner'] == true)
(sourceType == SourceType.fav && args['isOwner'] == true)
? (item, index) async {
if (sourceType == SourceType.watchLater) {
var res = await UserHttp.toViewDel(
@@ -402,7 +390,7 @@ class VideoDetailController extends GetxController
} else {
var res = await FavHttp.favVideo(
resources: '${item.aid}:${item.type}',
delIds: '${Get.arguments?['mediaId']}',
delIds: '${args['mediaId']}',
);
if (res['status']) {
mediaList.removeAt(index);
@@ -1136,7 +1124,7 @@ class VideoDetailController extends GetxController
autoplay: autoplay ?? autoPlay.value,
epid: isUgc ? null : epId,
seasonId: isUgc ? null : seasonId,
subType: isUgc ? null : subType,
pgcType: isUgc ? null : pgcType,
videoType: videoType,
callback: () {
if (videoState.value is! Success) {
@@ -1189,7 +1177,7 @@ class VideoDetailController extends GetxController
epid: epId,
seasonId: seasonId,
tryLook: plPlayerController.tryLook,
videoType: _actualVideoType,
videoType: _actualVideoType ?? videoType,
);
if (result['status']) {
@@ -1204,9 +1192,10 @@ class VideoDetailController extends GetxController
if (data.dash == null && data.durl != null) {
videoUrl = data.durl!.first.url!;
audioUrl = '';
if (Get.arguments?['progress'] != null) {
this.defaultST = Duration(milliseconds: Get.arguments['progress']);
Get.arguments['progress'] = null;
final progress = args['progress'];
if (progress != null) {
this.defaultST = Duration(milliseconds: progress);
args['progress'] = null;
} else {
this.defaultST = defaultST ?? Duration.zero;
}
@@ -1340,9 +1329,10 @@ class VideoDetailController extends GetxController
audioUrl = '';
}
//
if (Get.arguments?['progress'] != null) {
this.defaultST = Duration(milliseconds: Get.arguments['progress']);
Get.arguments['progress'] = null;
final progress = args['progress'];
if (progress != null) {
this.defaultST = Duration(milliseconds: progress);
args['progress'] = null;
} else {
this.defaultST =
defaultST ??
@@ -1577,11 +1567,12 @@ class VideoDetailController extends GetxController
}
void updateMediaListHistory(int aid) {
if (Get.arguments?['sortField'] != null) {
final sortField = args['sortField'];
if (sortField != null) {
VideoHttp.medialistHistory(
desc: _mediaDesc ? 1 : 0,
oid: aid,
upperMid: Get.arguments?['mediaId'],
upperMid: sortField,
);
}
}
@@ -1605,7 +1596,7 @@ class VideoDetailController extends GetxController
cid: cid.value,
epid: isUgc ? null : epId,
seasonId: isUgc ? null : seasonId,
subType: isUgc ? null : subType,
pgcType: isUgc ? null : pgcType,
videoType: videoType,
);
} catch (_) {}

View File

@@ -32,29 +32,38 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
class PgcIntroController extends CommonIntroController {
var seasonId = Get.parameters['seasonId'] != null
? int.tryParse(Get.parameters['seasonId']!)
: null;
var epId = Get.parameters['epId'] != null
? int.tryParse(Get.parameters['epId']!)
: null;
int? seasonId;
int? epId;
late final String pgcType =
Get.parameters['type'] == '1' || Get.parameters['type'] == '4'
late final String pgcType = pgcItem.type == 1 || pgcItem.type == 4
? '追番'
: '追剧';
final isPgc = Get.arguments['videoType'] == VideoType.pgc;
final PgcInfoModel pgcItem = Get.arguments['pgcItem'];
late final bool isPgc;
late final PgcInfoModel pgcItem;
@override
(Object, int) getFavRidType() => (epId!, 24);
@override
StatDetail? getStat() => pgcItem.stat;
late final RxBool isFollowed = false.obs;
late final RxInt followStatus = (-1).obs;
@override
void onInit() {
final args = Get.arguments;
seasonId = args['seasonId'];
epId = args['epId'];
isPgc = args['videoType'] == VideoType.pgc;
pgcItem = args['pgcItem'];
super.onInit();
if (isPgc) {
if (accountService.isLogin.value) {
if (seasonId != null) {
queryIsFollowed();
}
queryIsFollowed();
if (epId != null) {
queryPgcLikeCoinFav();
}
@@ -125,12 +134,6 @@ class PgcIntroController extends CommonIntroController {
);
}
@override
(Object, int) getFavRidType() => (epId!, 24);
@override
StatDetail? getStat() => pgcItem.stat;
// 分享视频
void actionShareVideo(BuildContext context) {
showDialog(
@@ -202,12 +205,12 @@ class PgcIntroController extends CommonIntroController {
6漫画
7综艺 // 4099
*/
dynType: switch (Get.parameters['type']) {
'1' => 4097,
'2' => 4098,
'3' => 4101,
'4' => 4100,
'5' || '7' => 4099,
dynType: switch (pgcItem.type) {
1 => 4097,
2 => 4098,
3 => 4101,
4 => 4100,
5 || 7 => 4099,
_ => -1,
},
pic: pgcItem.cover,
@@ -283,16 +286,15 @@ class PgcIntroController extends CommonIntroController {
this.epId = epId;
this.bvid = bvid;
final videoDetailCtr =
Get.find<VideoDetailController>(tag: Get.arguments['heroTag'])
..plPlayerController.pause()
..makeHeartBeat()
..onReset()
..epId = epId
..bvid = bvid
..aid = aid
..cid.value = cid
..queryVideoUrl();
final videoDetailCtr = Get.find<VideoDetailController>(tag: heroTag)
..plPlayerController.pause()
..makeHeartBeat()
..onReset()
..epId = epId
..bvid = bvid
..aid = aid
..cid.value = cid
..queryVideoUrl();
if (cover != null && cover.isNotEmpty) {
videoDetailCtr.cover.value = cover;
}
@@ -300,7 +302,7 @@ class PgcIntroController extends CommonIntroController {
// 重新请求评论
if (videoDetailCtr.showReply) {
try {
Get.find<VideoReplyController>(tag: Get.arguments['heroTag'])
Get.find<VideoReplyController>(tag: heroTag)
..aid = aid
..onReload();
} catch (_) {}
@@ -353,7 +355,7 @@ class PgcIntroController extends CommonIntroController {
bool prevPlay() {
final episodes = pgcItem.episodes!;
VideoDetailController videoDetailCtr = Get.find<VideoDetailController>(
tag: Get.arguments['heroTag'],
tag: heroTag,
);
int currentIndex = episodes.indexWhere(
(e) => e.cid == videoDetailCtr.cid.value,
@@ -377,7 +379,7 @@ class PgcIntroController extends CommonIntroController {
try {
final episodes = pgcItem.episodes!;
VideoDetailController videoDetailCtr = Get.find<VideoDetailController>(
tag: Get.arguments['heroTag'],
tag: heroTag,
);
PlayRepeat playRepeat = videoDetailCtr.plPlayerController.playRepeat;
@@ -437,9 +439,6 @@ class PgcIntroController extends CommonIntroController {
}
}
RxBool isFollowed = false.obs;
RxInt followStatus = (-1).obs;
void queryIsFollowed() {
// try {
// var result = await Request().get(
@@ -469,14 +468,14 @@ class PgcIntroController extends CommonIntroController {
@override
void queryVideoIntro([EpisodeItem? episode]) {
episode ??= pgcItem.episodes!.firstWhere((e) => e.cid == cid.value);
videoDetail
..value.title = episode.showTitle
..refresh();
videoPlayerServiceHandler.onVideoDetailChange(
episode,
cid.value,
heroTag,
artist: pgcItem.title,
);
videoDetail
..value.title = episode.showTitle
..refresh();
}
}

View File

@@ -79,19 +79,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
});
}
try {
var videoItem = Get.arguments['videoItem'];
if (videoItem != null) {
if (videoItem.title case String e) {
videoDetail.value.title = e;
} else if (videoItem.title case List list) {
videoDetail.value.title = list.fold<String>(
'',
(prev, val) => prev + val['text'],
);
}
}
} catch (_) {}
videoDetail.value.title = Get.arguments['title'] ?? '';
}
// 获取视频简介&分p
@@ -481,11 +469,9 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
if (videoDetailCtr.mediaList.indexWhere((item) => item.bvid == bvid) ==
-1) {
PageUtils.toVideoPage(
'bvid=$bvid&cid=$cid',
arguments: {
'pic': ?cover,
'heroTag': Utils.makeHeroTag(bvid),
},
bvid: bvid,
cid: cid,
cover: cover,
);
return;
}
@@ -690,10 +676,8 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
if (Get.isRegistered<RelatedController>(tag: heroTag)) {
relatedCtr = Get.find<RelatedController>(tag: heroTag);
} else {
relatedCtr = Get.put(RelatedController(false), tag: heroTag)
..queryData().whenComplete(() {
playRelated();
});
relatedCtr = Get.put(RelatedController(autoQuery: false), tag: heroTag)
..queryData().whenComplete(playRelated);
return false;
}

View File

@@ -66,8 +66,7 @@ class _UgcIntroPanelState extends State<UgcIntroPanel>
@override
void initState() {
super.initState();
ugcIntroController = Get.put(UgcIntroController(), tag: widget.heroTag)
..heroTag = widget.heroTag;
ugcIntroController = Get.put(UgcIntroController(), tag: widget.heroTag);
}
@override

View File

@@ -6,15 +6,14 @@ import 'package:get/get.dart';
class RelatedController
extends CommonListController<List<HotVideoItemModel>?, HotVideoItemModel> {
RelatedController([this.autoQuery]);
// 视频aid
String bvid = Get.parameters['bvid'] ?? "";
final bool? autoQuery;
RelatedController({this.autoQuery = true});
String bvid = Get.arguments['bvid'];
final bool autoQuery;
@override
void onInit() {
super.onInit();
if (autoQuery != false) {
if (autoQuery) {
queryData();
}
}

View File

@@ -62,17 +62,9 @@ class VideoReplyController extends ReplyController<MainListReply>
return response.replies;
}
int get _epId {
return switch (videoCtr.epId) {
int e => e,
String e => int.parse(e),
_ => throw UnsupportedError(''),
};
}
@override
Future<LoadingState<MainListReply>> customGetData() => ReplyGrpc.mainList(
oid: isPugv ? _epId : aid,
oid: isPugv ? videoCtr.epId! : aid,
type: videoType.replyType,
mode: mode.value,
cursorNext: cursorNext,

View File

@@ -74,6 +74,8 @@ class VideoDetailPageV extends StatefulWidget {
class _VideoDetailPageVState extends State<VideoDetailPageV>
with TickerProviderStateMixin, RouteAware, WidgetsBindingObserver {
final heroTag = Get.arguments['heroTag'];
late final VideoDetailController videoDetailController;
late final VideoReplyController _videoReplyController;
PlPlayerController? plPlayerController;
@@ -86,8 +88,6 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
ScrollController get introScrollController =>
_introScrollController ??= ScrollController();
late String heroTag;
bool get autoExitFullscreen =>
videoDetailController.plPlayerController.autoExitFullscreen;
bool get autoPlayEnable =>
@@ -130,9 +130,6 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
super.initState();
PlPlayerController.setPlayCallBack(playCallBack);
if (Get.arguments != null && Get.arguments['heroTag'] != null) {
heroTag = Get.arguments['heroTag'];
}
videoDetailController = Get.put(VideoDetailController(), tag: heroTag);
if (videoDetailController.showReply) {