opt: webview to video

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-02-08 22:56:43 +08:00
parent 9a3766e7b7
commit 7cfebcb6ed
7 changed files with 68 additions and 54 deletions

View File

@@ -225,13 +225,18 @@ class PiliScheme {
}
// 投稿跳转
static Future<void> videoPush(int? aid, String? bvid) async {
static Future<void> videoPush(int? aid, String? bvid,
[bool showDialog = true]) async {
try {
aid ??= IdUtils.bv2av(bvid!);
bvid ??= IdUtils.av2bv(aid);
SmartDialog.showLoading<dynamic>(msg: '获取中...');
if (showDialog) {
SmartDialog.showLoading<dynamic>(msg: '获取中...');
}
final int cid = await SearchHttp.ab2c(bvid: bvid, aid: aid);
SmartDialog.dismiss();
if (showDialog) {
SmartDialog.dismiss();
}
Utils.toDupNamed(
'/video?bvid=$bvid&cid=$cid',
arguments: <String, String?>{

View File

@@ -68,10 +68,11 @@ class IdUtils {
if (input == null || input.isEmpty) {
return result;
}
final RegExp bvRegex = RegExp(r'bv([0-9A-Za-z]+)', caseSensitive: false);
final RegExp bvRegex =
RegExp(r'^bv([0-9A-Za-z]{10})', caseSensitive: false);
String? bvid = bvRegex.firstMatch(input)?.group(1);
late final RegExp avRegex = RegExp(r'av(\d+)', caseSensitive: false);
late final RegExp avRegex = RegExp(r'^av(\d+)', caseSensitive: false);
late String? aid = avRegex.firstMatch(input)?.group(1);
if (bvid != null) {

View File

@@ -21,6 +21,7 @@ import 'package:PiliPlus/models/user/fav_folder.dart';
import 'package:PiliPlus/pages/later/controller.dart';
import 'package:PiliPlus/pages/video/detail/introduction/widgets/fav_panel.dart';
import 'package:PiliPlus/pages/video/detail/introduction/widgets/group_panel.dart';
import 'package:PiliPlus/utils/app_scheme.dart';
import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/feed_back.dart';
import 'package:PiliPlus/utils/id_utils.dart';
@@ -367,19 +368,46 @@ class Utils {
);
}
static bool _handleInAppWebview(String url) {
if (RegExp(
r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)/video/BV[a-zA-Z\d]+')
.hasMatch(url)) {
try {
String? bvid = RegExp(r'BV[a-zA-Z\d]+').firstMatch(url)?.group(0);
if (bvid != null) {
PiliScheme.videoPush(null, bvid);
return true;
}
} catch (_) {}
} else if (RegExp(
r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)/playlist')
.hasMatch(url)) {
try {
String? bvid =
RegExp(r'bvid=(BV[a-zA-Z\d]+)').firstMatch(url)?.group(1);
if (bvid != null) {
PiliScheme.videoPush(null, bvid);
return true;
}
} catch (_) {}
} else if (RegExp(r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)')
.hasMatch(url)) {
toDupNamed(
'/webview',
parameters: {'url': url},
);
return true;
}
return false;
}
static void handleWebview(
String url, {
bool off = false,
bool inApp = false,
}) {
if (inApp.not && GStorage.openInBrowser) {
if (RegExp(r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)')
.hasMatch(url)) {
toDupNamed(
'/webview',
parameters: {'url': url},
);
} else {
if (_handleInAppWebview(url).not) {
launchURL(url);
}
} else {
@@ -389,10 +417,12 @@ class Utils {
parameters: {'url': url},
);
} else {
toDupNamed(
'/webview',
parameters: {'url': url},
);
if (_handleInAppWebview(url).not) {
toDupNamed(
'/webview',
parameters: {'url': url},
);
}
}
}
}