mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: speed test
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -53,22 +53,20 @@ class _SelectDialogState<T> extends State<SelectDialog<T>> {
|
|||||||
..options.headers['referer'] = 'https://www.bilibili.com/';
|
..options.headers['referer'] = 'https://www.bilibili.com/';
|
||||||
int maxSize = 8 * 1024 * 1024;
|
int maxSize = 8 * 1024 * 1024;
|
||||||
int downloaded = 0;
|
int downloaded = 0;
|
||||||
Stopwatch stopwatch = Stopwatch()..start();
|
int start = DateTime.now().millisecondsSinceEpoch;
|
||||||
try {
|
try {
|
||||||
await dio.get(
|
await dio.get(
|
||||||
videoUrl,
|
videoUrl,
|
||||||
onReceiveProgress: (int count, int total) {
|
onReceiveProgress: (int count, int total) {
|
||||||
downloaded += count;
|
downloaded += count;
|
||||||
if (stopwatch.elapsedMilliseconds > 15 * 1000) {
|
int now = DateTime.now().millisecondsSinceEpoch;
|
||||||
stopwatch.stop();
|
if (now - start > 15 * 1000) {
|
||||||
dio.close(force: true);
|
dio.close(force: true);
|
||||||
}
|
}
|
||||||
if (downloaded >= maxSize) {
|
if (downloaded >= maxSize) {
|
||||||
stopwatch.stop();
|
|
||||||
dio.close(force: true);
|
dio.close(force: true);
|
||||||
_cdnResList[item.index] =
|
_cdnResList[item.index] =
|
||||||
(maxSize / stopwatch.elapsedMilliseconds / 1000)
|
(maxSize / (now - start) / 1000).toPrecision(2);
|
||||||
.toPrecision(2);
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
@@ -76,7 +74,6 @@ class _SelectDialogState<T> extends State<SelectDialog<T>> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
stopwatch.stop();
|
|
||||||
if (_cdnResList[item.index] == null) {
|
if (_cdnResList[item.index] == null) {
|
||||||
_cdnResList[item.index] = '测速失败: $e';
|
_cdnResList[item.index] = '测速失败: $e';
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@@ -84,9 +81,6 @@ class _SelectDialogState<T> extends State<SelectDialog<T>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (stopwatch.isRunning) {
|
|
||||||
stopwatch.stop();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user