opt: url scheme优化 issues #581
This commit is contained in:
@ -223,6 +223,10 @@
|
|||||||
android:pathPattern="/mobile/video/.*" />
|
android:pathPattern="/mobile/video/.*" />
|
||||||
<data android:scheme="https" android:host="www.bilibili.com"
|
<data android:scheme="https" android:host="www.bilibili.com"
|
||||||
android:pathPattern="/mobile/video/.*" />
|
android:pathPattern="/mobile/video/.*" />
|
||||||
|
<data android:scheme="https" android:host="b23.tv"
|
||||||
|
android:pathPattern="/*" />
|
||||||
|
<data android:scheme="https" android:host="space.bilibili.com"
|
||||||
|
android:pathPattern="/*" />
|
||||||
|
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
|||||||
import '../http/search.dart';
|
import '../http/search.dart';
|
||||||
import '../models/common/search_type.dart';
|
import '../models/common/search_type.dart';
|
||||||
import 'id_utils.dart';
|
import 'id_utils.dart';
|
||||||
|
import 'url_utils.dart';
|
||||||
import 'utils.dart';
|
import 'utils.dart';
|
||||||
|
|
||||||
class PiliSchame {
|
class PiliSchame {
|
||||||
@ -38,23 +39,16 @@ class PiliSchame {
|
|||||||
final String path = value.path;
|
final String path = value.path;
|
||||||
|
|
||||||
if (scheme == 'bilibili') {
|
if (scheme == 'bilibili') {
|
||||||
// bilibili://root
|
|
||||||
if (host == 'root') {
|
if (host == 'root') {
|
||||||
Navigator.popUntil(
|
Navigator.popUntil(
|
||||||
Get.context!, (Route<dynamic> route) => route.isFirst);
|
Get.context!, (Route<dynamic> route) => route.isFirst);
|
||||||
}
|
} else if (host == 'space') {
|
||||||
|
|
||||||
// bilibili://space/{uid}
|
|
||||||
else if (host == 'space') {
|
|
||||||
final String mid = path.split('/').last;
|
final String mid = path.split('/').last;
|
||||||
Get.toNamed<dynamic>(
|
Get.toNamed<dynamic>(
|
||||||
'/member?mid=$mid',
|
'/member?mid=$mid',
|
||||||
arguments: <String, dynamic>{'face': null},
|
arguments: <String, dynamic>{'face': null},
|
||||||
);
|
);
|
||||||
}
|
} else if (host == 'video') {
|
||||||
|
|
||||||
// bilibili://video/{aid}
|
|
||||||
else if (host == 'video') {
|
|
||||||
String pathQuery = path.split('/').last;
|
String pathQuery = path.split('/').last;
|
||||||
final numericRegex = RegExp(r'^[0-9]+$');
|
final numericRegex = RegExp(r'^[0-9]+$');
|
||||||
if (numericRegex.hasMatch(pathQuery)) {
|
if (numericRegex.hasMatch(pathQuery)) {
|
||||||
@ -68,24 +62,16 @@ class PiliSchame {
|
|||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast('投稿匹配失败');
|
SmartDialog.showToast('投稿匹配失败');
|
||||||
}
|
}
|
||||||
}
|
} else if (host == 'live') {
|
||||||
|
|
||||||
// bilibili://live/{roomid}
|
|
||||||
else if (host == 'live') {
|
|
||||||
final String roomId = path.split('/').last;
|
final String roomId = path.split('/').last;
|
||||||
Get.toNamed<dynamic>('/liveRoom?roomid=$roomId',
|
Get.toNamed<dynamic>('/liveRoom?roomid=$roomId',
|
||||||
arguments: <String, String?>{'liveItem': null, 'heroTag': roomId});
|
arguments: <String, String?>{'liveItem': null, 'heroTag': roomId});
|
||||||
}
|
} else if (host == 'bangumi') {
|
||||||
|
|
||||||
// bilibili://bangumi/season/${ssid}
|
|
||||||
else if (host == 'bangumi') {
|
|
||||||
if (path.startsWith('/season')) {
|
if (path.startsWith('/season')) {
|
||||||
final String seasonId = path.split('/').last;
|
final String seasonId = path.split('/').last;
|
||||||
_bangumiPush(int.parse(seasonId));
|
_bangumiPush(int.parse(seasonId), null);
|
||||||
}
|
}
|
||||||
}
|
} else if (host == 'opus') {
|
||||||
// 专栏 bilibili://opus/detail/883089655985078289
|
|
||||||
else if (host == 'opus') {
|
|
||||||
if (path.startsWith('/detail')) {
|
if (path.startsWith('/detail')) {
|
||||||
var opusId = path.split('/').last;
|
var opusId = path.split('/').last;
|
||||||
Get.toNamed(
|
Get.toNamed(
|
||||||
@ -101,6 +87,9 @@ class PiliSchame {
|
|||||||
Get.toNamed('/searchResult', parameters: {'keyword': ''});
|
Get.toNamed('/searchResult', parameters: {'keyword': ''});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (scheme == 'https') {
|
||||||
|
_fullPathPush(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 投稿跳转
|
// 投稿跳转
|
||||||
@ -131,10 +120,10 @@ class PiliSchame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 番剧跳转
|
// 番剧跳转
|
||||||
static Future<void> _bangumiPush(int seasonId) async {
|
static Future<void> _bangumiPush(int? seasonId, int? epId) async {
|
||||||
SmartDialog.showLoading<dynamic>(msg: '获取中...');
|
SmartDialog.showLoading<dynamic>(msg: '获取中...');
|
||||||
try {
|
try {
|
||||||
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: null);
|
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId);
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
var bangumiDetail = result['data'];
|
var bangumiDetail = result['data'];
|
||||||
final int cid = bangumiDetail.episodes!.first.cid;
|
final int cid = bangumiDetail.episodes!.first.cid;
|
||||||
@ -151,6 +140,8 @@ class PiliSchame {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(result['msg']);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
SmartDialog.showToast('番剧获取失败:$e');
|
SmartDialog.showToast('番剧获取失败:$e');
|
||||||
@ -163,29 +154,67 @@ class PiliSchame {
|
|||||||
// final String scheme = value.scheme!;
|
// final String scheme = value.scheme!;
|
||||||
final String host = value.host!;
|
final String host = value.host!;
|
||||||
final String? path = value.path;
|
final String? path = value.path;
|
||||||
// Map<String, String> query = value.query!;
|
Map<String, String>? query = value.query;
|
||||||
if (host.startsWith('live.bilibili')) {
|
RegExp regExp = RegExp(r'^(www\.)?m?\.(bilibili\.com)$');
|
||||||
|
if (regExp.hasMatch(host)) {
|
||||||
|
print('bilibili.com');
|
||||||
|
} else if (host.contains('live')) {
|
||||||
int roomId = int.parse(path!.split('/').last);
|
int roomId = int.parse(path!.split('/').last);
|
||||||
// print('直播');
|
Get.toNamed(
|
||||||
Get.toNamed('/liveRoom?roomid=$roomId',
|
'/liveRoom?roomid=$roomId',
|
||||||
arguments: {'liveItem': null, 'heroTag': roomId.toString()});
|
arguments: {'liveItem': null, 'heroTag': roomId.toString()},
|
||||||
return;
|
);
|
||||||
}
|
} else if (host.contains('space')) {
|
||||||
if (host.startsWith('space.bilibili')) {
|
var mid = path!.split('/').last;
|
||||||
print('个人空间');
|
Get.toNamed('/member?mid=$mid', arguments: {'face': ''});
|
||||||
return;
|
return;
|
||||||
|
} else if (host == 'b23.tv') {
|
||||||
|
final String fullPath = 'https://$host$path';
|
||||||
|
final String redirectUrl = await UrlUtils.parseRedirectUrl(fullPath);
|
||||||
|
final String pathSegment = Uri.parse(redirectUrl).path;
|
||||||
|
final String lastPathSegment = pathSegment.split('/').last;
|
||||||
|
final RegExp avRegex = RegExp(r'^[aA][vV]\d+', caseSensitive: false);
|
||||||
|
if (avRegex.hasMatch(lastPathSegment)) {
|
||||||
|
final Map<String, dynamic> map =
|
||||||
|
IdUtils.matchAvorBv(input: lastPathSegment);
|
||||||
|
if (map.containsKey('AV')) {
|
||||||
|
_videoPush(map['AV']! as int, null);
|
||||||
|
} else if (map.containsKey('BV')) {
|
||||||
|
_videoPush(null, map['BV'] as String);
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast('投稿匹配失败');
|
||||||
|
}
|
||||||
|
} else if (lastPathSegment.startsWith('ep')) {
|
||||||
|
_handleEpisodePath(lastPathSegment, redirectUrl);
|
||||||
|
} else if (lastPathSegment.startsWith('ss')) {
|
||||||
|
_handleSeasonPath(lastPathSegment, redirectUrl);
|
||||||
|
} else if (lastPathSegment.startsWith('BV')) {
|
||||||
|
UrlUtils.matchUrlPush(
|
||||||
|
lastPathSegment,
|
||||||
|
'',
|
||||||
|
redirectUrl,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Get.toNamed(
|
||||||
|
'/webview',
|
||||||
|
parameters: {'url': redirectUrl, 'type': 'url', 'pageTitle': ''},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
final String area = path.split('/')[1];
|
final String area = path.split('/').last;
|
||||||
switch (area) {
|
switch (area) {
|
||||||
case 'bangumi':
|
case 'bangumi':
|
||||||
// print('番剧');
|
print('番剧');
|
||||||
final String seasonId = path.split('/').last;
|
if (area.startsWith('ep')) {
|
||||||
_bangumiPush(matchNum(seasonId).first);
|
_bangumiPush(null, matchNum(area).first);
|
||||||
|
} else if (area.startsWith('ss')) {
|
||||||
|
_bangumiPush(matchNum(area).first, null);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
// print('投稿');
|
print('投稿');
|
||||||
final Map<String, dynamic> map = IdUtils.matchAvorBv(input: path);
|
final Map<String, dynamic> map = IdUtils.matchAvorBv(input: path);
|
||||||
if (map.containsKey('AV')) {
|
if (map.containsKey('AV')) {
|
||||||
_videoPush(map['AV']! as int, null);
|
_videoPush(map['AV']! as int, null);
|
||||||
@ -200,6 +229,7 @@ class PiliSchame {
|
|||||||
break;
|
break;
|
||||||
case 'space':
|
case 'space':
|
||||||
print('个人空间');
|
print('个人空间');
|
||||||
|
Get.toNamed('/member?mid=$area', arguments: {'face': ''});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,4 +241,18 @@ class PiliSchame {
|
|||||||
|
|
||||||
return matches.map((Match match) => int.parse(match.group(0)!)).toList();
|
return matches.map((Match match) => int.parse(match.group(0)!)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _handleEpisodePath(String lastPathSegment, String redirectUrl) {
|
||||||
|
final String seasonId = _extractIdFromPath(lastPathSegment);
|
||||||
|
_bangumiPush(null, matchNum(seasonId).first);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _handleSeasonPath(String lastPathSegment, String redirectUrl) {
|
||||||
|
final String seasonId = _extractIdFromPath(lastPathSegment);
|
||||||
|
_bangumiPush(matchNum(seasonId).first, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String _extractIdFromPath(String lastPathSegment) {
|
||||||
|
return lastPathSegment.split('/').last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,9 @@ 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]{10}', caseSensitive: false);
|
final RegExp bvRegex =
|
||||||
final RegExp avRegex = RegExp(r'AV\d+', caseSensitive: false);
|
RegExp(r'[bB][vV][0-9A-Za-z]{10}', caseSensitive: false);
|
||||||
|
final RegExp avRegex = RegExp(r'[aA][vV]\d+', caseSensitive: false);
|
||||||
|
|
||||||
final Iterable<Match> bvMatches = bvRegex.allMatches(input);
|
final Iterable<Match> bvMatches = bvRegex.allMatches(input);
|
||||||
final Iterable<Match> avMatches = avRegex.allMatches(input);
|
final Iterable<Match> avMatches = avRegex.allMatches(input);
|
||||||
|
Reference in New Issue
Block a user