Merge branch 'main' into feature-liveRoomRender
This commit is contained in:
@ -5,6 +5,7 @@ import 'package:get/get.dart';
|
||||
import '../http/search.dart';
|
||||
import '../models/common/search_type.dart';
|
||||
import 'id_utils.dart';
|
||||
import 'url_utils.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
class PiliSchame {
|
||||
@ -38,23 +39,16 @@ class PiliSchame {
|
||||
final String path = value.path;
|
||||
|
||||
if (scheme == 'bilibili') {
|
||||
// bilibili://root
|
||||
if (host == 'root') {
|
||||
Navigator.popUntil(
|
||||
Get.context!, (Route<dynamic> route) => route.isFirst);
|
||||
}
|
||||
|
||||
// bilibili://space/{uid}
|
||||
else if (host == 'space') {
|
||||
} else if (host == 'space') {
|
||||
final String mid = path.split('/').last;
|
||||
Get.toNamed<dynamic>(
|
||||
'/member?mid=$mid',
|
||||
arguments: <String, dynamic>{'face': null},
|
||||
);
|
||||
}
|
||||
|
||||
// bilibili://video/{aid}
|
||||
else if (host == 'video') {
|
||||
} else if (host == 'video') {
|
||||
String pathQuery = path.split('/').last;
|
||||
final numericRegex = RegExp(r'^[0-9]+$');
|
||||
if (numericRegex.hasMatch(pathQuery)) {
|
||||
@ -68,24 +62,16 @@ class PiliSchame {
|
||||
} else {
|
||||
SmartDialog.showToast('投稿匹配失败');
|
||||
}
|
||||
}
|
||||
|
||||
// bilibili://live/{roomid}
|
||||
else if (host == 'live') {
|
||||
} else if (host == 'live') {
|
||||
final String roomId = path.split('/').last;
|
||||
Get.toNamed<dynamic>('/liveRoom?roomid=$roomId',
|
||||
arguments: <String, String?>{'liveItem': null, 'heroTag': roomId});
|
||||
}
|
||||
|
||||
// bilibili://bangumi/season/${ssid}
|
||||
else if (host == 'bangumi') {
|
||||
} else if (host == 'bangumi') {
|
||||
if (path.startsWith('/season')) {
|
||||
final String seasonId = path.split('/').last;
|
||||
_bangumiPush(int.parse(seasonId));
|
||||
_bangumiPush(int.parse(seasonId), null);
|
||||
}
|
||||
}
|
||||
// 专栏 bilibili://opus/detail/883089655985078289
|
||||
else if (host == 'opus') {
|
||||
} else if (host == 'opus') {
|
||||
if (path.startsWith('/detail')) {
|
||||
var opusId = path.split('/').last;
|
||||
Get.toNamed(
|
||||
@ -101,6 +87,9 @@ class PiliSchame {
|
||||
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: '获取中...');
|
||||
try {
|
||||
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: null);
|
||||
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId);
|
||||
if (result['status']) {
|
||||
var bangumiDetail = result['data'];
|
||||
final int cid = bangumiDetail.episodes!.first.cid;
|
||||
@ -151,6 +140,8 @@ class PiliSchame {
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('番剧获取失败:$e');
|
||||
@ -163,29 +154,67 @@ class PiliSchame {
|
||||
// final String scheme = value.scheme!;
|
||||
final String host = value.host!;
|
||||
final String? path = value.path;
|
||||
// Map<String, String> query = value.query!;
|
||||
if (host.startsWith('live.bilibili')) {
|
||||
Map<String, String>? query = value.query;
|
||||
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);
|
||||
// print('直播');
|
||||
Get.toNamed('/liveRoom?roomid=$roomId',
|
||||
arguments: {'liveItem': null, 'heroTag': roomId.toString()});
|
||||
return;
|
||||
}
|
||||
if (host.startsWith('space.bilibili')) {
|
||||
print('个人空间');
|
||||
Get.toNamed(
|
||||
'/liveRoom?roomid=$roomId',
|
||||
arguments: {'liveItem': null, 'heroTag': roomId.toString()},
|
||||
);
|
||||
} else if (host.contains('space')) {
|
||||
var mid = path!.split('/').last;
|
||||
Get.toNamed('/member?mid=$mid', arguments: {'face': ''});
|
||||
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) {
|
||||
final String area = path.split('/')[1];
|
||||
final String area = path.split('/').last;
|
||||
switch (area) {
|
||||
case 'bangumi':
|
||||
// print('番剧');
|
||||
final String seasonId = path.split('/').last;
|
||||
_bangumiPush(matchNum(seasonId).first);
|
||||
print('番剧');
|
||||
if (area.startsWith('ep')) {
|
||||
_bangumiPush(null, matchNum(area).first);
|
||||
} else if (area.startsWith('ss')) {
|
||||
_bangumiPush(matchNum(area).first, null);
|
||||
}
|
||||
break;
|
||||
case 'video':
|
||||
// print('投稿');
|
||||
print('投稿');
|
||||
final Map<String, dynamic> map = IdUtils.matchAvorBv(input: path);
|
||||
if (map.containsKey('AV')) {
|
||||
_videoPush(map['AV']! as int, null);
|
||||
@ -200,6 +229,7 @@ class PiliSchame {
|
||||
break;
|
||||
case 'space':
|
||||
print('个人空间');
|
||||
Get.toNamed('/member?mid=$area', arguments: {'face': ''});
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -211,4 +241,18 @@ class PiliSchame {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -99,10 +99,8 @@ class CacheManage {
|
||||
try {
|
||||
// 清除缓存 图片缓存
|
||||
await clearLibraryCache();
|
||||
Timer(const Duration(milliseconds: 500), () {
|
||||
SmartDialog.dismiss().then((res) {
|
||||
SmartDialog.showToast('清除完成');
|
||||
});
|
||||
SmartDialog.dismiss().then((res) {
|
||||
SmartDialog.showToast('清除完成');
|
||||
});
|
||||
} catch (err) {
|
||||
SmartDialog.dismiss();
|
||||
|
17
lib/utils/global_data.dart
Normal file
17
lib/utils/global_data.dart
Normal file
@ -0,0 +1,17 @@
|
||||
import '../models/common/index.dart';
|
||||
|
||||
class GlobalData {
|
||||
int imgQuality = 10;
|
||||
FullScreenGestureMode fullScreenGestureMode =
|
||||
FullScreenGestureMode.values.last;
|
||||
bool enablePlayerControlAnimation = true;
|
||||
|
||||
// 私有构造函数
|
||||
GlobalData._();
|
||||
|
||||
// 单例实例
|
||||
static final GlobalData _instance = GlobalData._();
|
||||
|
||||
// 获取全局实例
|
||||
factory GlobalData() => _instance;
|
||||
}
|
@ -68,8 +68,9 @@ class IdUtils {
|
||||
if (input == null || input.isEmpty) {
|
||||
return result;
|
||||
}
|
||||
final RegExp bvRegex = RegExp(r'BV[0-9A-Za-z]{10}', caseSensitive: false);
|
||||
final RegExp avRegex = RegExp(r'AV\d+', caseSensitive: false);
|
||||
final RegExp bvRegex =
|
||||
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> avMatches = avRegex.allMatches(input);
|
||||
|
@ -1,11 +1,11 @@
|
||||
// import 'package:hive/hive.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pilipala/models/model_owner.dart';
|
||||
import 'package:pilipala/models/search/hot.dart';
|
||||
import 'package:pilipala/models/user/info.dart';
|
||||
import '../models/common/gesture_mode.dart';
|
||||
import 'global_data.dart';
|
||||
|
||||
class GStrorage {
|
||||
static late final Box<dynamic> userInfo;
|
||||
@ -44,6 +44,13 @@ class GStrorage {
|
||||
);
|
||||
// 视频设置
|
||||
video = await Hive.openBox('video');
|
||||
GlobalData().imgQuality =
|
||||
setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); // 设置全局变量
|
||||
GlobalData().fullScreenGestureMode = FullScreenGestureMode.values[
|
||||
setting.get(SettingBoxKey.fullScreenGestureMode,
|
||||
defaultValue: FullScreenGestureMode.values.last.index) as int];
|
||||
GlobalData().enablePlayerControlAnimation = setting
|
||||
.get(SettingBoxKey.enablePlayerControlAnimation, defaultValue: true);
|
||||
}
|
||||
|
||||
static void regAdapter() {
|
||||
@ -94,11 +101,13 @@ class SettingBoxKey {
|
||||
enableCDN = 'enableCDN',
|
||||
autoPiP = 'autoPiP',
|
||||
enableAutoLongPressSpeed = 'enableAutoLongPressSpeed',
|
||||
enablePlayerControlAnimation = 'enablePlayerControlAnimation',
|
||||
|
||||
// youtube 双击快进快退
|
||||
enableQuickDouble = 'enableQuickDouble',
|
||||
enableShowDanmaku = 'enableShowDanmaku',
|
||||
enableBackgroundPlay = 'enableBackgroundPlay',
|
||||
fullScreenGestureMode = 'fullScreenGestureMode',
|
||||
|
||||
/// 隐私
|
||||
blackMidsList = 'blackMidsList',
|
||||
@ -122,7 +131,9 @@ class SettingBoxKey {
|
||||
enableWordRe = 'enableWordRe',
|
||||
enableSearchWord = 'enableSearchWord',
|
||||
enableSystemProxy = 'enableSystemProxy',
|
||||
enableAi = 'enableAi';
|
||||
enableAi = 'enableAi',
|
||||
defaultHomePage = 'defaultHomePage',
|
||||
enableRelatedVideo = 'enableRelatedVideo';
|
||||
|
||||
/// 外观
|
||||
static const String themeMode = 'themeMode',
|
||||
@ -172,6 +183,8 @@ class VideoBoxKey {
|
||||
videoSpeed = 'videoSpeed',
|
||||
// 播放顺序
|
||||
playRepeat = 'playRepeat',
|
||||
// 系统预设倍速
|
||||
playSpeedSystem = 'playSpeedSystem',
|
||||
// 默认倍速
|
||||
playSpeedDefault = 'playSpeedDefault',
|
||||
// 默认长按倍速
|
||||
|
@ -14,19 +14,23 @@ class UrlUtils {
|
||||
dio.options.validateStatus = (status) {
|
||||
return status == 200 || status == 301 || status == 302;
|
||||
};
|
||||
final response = await dio.get(url);
|
||||
if (response.statusCode == 302) {
|
||||
redirectUrl = response.headers['location']?.first as String;
|
||||
if (redirectUrl.endsWith('/')) {
|
||||
redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1);
|
||||
}
|
||||
} else {
|
||||
if (url.endsWith('/')) {
|
||||
url = url.substring(0, url.length - 1);
|
||||
try {
|
||||
final response = await dio.get(url);
|
||||
if (response.statusCode == 302) {
|
||||
redirectUrl = response.headers['location']?.first as String;
|
||||
if (redirectUrl.endsWith('/')) {
|
||||
redirectUrl = redirectUrl.substring(0, redirectUrl.length - 1);
|
||||
}
|
||||
} else {
|
||||
if (url.endsWith('/')) {
|
||||
url = url.substring(0, url.length - 1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
return redirectUrl;
|
||||
} catch (err) {
|
||||
return url;
|
||||
}
|
||||
return redirectUrl;
|
||||
}
|
||||
|
||||
// 匹配url路由跳转
|
||||
|
@ -50,6 +50,9 @@ class Utils {
|
||||
return time;
|
||||
}
|
||||
if (time < 3600) {
|
||||
if (time == 0) {
|
||||
return time;
|
||||
}
|
||||
final int minute = time ~/ 60;
|
||||
final double res = time / 60;
|
||||
if (minute != res) {
|
||||
@ -87,6 +90,9 @@ class Utils {
|
||||
|
||||
// 时间显示,刚刚,x分钟前
|
||||
static String dateFormat(timeStamp, {formatType = 'list'}) {
|
||||
if (timeStamp == 0 || timeStamp == null || timeStamp == '') {
|
||||
return '';
|
||||
}
|
||||
// 当前时间
|
||||
int time = (DateTime.now().millisecondsSinceEpoch / 1000).round();
|
||||
// 对比
|
||||
@ -103,6 +109,7 @@ class Utils {
|
||||
toInt: false,
|
||||
formatType: formatType);
|
||||
}
|
||||
print('distance: $distance');
|
||||
if (distance <= 60) {
|
||||
return '刚刚';
|
||||
} else if (distance <= 3600) {
|
||||
@ -236,6 +243,10 @@ class Utils {
|
||||
SmartDialog.dismiss();
|
||||
var currentInfo = await PackageInfo.fromPlatform();
|
||||
var result = await Request().get(Api.latestApp, extra: {'ua': 'mob'});
|
||||
if (result.data == null || result.data.isEmpty) {
|
||||
SmartDialog.showToast('获取远程版本失败,请检查网络');
|
||||
return false;
|
||||
}
|
||||
LatestDataModel data = LatestDataModel.fromJson(result.data);
|
||||
bool isUpdate = Utils.needUpdate(currentInfo.version, data.tagName!);
|
||||
if (isUpdate) {
|
||||
@ -344,9 +355,8 @@ class Utils {
|
||||
}
|
||||
|
||||
static List<int> generateRandomBytes(int minLength, int maxLength) {
|
||||
return List<int>.generate(
|
||||
random.nextInt(maxLength-minLength+1), (_) => random.nextInt(0x60) + 0x20
|
||||
);
|
||||
return List<int>.generate(random.nextInt(maxLength - minLength + 1),
|
||||
(_) => random.nextInt(0x60) + 0x20);
|
||||
}
|
||||
|
||||
static String base64EncodeRandomString(int minLength, int maxLength) {
|
||||
|
Reference in New Issue
Block a user