feat: video download

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-11-06 12:12:32 +08:00
parent 976622df89
commit ffd4f9ee73
92 changed files with 4853 additions and 946 deletions

View File

@@ -0,0 +1,139 @@
import 'package:PiliPlus/models_new/download/bili_download_entry_info.dart';
import 'package:PiliPlus/models_new/video/video_detail/stat_detail.dart';
import 'package:PiliPlus/pages/common/common_intro_controller.dart';
import 'package:PiliPlus/pages/download/controller.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:flutter/scheduler.dart' show SchedulerBinding;
import 'package:get/get.dart';
class LocalIntroController extends CommonIntroController {
@override
void queryVideoIntro() {}
@override
void actionCoinVideo() {}
@override
void actionLikeVideo() {}
@override
void actionShareVideo(context) {}
@override
void actionTriple() {}
@override
Future<void> actionFavVideo({bool isQuick = false}) async {}
@override
(Object, int) get getFavRidType => throw UnimplementedError();
@override
StatDetail? getStat() => null;
@override
bool get isShowOnlineTotal => false;
late final Set<String> aidSet = {};
@override
void onClose() {
aidSet.clear();
super.onClose();
}
@override
void onInit() {
super.onInit();
videoDetail.value.title = videoDetailCtr.args['title'];
final controller = Get.find<DownloadPageController>();
final list = <BiliDownloadEntryInfo>[];
for (final e in controller.pages) {
final items = e.entrys..sort((a, b) => a.sortKey.compareTo(b.sortKey));
final completed = items.where((e) => e.isCompleted);
list.addAllIf(completed.isNotEmpty, completed);
if (completed.length == 1) {
aidSet.add(e.pageId);
}
}
this.list.value = list;
final currCid = videoDetailCtr.cid.value;
final index = list.indexWhere((e) => e.cid == currCid);
this.index.value = index;
if (index != 0) {
SchedulerBinding.instance.addPostFrameCallback((_) {
try {
if (videoDetailCtr.scrollKey.currentState?.mounted ?? false) {
(videoDetailCtr.scrollKey.currentState!.innerController
as ExtendedNestedScrollController)
.nestedPositions
.first
.localJumpTo(_offset);
} else if (videoDetailCtr.introScrollCtr?.hasClients ?? false) {
videoDetailCtr.introScrollCtr!.jumpTo(_offset);
}
} catch (_) {
if (kDebugMode) rethrow;
}
});
}
}
final index = (-1).obs;
double get _offset => index * 100 + 7 - 35;
final list = RxList<BiliDownloadEntryInfo>();
@override
bool nextPlay() {
final next = index.value + 1;
if (next < list.length) {
playIndex(next);
return true;
} else {
final playCtr = videoDetailCtr.plPlayerController;
if (playCtr.playRepeat == PlayRepeat.listCycle) {
if (list.length == 1) {
if (playCtr.videoPlayerController case final ctr?) {
ctr.seek(Duration.zero).whenComplete(ctr.play);
}
} else {
playIndex(0);
}
return true;
}
}
return false;
}
@override
bool prevPlay() {
final prev = index.value - 1;
if (prev >= 0) {
playIndex(prev);
return true;
}
return false;
}
void playIndex(
int index, {
BiliDownloadEntryInfo? entry,
}) {
entry ??= list[index];
videoDetailCtr
..onReset()
..cover.value = entry.cover
..aid = entry.avid
..bvid = entry.bvid
..cid.value = entry.cid
..args['dirPath'] = entry.entryDirPath
..initFileSource(entry, isInit: false)
..playerInit();
videoDetail
..value.title = entry.showTitle
..refresh();
this.index.value = index;
}
}

View File

@@ -0,0 +1,172 @@
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/widgets/badge.dart';
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
import 'package:PiliPlus/models/common/badge_type.dart';
import 'package:PiliPlus/models/common/video/video_quality.dart';
import 'package:PiliPlus/models_new/download/bili_download_entry_info.dart';
import 'package:PiliPlus/pages/video/introduction/local/controller.dart';
import 'package:PiliPlus/utils/duration_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class LocalIntroPanel extends StatefulWidget {
const LocalIntroPanel({super.key, required this.heroTag});
final String heroTag;
@override
State<LocalIntroPanel> createState() => _LocalIntroPanelState();
}
class _LocalIntroPanelState extends State<LocalIntroPanel>
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;
late final _controller = Get.find<LocalIntroController>(tag: widget.heroTag);
@override
Widget build(BuildContext context) {
super.build(context);
final theme = Theme.of(context);
return Obx(() {
final currIndex = _controller.index.value;
return SliverFixedExtentList.builder(
itemCount: _controller.list.length,
itemBuilder: (context, index) {
final item = _controller.list[index];
return _buildItem(theme, currIndex == index, index, item);
},
itemExtent: 100,
);
});
}
Widget _buildItem(
ThemeData theme,
bool isCurr,
int index,
BiliDownloadEntryInfo entry,
) {
final outline = theme.colorScheme.outline;
return Padding(
padding: const EdgeInsets.only(bottom: 2),
child: SizedBox(
height: 98,
child: Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () {
if (isCurr) {
return;
}
_controller.playIndex(index, entry: entry);
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: StyleString.safeSpace,
vertical: 5,
),
child: Row(
spacing: 10,
children: [
Stack(
clipBehavior: Clip.none,
children: [
NetworkImgLayer(
src: entry.cover,
width: 140.8,
height: 88,
),
PBadge(
text: DurationUtils.formatDuration(
entry.totalTimeMilli ~/ 1000,
),
right: 6.0,
bottom: 6.0,
type: PBadgeType.gray,
),
if (entry.videoQuality case final videoQuality?)
PBadge(
text: VideoQuality.fromCode(videoQuality).shortDesc,
right: 6.0,
top: 6.0,
type: PBadgeType.gray,
),
],
),
Expanded(
child: Stack(
clipBehavior: Clip.none,
children: [
Column(
spacing: 5,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
entry.title,
textAlign: TextAlign.start,
style: TextStyle(
fontSize: theme.textTheme.bodyMedium!.fontSize,
height: 1.42,
letterSpacing: 0.3,
color: isCurr
? theme.colorScheme.primary
: null,
fontWeight: isCurr ? FontWeight.bold : null,
),
maxLines: entry.ep != null ? 1 : 2,
overflow: TextOverflow.ellipsis,
),
if (entry.pageData?.part case final part?)
if (part != entry.title)
Text(
part,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.onSurfaceVariant,
),
),
if (entry.ep?.showTitle case final showTitle?)
Text(
showTitle,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
if (entry.ownerName case final ownerName?)
Align(
alignment: Alignment.bottomLeft,
child: Text(
ownerName,
maxLines: 1,
style: TextStyle(
fontSize: 12,
height: 1,
color: outline,
),
),
),
Align(
alignment: Alignment.bottomRight,
child: entry.moreBtn(theme),
),
],
),
),
],
),
),
),
),
),
);
}
}

View File

@@ -19,7 +19,6 @@ import 'package:PiliPlus/models_new/video/video_detail/episode.dart'
import 'package:PiliPlus/models_new/video/video_detail/stat_detail.dart';
import 'package:PiliPlus/pages/common/common_intro_controller.dart';
import 'package:PiliPlus/pages/dynamics_repost/view.dart';
import 'package:PiliPlus/pages/video/controller.dart';
import 'package:PiliPlus/pages/video/pay_coins/view.dart';
import 'package:PiliPlus/pages/video/reply/controller.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
@@ -66,7 +65,7 @@ class PgcIntroController extends CommonIntroController {
super.onInit();
if (isPgc) {
if (accountService.isLogin.value) {
if (isLogin) {
queryIsFollowed();
if (epId != null) {
queryPgcLikeCoinFav();
@@ -101,7 +100,7 @@ class PgcIntroController extends CommonIntroController {
// (取消)点赞
@override
Future<void> actionLikeVideo() async {
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -119,7 +118,7 @@ class PgcIntroController extends CommonIntroController {
// 投币
@override
void actionCoinVideo() {
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -294,7 +293,7 @@ class PgcIntroController extends CommonIntroController {
this.epId = epId;
this.bvid = bvid;
final videoDetailCtr = Get.find<VideoDetailController>(tag: heroTag)
videoDetailCtr
..plPlayerController.pause()
..makeHeartBeat()
..onReset()
@@ -316,7 +315,7 @@ class PgcIntroController extends CommonIntroController {
} catch (_) {}
}
if (isPgc && accountService.isLogin.value) {
if (isPgc && isLogin) {
queryPgcLikeCoinFav();
}
@@ -364,9 +363,6 @@ class PgcIntroController extends CommonIntroController {
@override
bool prevPlay() {
final episodes = pgcItem.episodes!;
VideoDetailController videoDetailCtr = Get.find<VideoDetailController>(
tag: heroTag,
);
int currentIndex = episodes.indexWhere(
(e) => e.cid == videoDetailCtr.cid.value,
);
@@ -388,9 +384,7 @@ class PgcIntroController extends CommonIntroController {
bool nextPlay() {
try {
final episodes = pgcItem.episodes!;
VideoDetailController videoDetailCtr = Get.find<VideoDetailController>(
tag: heroTag,
);
PlayRepeat playRepeat = videoDetailCtr.plPlayerController.playRepeat;
int currentIndex = episodes.indexWhere(
@@ -418,7 +412,7 @@ class PgcIntroController extends CommonIntroController {
@override
Future<void> actionTriple() async {
feedBack();
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}

View File

@@ -24,7 +24,6 @@ import 'package:PiliPlus/models_new/video/video_detail/stat_detail.dart';
import 'package:PiliPlus/models_new/video/video_detail/ugc_season.dart';
import 'package:PiliPlus/pages/common/common_intro_controller.dart';
import 'package:PiliPlus/pages/dynamics_repost/view.dart';
import 'package:PiliPlus/pages/video/controller.dart';
import 'package:PiliPlus/pages/video/pay_coins/view.dart';
import 'package:PiliPlus/pages/video/related/controller.dart';
import 'package:PiliPlus/pages/video/reply/controller.dart';
@@ -104,15 +103,12 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
}
videoDetail.value = data;
try {
final videoDetailController = Get.find<VideoDetailController>(
tag: heroTag,
);
if (videoDetailController.cover.value.isEmpty ||
(videoDetailController.videoUrl.isNullOrEmpty &&
!videoDetailController.isQuerying)) {
videoDetailController.cover.value = data.pic ?? '';
if (videoDetailCtr.cover.value.isEmpty ||
(videoDetailCtr.videoUrl.isNullOrEmpty &&
!videoDetailCtr.isQuerying)) {
videoDetailCtr.cover.value = data.pic ?? '';
}
if (videoDetailController.showReply) {
if (videoDetailCtr.showReply) {
try {
Get.find<VideoReplyController>(tag: heroTag).count.value =
data.stat?.reply ?? 0;
@@ -129,7 +125,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
status.value = false;
}
if (accountService.isLogin.value) {
if (isLogin) {
queryAllStatus();
queryFollowStatus();
}
@@ -184,7 +180,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
@override
Future<void> actionTriple() async {
feedBack();
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -224,7 +220,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
// (取消)点赞
@override
Future<void> actionLikeVideo() async {
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -246,7 +242,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
}
Future<void> actionDislikeVideo() async {
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -274,7 +270,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
// 投币
@override
void actionCoinVideo() {
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -426,7 +422,7 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
// 关注/取关up
Future<void> actionRelationMod(BuildContext context) async {
if (!accountService.isLogin.value) {
if (!isLogin) {
SmartDialog.showToast('账号未登录');
return;
}
@@ -479,7 +475,6 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
final String? cover = episode.cover;
// 重新获取视频资源
final videoDetailCtr = Get.find<VideoDetailController>(tag: heroTag);
if (videoDetailCtr.isPlayAll) {
if (videoDetailCtr.mediaList.indexWhere((item) => item.bvid == bvid) ==
@@ -566,7 +561,6 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
final List<BaseEpisodeItem> episodes = <BaseEpisodeItem>[];
bool isPart = false;
final videoDetailCtr = Get.find<VideoDetailController>(tag: heroTag);
final videoDetail = this.videoDetail.value;
if (!skipPart && (videoDetail.pages?.length ?? 0) > 1) {
@@ -632,7 +626,6 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
try {
final List<BaseEpisodeItem> episodes = <BaseEpisodeItem>[];
bool isPart = false;
final videoDetailCtr = Get.find<VideoDetailController>(tag: heroTag);
final videoDetail = this.videoDetail.value;
// part -> playall -> season

View File

@@ -6,6 +6,7 @@ import 'package:PiliPlus/pages/video/controller.dart';
import 'package:PiliPlus/pages/video/introduction/ugc/controller.dart';
import 'package:PiliPlus/utils/id_utils.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
// TODO refa
@@ -18,6 +19,8 @@ class PagesPanel extends StatefulWidget {
required this.heroTag,
this.showEpisodes,
required this.ugcIntroController,
this.onDownload,
this.cidSet,
});
final List<Part>? list;
@@ -28,6 +31,9 @@ class PagesPanel extends StatefulWidget {
final Function? showEpisodes;
final UgcIntroController ugcIntroController;
final Set<int?>? cidSet;
final bool Function(Part part)? onDownload;
@override
State<PagesPanel> createState() => _PagesPanelState();
}
@@ -105,7 +111,7 @@ class _PagesPanelState extends State<PagesPanel> {
const Text('视频选集 '),
Expanded(
child: Text(
' 正在播放:${pages[pageIndex].pagePart}',
' 正在播放:${pages[pageIndex].part}',
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
@@ -160,6 +166,12 @@ class _PagesPanelState extends State<PagesPanel> {
child: InkWell(
borderRadius: const BorderRadius.all(Radius.circular(6)),
onTap: () {
if (widget.onDownload case final onDownload?) {
if (onDownload(item) && mounted) {
setState(() {});
}
return;
}
if (widget.showEpisodes == null) {
Get.back();
}
@@ -193,7 +205,7 @@ class _PagesPanelState extends State<PagesPanel> {
],
Expanded(
child: Text(
item.pagePart!,
item.part!,
maxLines: 1,
style: TextStyle(
fontSize: 13,
@@ -204,6 +216,14 @@ class _PagesPanelState extends State<PagesPanel> {
overflow: TextOverflow.ellipsis,
),
),
if (widget.cidSet?.contains(item.cid) ?? false)
Icon(
size: 13,
color: theme.colorScheme.secondary.withValues(
alpha: 0.8,
),
FontAwesomeIcons.circleDown,
),
],
),
),

View File

@@ -20,7 +20,7 @@ mixin TripleMixin on GetxController, TickerProvider {
bool get hasTriple => hasLike.value && hasCoin && hasFav.value;
void actionTriple();
Future<void> actionLikeVideo();
void actionLikeVideo();
// no need for pugv
AnimationController? _tripleAnimCtr;