feat: 番剧、投稿、直播外链跳转至Pili

This commit is contained in:
guozhigq
2023-08-31 11:45:30 +08:00
parent f6c7143d2d
commit 08e4e64764

View File

@ -17,9 +17,11 @@ class PiliSchame {
_routePush(value); _routePush(value);
} }
/// /// 完整链接进入 b23.无效
appScheme.getLatestScheme().then((value) { appScheme.getLatestScheme().then((value) {
if (value != null) {} if (value != null) {
_fullPathPush(value);
}
}); });
/// 注册从外部打开的Scheme监听信息 # /// 注册从外部打开的Scheme监听信息 #
@ -55,13 +57,7 @@ class PiliSchame {
else if (host == 'video') { else if (host == 'video') {
var pathQuery = path.split('/').last; var pathQuery = path.split('/').last;
int aid = int.parse(pathQuery); int aid = int.parse(pathQuery);
String bvid = IdUtils.av2bv(aid); _videoPush(aid, null);
int cid = await SearchHttp.ab2c(bvid: bvid);
String heroTag = Utils.makeHeroTag(aid);
Get.toNamed('/video?bvid=$bvid&cid=$cid', arguments: {
'pic': null,
'heroTag': heroTag,
});
} }
// bilibili://live/{roomid} // bilibili://live/{roomid}
@ -74,11 +70,43 @@ class PiliSchame {
// bilibili://bangumi/season/${ssid} // bilibili://bangumi/season/${ssid}
else if (host == 'bangumi') { else if (host == 'bangumi') {
if (path.startsWith('/season')) { if (path.startsWith('/season')) {
var seasonId = path.split('/').last;
_bangumiPush(int.parse(seasonId));
}
}
}
}
// 投稿跳转
static void _videoPush(int? aidVal, String? bvidVal) async {
SmartDialog.showLoading(msg: '获取中...'); SmartDialog.showLoading(msg: '获取中...');
try { try {
var seasonId = path.split('/').last; int? aid = aidVal;
var result = await SearchHttp.bangumiInfo( String? bvid = bvidVal;
seasonId: int.parse(seasonId), epId: null); if (aidVal == null) {
aid = IdUtils.bv2av(bvidVal!);
}
if (bvidVal == null) {
bvid = IdUtils.av2bv(aidVal!);
}
int cid = await SearchHttp.ab2c(bvid: bvidVal, aid: aidVal);
String heroTag = Utils.makeHeroTag(aid);
SmartDialog.dismiss().then(
(e) => Get.toNamed('/video?bvid=$bvid&cid=$cid', arguments: {
'pic': null,
'heroTag': heroTag,
}),
);
} catch (e) {
SmartDialog.showToast('video获取失败${e.toString()}');
}
}
// 番剧跳转
static void _bangumiPush(int seasonId) async {
SmartDialog.showLoading(msg: '获取中...');
try {
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: null);
if (result['status']) { if (result['status']) {
var bangumiDetail = result['data']; var bangumiDetail = result['data'];
int cid = bangumiDetail.episodes!.first.cid; int cid = bangumiDetail.episodes!.first.cid;
@ -97,10 +125,61 @@ class PiliSchame {
); );
} }
} catch (e) { } catch (e) {
SmartDialog.showToast('失败:${e.toString()}'); SmartDialog.showToast('番剧获取失败:${e.toString()}');
} }
}
static void _fullPathPush(value) async {
// https://m.bilibili.com/bangumi/play/ss39708
// https | m.bilibili.com | /bangumi/play/ss39708
String scheme = value.scheme!;
String host = value.host!;
String? path = value.path;
// Map<String, String> query = value.query!;
if (host.startsWith('live.bilibili')) {
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('个人空间');
return;
}
if (path != null) {
String area = path.split('/')[1];
switch (area) {
case 'bangumi':
// print('番剧');
String seasonId = path.split('/').last;
_bangumiPush(matchNum(seasonId).first);
break;
case 'video':
// print('投稿');
Map map = IdUtils.matchAvorBv(input: path);
if (map.containsKey('AV')) {
_videoPush(map['AV'], null);
} else if (map.containsKey('BV')) {
_videoPush(null, map['BV']);
} else {
SmartDialog.showToast('投稿匹配失败');
}
break;
case 'read':
print('专栏');
break;
case 'space':
print('个人空间');
break;
} }
} }
} }
static List<int> matchNum(String str) {
RegExp regExp = RegExp(r'\d+');
Iterable<Match> matches = regExp.allMatches(str);
return matches.map((match) => int.parse(match.group(0)!)).toList();
} }
} }