mod: CDN优化 issues #70

This commit is contained in:
guozhigq
2023-10-21 01:11:38 +08:00
parent 41e9cfcbbb
commit 9744ec88a0
29 changed files with 89 additions and 38 deletions

View File

@ -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';

View 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;
}
}