mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-26 02:58:39 +00:00
@@ -17,6 +17,7 @@ class PiliScheme {
|
||||
static late AppLinks appLinks;
|
||||
static StreamSubscription? listener;
|
||||
static final uriDigitRegExp = RegExp(r'/(\d+)');
|
||||
static final _prefixRegex = RegExp(r'^\S+://');
|
||||
|
||||
static void init() {
|
||||
// Register our protocol only on Windows platform
|
||||
@@ -40,7 +41,7 @@ class PiliScheme {
|
||||
try {
|
||||
if (url.startsWith('//')) {
|
||||
url = 'https:$url';
|
||||
} else if (!RegExp(r'^\S+://').hasMatch(url)) {
|
||||
} else if (!_prefixRegex.hasMatch(url)) {
|
||||
url = 'https://$url';
|
||||
}
|
||||
return routePush(
|
||||
@@ -160,9 +161,7 @@ class PiliScheme {
|
||||
// to video
|
||||
// bilibili://video/12345678?page=0&h5awaken=random
|
||||
String? aid = uriDigitRegExp.firstMatch(path)?.group(1);
|
||||
String? bvid = RegExp(r'/(BV[a-z\d]{10})', caseSensitive: false)
|
||||
.firstMatch(path)
|
||||
?.group(1);
|
||||
String? bvid = IdUtils.bvRegex.firstMatch(path)?.group(0);
|
||||
if (aid != null || bvid != null) {
|
||||
if (queryParameters['cid'] != null) {
|
||||
bvid ??= IdUtils.av2bv(int.parse(aid!));
|
||||
@@ -349,7 +348,7 @@ class PiliScheme {
|
||||
// bilibili://following/detail/832703053858603029 (dynId)
|
||||
// bilibili://following/detail/12345678?comment_root_id=654321\u0026comment_on=1
|
||||
String? cvid = RegExp(r'^/detail/cv(\d+)', caseSensitive: false)
|
||||
.firstMatch(path)
|
||||
.matchAsPrefix(path)
|
||||
?.group(1);
|
||||
if (cvid != null) {
|
||||
PageUtils.toDupNamed(
|
||||
@@ -473,12 +472,8 @@ class PiliScheme {
|
||||
parameters: parameters,
|
||||
);
|
||||
default:
|
||||
String? aid = RegExp(r'^av(\d+)', caseSensitive: false)
|
||||
.firstMatch(path)
|
||||
?.group(1);
|
||||
String? bvid = RegExp(r'^BV[a-z\d]{10}', caseSensitive: false)
|
||||
.firstMatch(path)
|
||||
?.group(0);
|
||||
String? aid = IdUtils.avRegexExact.matchAsPrefix(path)?.group(1);
|
||||
String? bvid = IdUtils.bvRegexExact.matchAsPrefix(path)?.group(0);
|
||||
if (aid != null || bvid != null) {
|
||||
videoPush(
|
||||
aid != null ? int.parse(aid) : null,
|
||||
@@ -621,9 +616,7 @@ class PiliScheme {
|
||||
.firstMatch(path)
|
||||
?.group(1);
|
||||
String? bvid = uri.queryParameters['bvid'] ??
|
||||
RegExp(r'/(BV[a-z\d]{10})', caseSensitive: false)
|
||||
.firstMatch(path)
|
||||
?.group(1);
|
||||
IdUtils.bvRegex.firstMatch(path)?.group(0);
|
||||
if (bvid != null) {
|
||||
if (mediaId != null) {
|
||||
final int? cid = await SearchHttp.ab2c(bvid: bvid);
|
||||
@@ -651,15 +644,11 @@ class PiliScheme {
|
||||
case 'bangumi':
|
||||
// www.bilibili.com/bangumi/play/ep{eid}?start_progress={offset}&thumb_up_dm_id={dmid}
|
||||
if (kDebugMode) debugPrint('番剧');
|
||||
String? id = RegExp(r'(ss|ep)\d+').firstMatch(path)?.group(0);
|
||||
if (id != null) {
|
||||
bool isSeason = id.startsWith('ss');
|
||||
id = id.substring(2);
|
||||
PageUtils.viewPgc(
|
||||
seasonId: isSeason ? id : null,
|
||||
epId: isSeason ? null : id,
|
||||
progress: uri.queryParameters['start_progress'],
|
||||
);
|
||||
bool hasMatch = PageUtils.viewPgcFromUri(
|
||||
path,
|
||||
progress: uri.queryParameters['start_progress'],
|
||||
);
|
||||
if (hasMatch) {
|
||||
return true;
|
||||
}
|
||||
launchURL();
|
||||
|
||||
@@ -15,8 +15,12 @@ class IdUtils {
|
||||
'FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf';
|
||||
static final invData = {for (var (i, c) in data.codeUnits.indexed) c: i};
|
||||
|
||||
static final bvRegex = RegExp(r'bv(1[0-9A-Za-z]{9})', caseSensitive: false);
|
||||
static final bvRegex = RegExp(r'bv[0-9a-zA-Z]{10}', caseSensitive: false);
|
||||
static final bvRegexExact =
|
||||
RegExp(r'^bv[0-9a-zA-Z]{10}$', caseSensitive: false);
|
||||
static final avRegex = RegExp(r'av(\d+)', caseSensitive: false);
|
||||
static final avRegexExact = RegExp(r'^av(\d+)$', caseSensitive: false);
|
||||
static final digitOnlyRegExp = RegExp(r'^\d+$');
|
||||
|
||||
static void swap<T>(List<T> list, int idx1, int idx2) {
|
||||
final idx1Value = list[idx1];
|
||||
@@ -58,12 +62,12 @@ class IdUtils {
|
||||
if (input == null || input.isEmpty) {
|
||||
return result;
|
||||
}
|
||||
String? bvid = bvRegex.firstMatch(input)?.group(1);
|
||||
String? bvid = bvRegex.firstMatch(input)?.group(0);
|
||||
|
||||
late String? aid = avRegex.firstMatch(input)?.group(1);
|
||||
|
||||
if (bvid != null) {
|
||||
result['BV'] = 'BV$bvid';
|
||||
result['BV'] = bvid;
|
||||
} else if (aid != null) {
|
||||
result['AV'] = int.parse(aid);
|
||||
}
|
||||
|
||||
@@ -232,14 +232,13 @@ class ImageUtil {
|
||||
}
|
||||
}
|
||||
|
||||
static final regExp =
|
||||
static final _thumbRegex =
|
||||
RegExp(r'(@(\d+[a-z]_?)*)(\..*)?$', caseSensitive: false);
|
||||
|
||||
static String thumbnailUrl(String? src, [int? quality]) {
|
||||
if (src != null && quality != 100) {
|
||||
bool hasMatch = false;
|
||||
src = src.splitMapJoin(
|
||||
regExp,
|
||||
_thumbRegex,
|
||||
onMatch: (Match match) {
|
||||
hasMatch = true;
|
||||
String suffix = match.group(3) ?? '.webp';
|
||||
|
||||
@@ -102,9 +102,7 @@ class PageUtils {
|
||||
autofocus: true,
|
||||
onChanged: (value) => duration = value,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'\d+')),
|
||||
],
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
decoration: const InputDecoration(suffixText: 'min'),
|
||||
),
|
||||
actions: [
|
||||
@@ -414,24 +412,13 @@ class PageUtils {
|
||||
|
||||
/// 专栏文章查看
|
||||
case 'DYNAMIC_TYPE_ARTICLE':
|
||||
String? url = item.modules.moduleDynamic?.major?.opus?.jumpUrl;
|
||||
if (url != null) {
|
||||
if (url.contains('opus') || url.contains('read')) {
|
||||
RegExp digitRegExp = RegExp(r'\d+');
|
||||
Iterable<Match> matches = digitRegExp.allMatches(url);
|
||||
String number = matches.first.group(0)!;
|
||||
toDupNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': number,
|
||||
'type': url.split('//').last.split('/')[1],
|
||||
},
|
||||
);
|
||||
} else {
|
||||
handleWebview('https:$url');
|
||||
}
|
||||
}
|
||||
|
||||
toDupNamed(
|
||||
'/articlePage',
|
||||
parameters: {
|
||||
'id': item.idStr,
|
||||
'type': 'opus',
|
||||
},
|
||||
);
|
||||
break;
|
||||
case 'DYNAMIC_TYPE_PGC':
|
||||
if (kDebugMode) debugPrint('番剧');
|
||||
@@ -675,14 +662,16 @@ class PageUtils {
|
||||
}
|
||||
}
|
||||
|
||||
static bool viewPgcFromUri(String uri) {
|
||||
String? id = RegExp(r'(ep|ss)\d+').firstMatch(uri)?.group(0);
|
||||
if (id != null) {
|
||||
bool isSeason = id.startsWith('ss');
|
||||
id = id.substring(2);
|
||||
static final _pgcRegex = RegExp(r'(ep|ss)(\d+)');
|
||||
static bool viewPgcFromUri(String uri, {String? progress}) {
|
||||
RegExpMatch? match = _pgcRegex.firstMatch(uri);
|
||||
if (match != null) {
|
||||
bool isSeason = match.group(1) == 'ss';
|
||||
String id = match.group(2)!;
|
||||
viewPgc(
|
||||
seasonId: isSeason ? id : null,
|
||||
epId: isSeason ? null : id,
|
||||
progress: progress,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ class Utils {
|
||||
return absolutePaths.join(':');
|
||||
}
|
||||
|
||||
static final numericRegex = RegExp(r'^[\d\.]+$');
|
||||
static bool isStringNumeric(String str) {
|
||||
RegExp numericRegex = RegExp(r'^[\d\.]+$');
|
||||
return numericRegex.hasMatch(str);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user