mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 11:08:03 +08:00
refa: cdn (#1743)
* refa: cdn * feat: live cdn (WIP) * tweaks Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * add live quality [skip ci] Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> * mod: replace durl host * tweak [skip ci] Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me> --------- Co-authored-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
e589f27195
commit
27ae296b28
@@ -68,7 +68,7 @@ class SelectDialog<T> extends StatelessWidget {
|
||||
}
|
||||
|
||||
class CdnSelectDialog extends StatefulWidget {
|
||||
final VideoItem? sample;
|
||||
final BaseItem? sample;
|
||||
|
||||
const CdnSelectDialog({
|
||||
super.key,
|
||||
@@ -113,7 +113,7 @@ class _CdnSelectDialogState extends State<CdnSelectDialog> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<VideoItem> _getSampleUrl() async {
|
||||
Future<BaseItem> _getSampleUrl() async {
|
||||
final result = await VideoHttp.videoUrl(
|
||||
cid: 196018899,
|
||||
bvid: 'BV1fK4y1t7hj',
|
||||
@@ -134,16 +134,19 @@ class _CdnSelectDialogState extends State<CdnSelectDialog> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _testAllCdnServices(VideoItem videoItem) async {
|
||||
Future<void> _testAllCdnServices(BaseItem videoItem) async {
|
||||
for (final item in CDNService.values) {
|
||||
if (!mounted) break;
|
||||
await _testSingleCdn(item, videoItem);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _testSingleCdn(CDNService item, VideoItem videoItem) async {
|
||||
Future<void> _testSingleCdn(CDNService item, BaseItem videoItem) async {
|
||||
try {
|
||||
final cdnUrl = VideoUtils.getCdnUrl(videoItem, item.code);
|
||||
final cdnUrl = VideoUtils.getCdnUrl(
|
||||
videoItem.playUrls,
|
||||
defaultCDNService: item,
|
||||
);
|
||||
await _measureDownloadSpeed(cdnUrl, item.index);
|
||||
} catch (e) {
|
||||
_handleSpeedTestError(e, item.index);
|
||||
@@ -211,7 +214,17 @@ class _CdnSelectDialogState extends State<CdnSelectDialog> {
|
||||
|
||||
if (kDebugMode) debugPrint('CDN speed test error: $error');
|
||||
if (!mounted) return;
|
||||
var message = error.toString();
|
||||
String message;
|
||||
if (error is DioException) {
|
||||
final statusCode = error.response?.statusCode;
|
||||
if (statusCode != null && 400 <= statusCode && statusCode < 500) {
|
||||
message = '此视频可能无法替换为该CDN';
|
||||
} else {
|
||||
message = error.toString();
|
||||
}
|
||||
} else {
|
||||
message = error.toString();
|
||||
}
|
||||
if (message.isEmpty) {
|
||||
message = '测速失败';
|
||||
}
|
||||
@@ -220,9 +233,9 @@ class _CdnSelectDialogState extends State<CdnSelectDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SelectDialog<String>(
|
||||
return SelectDialog<CDNService>(
|
||||
title: 'CDN 设置',
|
||||
values: CDNService.values.map((i) => (i.code, i.desc)).toList(),
|
||||
values: CDNService.values.map((i) => (i, i.desc)).toList(),
|
||||
value: VideoUtils.cdnService,
|
||||
subtitleBuilder: _cdnSpeedTest
|
||||
? (context, index) {
|
||||
|
||||
Reference in New Issue
Block a user