mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-28 21:30:18 +08:00
* opt: danmaku weight
* opt: cache clean
* opt: level img
* opt: play icon
* opt: svg big-vip
* opt: webview ua
* opt: simple dialog
* feat: export vtt
* tweak
* opt: mapIndexed
* feat: more subtitle
* refa: settings page
* feat: codec list options
* drawPath
Signed-off-by: dom <githubaccount56556@proton.me>
* custom dialog option
Signed-off-by: dom <githubaccount56556@proton.me>
* update
Signed-off-by: dom <githubaccount56556@proton.me>
* Revert "drawPath"
This reverts commit e8a4b19f0f.
* opt: _initStreamIndex
* fix: avoid gap
* fix: scale [skip ci]
* fix: hide repost menu not login
* tweaks
Signed-off-by: dom <githubaccount56556@proton.me>
---------
Co-authored-by: dom <githubaccount56556@proton.me>
122 lines
3.6 KiB
Dart
122 lines
3.6 KiB
Dart
import 'package:PiliPlus/models/common/video/cdn_type.dart';
|
|
import 'package:PiliPlus/models/common/video/video_decode_type.dart';
|
|
import 'package:PiliPlus/models_new/live/live_room_play_info/codec.dart';
|
|
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
|
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
|
import 'package:flutter/foundation.dart' show kDebugMode, debugPrint;
|
|
|
|
abstract final class VideoUtils {
|
|
static CDNService cdnService = Pref.defaultCDNService;
|
|
static String? liveCdnUrl = Pref.liveCdnUrl;
|
|
static bool disableAudioCDN = Pref.disableAudioCDN;
|
|
|
|
static const _proxyTf = 'proxy-tf-all-ws.bilivideo.com';
|
|
|
|
static final _mirrorRegex = RegExp(
|
|
r'^https?://(?:upos-\w+-(?!302)\w+|(?:upos|proxy)-tf-[^/]+)\.(?:bilivideo|akamaized)\.(?:com|net)/upgcxcode',
|
|
);
|
|
|
|
static final _mCdnTfRegex = RegExp(
|
|
r'^https?://(?:(?:(?:\d{1,3}\.){3}\d{1,3}|[^/]+\.mcdn\.bilivideo\.(?:com|cn|net))(?:\:\d{1,5})?/v\d/resource)',
|
|
);
|
|
|
|
static String getCdnUrl(
|
|
Iterable<String> urls, {
|
|
CDNService? defaultCDNService,
|
|
bool isAudio = false,
|
|
}) {
|
|
defaultCDNService ??= cdnService;
|
|
|
|
if (defaultCDNService == CDNService.baseUrl) {
|
|
return urls.first;
|
|
}
|
|
|
|
String? mcdnTf;
|
|
String? mcdnUpgcxcode;
|
|
|
|
String last = '';
|
|
for (final url in urls) {
|
|
last = url;
|
|
if (_mirrorRegex.hasMatch(url)) {
|
|
final uri = Uri.parse(url);
|
|
if (uri.queryParameters['os'] == 'mcdn') {
|
|
// upos-sz-mirrorcoso1.bilivideo.com os=mcdn
|
|
mcdnUpgcxcode = url;
|
|
} else {
|
|
if (defaultCDNService == CDNService.backupUrl ||
|
|
(isAudio && disableAudioCDN)) {
|
|
return url;
|
|
}
|
|
return uri.replace(host: defaultCDNService.host).toString();
|
|
}
|
|
}
|
|
|
|
if (_mCdnTfRegex.hasMatch(url)) {
|
|
mcdnTf = url;
|
|
continue;
|
|
}
|
|
|
|
// upos-\w*-302.* & bcache & mcdn host but upgcxcode path
|
|
if (url.contains('/upgcxcode/')) {
|
|
mcdnUpgcxcode = url;
|
|
continue;
|
|
}
|
|
|
|
// may be deprecated
|
|
if (url.contains('szbdyd.com')) {
|
|
final uri = Uri.parse(url);
|
|
final hostname =
|
|
uri.queryParameters['xy_usource'] ?? defaultCDNService.host;
|
|
return uri
|
|
.replace(scheme: 'https', host: hostname, port: 443)
|
|
.toString();
|
|
}
|
|
|
|
if (kDebugMode) {
|
|
debugPrint('unknown cdn type: $url');
|
|
}
|
|
}
|
|
|
|
return mcdnUpgcxcode == null
|
|
? mcdnTf == null
|
|
? last
|
|
: Uri(
|
|
scheme: 'https',
|
|
host: _proxyTf,
|
|
queryParameters: {'url': mcdnTf},
|
|
).toString()
|
|
: Uri.parse(mcdnUpgcxcode)
|
|
.replace(host: defaultCDNService.host ?? CDNService.ali.host)
|
|
.toString();
|
|
}
|
|
|
|
static String getLiveCdnUrl(CodecItem e, {int index = 0}) {
|
|
final urlInfo = e.urlInfo.getOrFirst(index);
|
|
return (liveCdnUrl ?? urlInfo.host) + e.baseUrl + urlInfo.extra;
|
|
}
|
|
|
|
static VideoDecodeFormatType selectCodec(
|
|
Iterable<String> codecs,
|
|
List<VideoDecodeFormatType> preferCodecs,
|
|
) {
|
|
if (preferCodecs.isNotEmpty) {
|
|
int bestIndex = preferCodecs.length;
|
|
for (final e in codecs) {
|
|
for (int i = 0; i < bestIndex; i++) {
|
|
if (preferCodecs[i].codes.any(e.startsWith)) {
|
|
bestIndex = i;
|
|
if (bestIndex == 0) {
|
|
return preferCodecs[0];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (bestIndex < preferCodecs.length) {
|
|
return preferCodecs[bestIndex];
|
|
}
|
|
}
|
|
return VideoDecodeFormatType.fromString(codecs.first);
|
|
}
|
|
}
|