From 08e4e6476468884230ccde47e8cb419af6d8ee7c Mon Sep 17 00:00:00 2001 From: guozhigq Date: Thu, 31 Aug 2023 11:45:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=95=AA=E5=89=A7=E3=80=81=E6=8A=95?= =?UTF-8?q?=E7=A8=BF=E3=80=81=E7=9B=B4=E6=92=AD=E5=A4=96=E9=93=BE=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E8=87=B3Pili?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/app_scheme.dart | 147 +++++++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 34 deletions(-) diff --git a/lib/utils/app_scheme.dart b/lib/utils/app_scheme.dart index 3736b5b5..5ac64a97 100644 --- a/lib/utils/app_scheme.dart +++ b/lib/utils/app_scheme.dart @@ -17,9 +17,11 @@ class PiliSchame { _routePush(value); } - /// + /// 完整链接进入 b23.无效 appScheme.getLatestScheme().then((value) { - if (value != null) {} + if (value != null) { + _fullPathPush(value); + } }); /// 注册从外部打开的Scheme监听信息 # @@ -55,13 +57,7 @@ class PiliSchame { else if (host == 'video') { var pathQuery = path.split('/').last; int aid = int.parse(pathQuery); - String bvid = IdUtils.av2bv(aid); - int cid = await SearchHttp.ab2c(bvid: bvid); - String heroTag = Utils.makeHeroTag(aid); - Get.toNamed('/video?bvid=$bvid&cid=$cid', arguments: { - 'pic': null, - 'heroTag': heroTag, - }); + _videoPush(aid, null); } // bilibili://live/{roomid} @@ -74,33 +70,116 @@ class PiliSchame { // bilibili://bangumi/season/${ssid} else if (host == 'bangumi') { if (path.startsWith('/season')) { - SmartDialog.showLoading(msg: '获取中...'); - try { - var seasonId = path.split('/').last; - var result = await SearchHttp.bangumiInfo( - seasonId: int.parse(seasonId), epId: null); - if (result['status']) { - var bangumiDetail = result['data']; - int cid = bangumiDetail.episodes!.first.cid; - String bvid = IdUtils.av2bv(bangumiDetail.episodes!.first.aid); - String heroTag = Utils.makeHeroTag(cid); - var epId = bangumiDetail.episodes!.first.id; - SmartDialog.dismiss().then( - (e) => Get.toNamed( - '/video?bvid=$bvid&cid=$cid&epId=$epId', - arguments: { - 'pic': bangumiDetail.cover, - 'heroTag': heroTag, - 'videoType': SearchType.media_bangumi, - }, - ), - ); - } - } catch (e) { - SmartDialog.showToast('失败:${e.toString()}'); - } + var seasonId = path.split('/').last; + _bangumiPush(int.parse(seasonId)); } } } } + + // 投稿跳转 + static void _videoPush(int? aidVal, String? bvidVal) async { + SmartDialog.showLoading(msg: '获取中...'); + try { + int? aid = aidVal; + String? bvid = bvidVal; + 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']) { + var bangumiDetail = result['data']; + int cid = bangumiDetail.episodes!.first.cid; + String bvid = IdUtils.av2bv(bangumiDetail.episodes!.first.aid); + String heroTag = Utils.makeHeroTag(cid); + var epId = bangumiDetail.episodes!.first.id; + SmartDialog.dismiss().then( + (e) => Get.toNamed( + '/video?bvid=$bvid&cid=$cid&epId=$epId', + arguments: { + 'pic': bangumiDetail.cover, + 'heroTag': heroTag, + 'videoType': SearchType.media_bangumi, + }, + ), + ); + } + } catch (e) { + 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 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 matchNum(String str) { + RegExp regExp = RegExp(r'\d+'); + Iterable matches = regExp.allMatches(str); + + return matches.map((match) => int.parse(match.group(0)!)).toList(); + } }