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,75 @@
import 'dart:async';
import 'package:PiliPlus/models_new/download/download_info.dart';
import 'package:PiliPlus/services/download/download_service.dart';
import 'package:get/get.dart';
class DownloadPageController extends GetxController {
final _downloadService = Get.find<DownloadService>();
late final StreamSubscription _sub;
final pages = RxList<DownloadPageInfo>();
final flag = RxInt(0);
@override
void onInit() {
super.onInit();
_loadList();
_sub = _downloadService.downloaFlag.listen((_) {
_loadList();
});
}
@override
void onClose() {
_sub.cancel();
super.onClose();
}
Future<void> _loadList() async {
await _downloadService.waitForInitialization;
if (isClosed) return;
if (_downloadService.downloadList.isEmpty) {
pages.clear();
return;
}
final list = <DownloadPageInfo>[];
for (final entry in _downloadService.downloadList) {
final pageId = entry.pageId;
final page = list.firstWhereOrNull((e) => e.pageId == pageId);
if (page != null) {
final aSortKey = entry.sortKey;
if (!entry.isCompleted) {
if (page.entry case final lastEntry?) {
if (aSortKey < lastEntry.sortKey) {
page.entry = entry;
}
} else {
page.entry = entry;
}
}
final bSortKey = page.sortKey;
if (aSortKey < bSortKey) {
page
..cover = entry.cover
..sortKey = aSortKey;
}
page.entrys.add(entry);
} else {
list.add(
DownloadPageInfo(
pageId: pageId,
dirPath: entry.pageDirPath,
title: entry.title,
cover: entry.cover,
sortKey: entry.sortKey,
seasonType: entry.ep?.seasonType,
entrys: [entry],
entry: entry.isCompleted ? null : entry,
),
);
}
}
pages.value = list;
flag.value++;
}
}