mod: CDN优化 issues #70
This commit is contained in:
@ -105,6 +105,7 @@ class SettingBoxKey {
|
||||
static const String enableAutoEnter = 'enableAutoEnter';
|
||||
static const String enableAutoExit = 'enableAutoExit';
|
||||
static const String p1080 = 'p1080';
|
||||
static const String enableCDN = 'enableCDN';
|
||||
|
||||
// youtube 双击快进快退
|
||||
static const String enableQuickDouble = 'enableQuickDouble';
|
||||
|
36
lib/utils/video_utils.dart
Normal file
36
lib/utils/video_utils.dart
Normal file
@ -0,0 +1,36 @@
|
||||
import 'package:pilipala/models/video/play/url.dart';
|
||||
|
||||
class VideoUtils {
|
||||
static String getCdnUrl(dynamic item) {
|
||||
var backupUrl = "";
|
||||
var videoUrl = "";
|
||||
|
||||
/// 先获取backupUrl 一般是upgcxcode地址 播放更稳定
|
||||
if (item is VideoItem) {
|
||||
backupUrl = item.backupUrl ?? "";
|
||||
videoUrl = backupUrl.contains("http") ? backupUrl : (item.baseUrl ?? "");
|
||||
} else if (item is AudioItem) {
|
||||
backupUrl = item.backupUrl ?? "";
|
||||
videoUrl = backupUrl.contains("http") ? backupUrl : (item.baseUrl ?? "");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
/// issues #70
|
||||
if (videoUrl.contains(".mcdn.bilivideo") ||
|
||||
videoUrl.contains("/upgcxcode/")) {
|
||||
//CDN列表
|
||||
var cdnList = {
|
||||
'ali': 'upos-sz-mirrorali.bilivideo.com',
|
||||
'cos': 'upos-sz-mirrorcos.bilivideo.com',
|
||||
'hw': 'upos-sz-mirrorhw.bilivideo.com',
|
||||
};
|
||||
//取一个CDN
|
||||
var cdn = cdnList['ali'] ?? "";
|
||||
var reg = RegExp(r'(http|https)://(.*?)/upgcxcode/');
|
||||
videoUrl = videoUrl.replaceAll(reg, "https://$cdn/upgcxcode/");
|
||||
}
|
||||
|
||||
return videoUrl;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user