mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 新增更多CDN选项,且默认单独关闭音频CDN
This commit is contained in:
@@ -1,44 +1,101 @@
|
||||
import 'package:PiliPalaX/models/video/play/CDN.dart';
|
||||
import 'package:PiliPalaX/models/video/play/url.dart';
|
||||
import 'package:PiliPalaX/utils/storage.dart';
|
||||
|
||||
import '../models/live/room_info.dart';
|
||||
|
||||
class VideoUtils {
|
||||
static String getCdnUrl(dynamic item) {
|
||||
var backupUrl = "";
|
||||
var videoUrl = "";
|
||||
static bool isMCDNorPCDN(String url) {
|
||||
return url.contains("szbdyd.com") ||
|
||||
url.contains(".mcdn.bilivideo") ||
|
||||
RegExp(r'^https?://\d{1,3}\.\d{1,3}').hasMatch(url);
|
||||
}
|
||||
|
||||
/// 先获取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 if (item is CodecItem) {
|
||||
static String getCdnUrl(dynamic item) {
|
||||
String? backupUrl;
|
||||
String? videoUrl;
|
||||
String defaultCDNService = GStorage.setting
|
||||
.get(SettingBoxKey.CDNService, defaultValue: CDNService.ali.code);
|
||||
if (item is AudioItem) {
|
||||
if (GStorage.setting
|
||||
.get(SettingBoxKey.disableAudioCDN, defaultValue: true)) {
|
||||
return item.backupUrl ?? item.baseUrl ?? "";
|
||||
}
|
||||
}
|
||||
if (defaultCDNService == CDNService.baseUrl.code) {
|
||||
return item.baseUrl ?? "";
|
||||
}
|
||||
if (item is CodecItem) {
|
||||
backupUrl = (item.urlInfo?.first.host)! +
|
||||
item.baseUrl! +
|
||||
item.urlInfo!.first.extra!;
|
||||
videoUrl = backupUrl.contains("http") ? backupUrl : (item.baseUrl ?? "");
|
||||
} else {
|
||||
backupUrl = item.backupUrl;
|
||||
}
|
||||
if (defaultCDNService == CDNService.backupUrl.code) {
|
||||
return backupUrl ?? item.baseUrl ?? "";
|
||||
}
|
||||
videoUrl = (backupUrl == null || isMCDNorPCDN(backupUrl))
|
||||
? item.baseUrl
|
||||
: backupUrl;
|
||||
|
||||
if (videoUrl == null) {
|
||||
return "";
|
||||
}
|
||||
print("videoUrl:$videoUrl");
|
||||
|
||||
/// issues #70
|
||||
if (videoUrl.contains(".mcdn.bilivideo")) {
|
||||
String defaultCDNHost = CDNServiceCode.fromCode(defaultCDNService)!.host;
|
||||
print("defaultCDNHost:$defaultCDNHost");
|
||||
if (videoUrl.contains("szbdyd.com")) {
|
||||
String hostname =
|
||||
Uri.parse(videoUrl).queryParameters['xy_usource'] ?? defaultCDNHost;
|
||||
videoUrl =
|
||||
'https://proxy-tf-all-ws.bilivideo.com/?url=${Uri.encodeComponent(videoUrl)}';
|
||||
Uri.parse(videoUrl).replace(host: hostname, port: 443).toString();
|
||||
} else if (videoUrl.contains(".mcdn.bilivideo")) {
|
||||
videoUrl = Uri.parse(videoUrl)
|
||||
.replace(host: defaultCDNHost, port: 443)
|
||||
.toString();
|
||||
// videoUrl =
|
||||
// 'https://proxy-tf-all-ws.bilivideo.com/?url=${Uri.encodeComponent(videoUrl)}';
|
||||
} else if (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/");
|
||||
videoUrl = Uri.parse(videoUrl)
|
||||
.replace(host: defaultCDNHost, port: 443)
|
||||
.toString();
|
||||
}
|
||||
print("videoUrl:$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 if (item is CodecItem) {
|
||||
// backupUrl = (item.urlInfo?.first.host)! +
|
||||
// item.baseUrl! +
|
||||
// item.urlInfo!.first.extra!;
|
||||
// videoUrl = backupUrl.contains("http") ? backupUrl : (item.baseUrl ?? "");
|
||||
// } else {
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// /// issues #70
|
||||
// if (videoUrl.contains(".mcdn.bilivideo")) {
|
||||
// videoUrl =
|
||||
// 'https://proxy-tf-all-ws.bilivideo.com/?url=${Uri.encodeComponent(videoUrl)}';
|
||||
// } else if (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['cos'] ?? "";
|
||||
// var reg = RegExp(r'(http|https)://(.*?)/upgcxcode/');
|
||||
// videoUrl = videoUrl.replaceAll(reg, "https://$cdn/upgcxcode/");
|
||||
// }
|
||||
|
||||
return videoUrl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user