This commit is contained in:
My-Responsitories
2026-01-07 15:01:13 +08:00
parent 678cc919c7
commit a575fc7627
8 changed files with 52 additions and 47 deletions

View File

@@ -44,13 +44,12 @@ abstract final class UserHttp {
}
}
static Future<dynamic> userStatOwner() async {
static Future<LoadingState<UserStat>> userStatOwner() async {
final res = await Request().get(Api.userStatOwner);
if (res.data['code'] == 0) {
UserStat data = UserStat.fromJson(res.data['data']);
return {'status': true, 'data': data};
return Success(UserStat.fromJson(res.data['data']));
} else {
return {'status': false, 'msg': res.data['message']};
return Error(res.data['message']);
}
}

View File

@@ -36,7 +36,7 @@ class BiliDownloadEntryInfo with MultiSelectData {
late String pageDirPath;
late String entryDirPath;
DownloadStatus? status;
DownloadStatus status = .wait;
int get cid => source?.cid ?? pageData!.cid;
@@ -398,4 +398,6 @@ enum DownloadStatus {
final String message;
const DownloadStatus(this.message);
bool get isDownloading => index <= 3;
}

View File

@@ -145,7 +145,7 @@ class DetailItem extends StatelessWidget {
final curDownload = downloadService.curDownload.value;
if (curDownload != null &&
curDownload.cid == cid &&
curDownload.status!.index <= 3) {
curDownload.status.isDownloading) {
downloadService.cancelDownload(
isDelete: false,
downloadNext: false,
@@ -352,7 +352,7 @@ class DetailItem extends StatelessWidget {
? theme.colorScheme.primary
: theme.colorScheme.outline;
return progressWidget(
statusMsg: status!.message,
statusMsg: status.message,
progressStr:
status ==
DownloadStatus
@@ -385,7 +385,7 @@ class DetailItem extends StatelessWidget {
}
Widget entryProgress(ThemeData theme) => progressWidget(
statusMsg: entry.status?.message ?? '暂停中',
statusMsg: entry.status.message,
progressStr: entry.totalBytes == 0
? ''
: '${CacheManager.formatSize(entry.downloadedBytes)}/${CacheManager.formatSize(entry.totalBytes)}',

View File

@@ -126,8 +126,8 @@ class MineController extends CommonDataController<FavFolderData, FavFolderData>
Future<void> queryUserStatOwner() async {
final res = await UserHttp.userStatOwner();
if (res['status']) {
userStat.value = res['data'];
if (res case Success(:final response)) {
userStat.value = response;
}
}

View File

@@ -402,7 +402,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
@override
// 返回当前页面时
Future<void> didPopNext() async {
void didPopNext() {
if (videoDetailController.imageview) {
videoDetailController.imageview = false;
return;
@@ -442,20 +442,24 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness();
}
}
super.didPopNext();
if (videoDetailController.autoPlay.value) {
await videoDetailController.playerInit(
autoplay: videoDetailController.playerStatus == PlayerStatus.playing,
);
} else if (videoDetailController.plPlayerController.preInitPlayer &&
!videoDetailController.isQuerying &&
videoDetailController.videoState.value is! Error) {
await videoDetailController.playerInit();
}
plPlayerController
?..addStatusLister(playerListener)
..addPositionListener(positionListener);
() async {
if (videoDetailController.autoPlay.value) {
await videoDetailController.playerInit(
autoplay: videoDetailController.playerStatus == PlayerStatus.playing,
);
} else if (videoDetailController.plPlayerController.preInitPlayer &&
!videoDetailController.isQuerying &&
videoDetailController.videoState.value is! Error) {
await videoDetailController.playerInit();
}
plPlayerController
?..addStatusLister(playerListener)
..addPositionListener(positionListener);
}();
super.didPopNext();
}
@override

View File

@@ -497,13 +497,13 @@ class PlPlayerController {
return _instance != null;
}
static void setPlayCallBack(Function? playCallBack) {
static void setPlayCallBack(VoidCallback? playCallBack) {
_playCallBack = playCallBack;
}
static Function? _playCallBack;
static VoidCallback? _playCallBack;
static void playIfExists({bool repeat = false, bool hideControls = true}) {
static void playIfExists() {
// await _instance?.play(repeat: repeat, hideControls: hideControls);
_playCallBack?.call();
}

View File

@@ -246,8 +246,7 @@ class DownloadService extends GetxService {
..entryDirPath = entryDir.path
..status = DownloadStatus.wait;
waitDownloadQueue.add(entry);
final currStatus = curDownload.value?.status?.index;
if (currStatus == null || currStatus > 3) {
if (curDownload.value?.status.isDownloading != true) {
startDownload(entry);
}
}
@@ -285,9 +284,10 @@ class DownloadService extends GetxService {
await _audioDownloadManager?.cancel(isDelete: false);
_downloadManager = null;
_audioDownloadManager = null;
final prevStatus = curDownload.value?.status?.index;
if (prevStatus != null && prevStatus <= 3) {
curDownload.value?.status = DownloadStatus.pause;
if (curDownload.value case final curEntry?) {
if (curEntry.status.isDownloading) {
curEntry.status = DownloadStatus.pause;
}
}
_curCid = entry.cid;
@@ -372,13 +372,12 @@ class DownloadService extends GetxService {
_updateCurStatus(DownloadStatus.getPlayUrl);
final BiliDownloadMediaInfo mediaFileInfo =
await DownloadHttp.getVideoUrl(
entry: entry,
ep: entry.ep,
source: entry.source,
pageData: entry.pageData,
);
final mediaFileInfo = await DownloadHttp.getVideoUrl(
entry: entry,
ep: entry.ep,
source: entry.source,
pageData: entry.pageData,
);
final videoDir = Directory(path.join(entry.entryDirPath, entry.typeTag));
if (!videoDir.existsSync()) {

View File

@@ -2,6 +2,7 @@
// https://github.com/SocialSisterYi/bilibili-API-collect/blob/master/docs/misc/sign/wbi.md
// import md5 from 'md5'
// import axios from 'axios'
import 'dart:async';
import 'dart:convert';
import 'package:PiliPlus/http/api.dart';
@@ -74,7 +75,7 @@ abstract final class WbiSign {
.toString(); // 计算 w_rid
}
static Future<String> _getWbiKeys(DateTime nowDate) async {
static Future<String> _getWbiKeys() async {
final resp = await Request().get(Api.userInfo);
try {
final wbiUrls = resp.data['data']['wbi_img'];
@@ -84,9 +85,7 @@ abstract final class WbiSign {
Utils.getFileName(wbiUrls['sub_url'], fileExt: false),
);
_localCache
..put(LocalCacheKey.mixinKey, mixinKey)
..put(LocalCacheKey.timeStamp, nowDate.millisecondsSinceEpoch);
_localCache.put(LocalCacheKey.mixinKey, mixinKey);
return mixinKey;
} catch (_) {
@@ -94,17 +93,19 @@ abstract final class WbiSign {
}
}
static Future<String> getWbiKeys() async {
final DateTime nowDate = DateTime.now();
static FutureOr<String> getWbiKeys() {
final nowDate = DateTime.now();
if (DateTime.fromMillisecondsSinceEpoch(
_localCache.get(LocalCacheKey.timeStamp, defaultValue: 0) as int,
).day ==
nowDate.day) {
final String? mixinKey = _localCache.get(LocalCacheKey.mixinKey);
if (mixinKey != null) return mixinKey;
return _future ??= _getWbiKeys(nowDate);
return _future ??= _getWbiKeys();
} else {
return _future = _getWbiKeys(nowDate);
return _future = _localCache
.put(LocalCacheKey.timeStamp, nowDate.millisecondsSinceEpoch)
.then((_) => _getWbiKeys());
}
}