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

@@ -71,7 +71,7 @@ class _AboutPageState extends State<AboutPage> {
onSubmitted: (value) { onSubmitted: (value) {
Get.back(); Get.back();
if (value.isNotEmpty) { if (value.isNotEmpty) {
Get.toNamed('/webview', parameters: {'url': value}); Utils.handleWebview(value, inApp: true);
} }
}, },
), ),

View File

@@ -310,10 +310,7 @@ Widget forWard(item, context, source, callback, {floor = 1}) {
if (url.contains('bangumi/play') && Utils.viewPgcFromUri(url)) { if (url.contains('bangumi/play') && Utils.viewPgcFromUri(url)) {
return; return;
} }
Get.toNamed( Utils.handleWebview(url, inApp: true);
'/webview',
parameters: {'url': url},
);
} catch (_) {} } catch (_) {}
}, },
child: Container( child: Container(

View File

@@ -1,11 +1,11 @@
import 'package:PiliPlus/http/loading_state.dart'; import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/common/common_controller.dart'; import 'package:PiliPlus/pages/common/common_controller.dart';
import 'package:PiliPlus/pages/search_result/controller.dart'; import 'package:PiliPlus/pages/search_result/controller.dart';
import 'package:PiliPlus/utils/app_scheme.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:PiliPlus/http/search.dart'; import 'package:PiliPlus/http/search.dart';
import 'package:PiliPlus/models/common/search_type.dart'; import 'package:PiliPlus/models/common/search_type.dart';
import 'package:PiliPlus/utils/id_utils.dart'; import 'package:PiliPlus/utils/id_utils.dart';
import 'package:PiliPlus/utils/utils.dart';
class SearchPanelController extends CommonController { class SearchPanelController extends CommonController {
SearchPanelController({ SearchPanelController({
@@ -61,39 +61,17 @@ class SearchPanelController extends CommonController {
void onPushDetail(resultList) async { void onPushDetail(resultList) async {
// 匹配输入内容如果是AV、BV号且有结果 直接跳转详情页 // 匹配输入内容如果是AV、BV号且有结果 直接跳转详情页
Map matchRes = IdUtils.matchAvorBv(input: keyword); Map matchRes = IdUtils.matchAvorBv(input: keyword);
List matchKeys = matchRes.keys.toList(); if (matchRes.isNotEmpty) {
String? bvid; PiliScheme.videoPush(matchRes['AV'], matchRes['BV'], false);
try { return;
bvid = resultList.first.bvid;
} catch (_) {
bvid = null;
} }
// keyword 可能输入纯数字 // keyword 可能输入纯数字
int? aid;
try { try {
aid = resultList.first.aid; int? aid = int.tryParse(keyword);
} catch (_) { if (aid != null && resultList.first.aid == aid) {
aid = null; PiliScheme.videoPush(aid, null, false);
}
if (matchKeys.isNotEmpty && searchType == SearchType.video ||
aid.toString() == keyword) {
int cid = await SearchHttp.ab2c(aid: aid, bvid: bvid);
if (matchKeys.isNotEmpty &&
matchKeys.first == 'BV' &&
matchRes[matchKeys.first] == bvid ||
matchKeys.isNotEmpty &&
matchKeys.first == 'AV' &&
matchRes[matchKeys.first] == aid ||
aid.toString() == keyword) {
Get.toNamed(
'/video?bvid=$bvid&cid=$cid',
arguments: {
'videoItem': resultList.first,
'heroTag': Utils.makeHeroTag(bvid),
},
);
}
} }
} catch (_) {}
} }
@override @override

View File

@@ -221,7 +221,9 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
return NavigationActionPolicy.CANCEL; return NavigationActionPolicy.CANCEL;
} }
} catch (_) {} } catch (_) {}
} else if (url.startsWith('http://m.bilibili.com/playlist/')) { } else if (RegExp(
r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)/playlist')
.hasMatch(url)) {
try { try {
String? bvid = String? bvid =
RegExp(r'bvid=(BV[a-zA-Z\d]+)').firstMatch(url)?.group(1); RegExp(r'bvid=(BV[a-zA-Z\d]+)').firstMatch(url)?.group(1);
@@ -230,9 +232,10 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
return NavigationActionPolicy.CANCEL; return NavigationActionPolicy.CANCEL;
} }
} catch (_) {} } catch (_) {}
} else { } else if (url.startsWith('http').not) {
if (url.startsWith('bilibili://video/')) { if (url.startsWith('bilibili://video/')) {
String? str = Uri.parse(url).pathSegments.getOrNull(0); String? str =
navigationAction.request.url!.pathSegments.getOrNull(0);
Get.offAndToNamed( Get.offAndToNamed(
'/searchResult', '/searchResult',
parameters: {'keyword': str ?? ''}, parameters: {'keyword': str ?? ''},

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 { try {
aid ??= IdUtils.bv2av(bvid!); aid ??= IdUtils.bv2av(bvid!);
bvid ??= IdUtils.av2bv(aid); bvid ??= IdUtils.av2bv(aid);
if (showDialog) {
SmartDialog.showLoading<dynamic>(msg: '获取中...'); SmartDialog.showLoading<dynamic>(msg: '获取中...');
}
final int cid = await SearchHttp.ab2c(bvid: bvid, aid: aid); final int cid = await SearchHttp.ab2c(bvid: bvid, aid: aid);
if (showDialog) {
SmartDialog.dismiss(); SmartDialog.dismiss();
}
Utils.toDupNamed( Utils.toDupNamed(
'/video?bvid=$bvid&cid=$cid', '/video?bvid=$bvid&cid=$cid',
arguments: <String, String?>{ arguments: <String, String?>{

View File

@@ -68,10 +68,11 @@ class IdUtils {
if (input == null || input.isEmpty) { if (input == null || input.isEmpty) {
return result; 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); 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); late String? aid = avRegex.firstMatch(input)?.group(1);
if (bvid != null) { 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/later/controller.dart';
import 'package:PiliPlus/pages/video/detail/introduction/widgets/fav_panel.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/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/extension.dart';
import 'package:PiliPlus/utils/feed_back.dart'; import 'package:PiliPlus/utils/feed_back.dart';
import 'package:PiliPlus/utils/id_utils.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( static void handleWebview(
String url, { String url, {
bool off = false, bool off = false,
bool inApp = false, bool inApp = false,
}) { }) {
if (inApp.not && GStorage.openInBrowser) { if (inApp.not && GStorage.openInBrowser) {
if (RegExp(r'^(https?://)?((www|m).)?(bilibili|b23).(com|tv)') if (_handleInAppWebview(url).not) {
.hasMatch(url)) {
toDupNamed(
'/webview',
parameters: {'url': url},
);
} else {
launchURL(url); launchURL(url);
} }
} else { } else {
@@ -389,6 +417,7 @@ class Utils {
parameters: {'url': url}, parameters: {'url': url},
); );
} else { } else {
if (_handleInAppWebview(url).not) {
toDupNamed( toDupNamed(
'/webview', '/webview',
parameters: {'url': url}, parameters: {'url': url},
@@ -396,6 +425,7 @@ class Utils {
} }
} }
} }
}
static bool viewPgcFromUri(String uri) { static bool viewPgcFromUri(String uri) {
String? id = RegExp(r'(ep|ss)\d+').firstMatch(uri)?.group(0); String? id = RegExp(r'(ep|ss)\d+').firstMatch(uri)?.group(0);