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),
),
],
),
),
],
),
),
),
),
),
);
}
}