opt: RoutePush bangumi
This commit is contained in:
@ -2,6 +2,7 @@ import 'package:appscheme/appscheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/utils/route_push.dart';
|
||||
import '../http/search.dart';
|
||||
import '../models/common/search_type.dart';
|
||||
import 'id_utils.dart';
|
||||
@ -68,7 +69,7 @@ class PiliSchame {
|
||||
} else if (host == 'bangumi') {
|
||||
if (path.startsWith('/season')) {
|
||||
final String seasonId = path.split('/').last;
|
||||
_bangumiPush(int.parse(seasonId), null);
|
||||
RoutePush.bangumiPush(int.parse(seasonId), null);
|
||||
}
|
||||
} else if (host == 'opus') {
|
||||
if (path.startsWith('/detail')) {
|
||||
@ -126,35 +127,6 @@ class PiliSchame {
|
||||
}
|
||||
}
|
||||
|
||||
// 番剧跳转
|
||||
static Future<void> _bangumiPush(int? seasonId, int? epId) async {
|
||||
SmartDialog.showLoading<dynamic>(msg: '获取中...');
|
||||
try {
|
||||
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId);
|
||||
if (result['status']) {
|
||||
var bangumiDetail = result['data'];
|
||||
final int cid = bangumiDetail.episodes!.first.cid;
|
||||
final String bvid = IdUtils.av2bv(bangumiDetail.episodes!.first.aid);
|
||||
final 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: <String, dynamic>{
|
||||
'pic': bangumiDetail.cover,
|
||||
'heroTag': heroTag,
|
||||
'videoType': SearchType.media_bangumi,
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('番剧获取失败:$e');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _fullPathPush(SchemeEntity value) async {
|
||||
// https://m.bilibili.com/bangumi/play/ss39708
|
||||
// https | m.bilibili.com | /bangumi/play/ss39708
|
||||
@ -177,10 +149,10 @@ class PiliSchame {
|
||||
}
|
||||
if (path.startsWith('/bangumi')) {
|
||||
if (lastPathSegment.contains('ss')) {
|
||||
_bangumiPush(matchNum(lastPathSegment).first, null);
|
||||
RoutePush.bangumiPush(matchNum(lastPathSegment).first, null);
|
||||
}
|
||||
if (lastPathSegment.contains('ep')) {
|
||||
_bangumiPush(null, matchNum(lastPathSegment).first);
|
||||
RoutePush.bangumiPush(null, matchNum(lastPathSegment).first);
|
||||
}
|
||||
}
|
||||
} else if (host.contains('live')) {
|
||||
@ -233,9 +205,9 @@ class PiliSchame {
|
||||
case 'bangumi':
|
||||
print('番剧');
|
||||
if (area.startsWith('ep')) {
|
||||
_bangumiPush(null, matchNum(area).first);
|
||||
RoutePush.bangumiPush(null, matchNum(area).first);
|
||||
} else if (area.startsWith('ss')) {
|
||||
_bangumiPush(matchNum(area).first, null);
|
||||
RoutePush.bangumiPush(matchNum(area).first, null);
|
||||
}
|
||||
break;
|
||||
case 'video':
|
||||
@ -276,12 +248,12 @@ class PiliSchame {
|
||||
|
||||
static void _handleEpisodePath(String lastPathSegment, String redirectUrl) {
|
||||
final String seasonId = _extractIdFromPath(lastPathSegment);
|
||||
_bangumiPush(null, matchNum(seasonId).first);
|
||||
RoutePush.bangumiPush(null, matchNum(seasonId).first);
|
||||
}
|
||||
|
||||
static void _handleSeasonPath(String lastPathSegment, String redirectUrl) {
|
||||
final String seasonId = _extractIdFromPath(lastPathSegment);
|
||||
_bangumiPush(matchNum(seasonId).first, null);
|
||||
RoutePush.bangumiPush(matchNum(seasonId).first, null);
|
||||
}
|
||||
|
||||
static String _extractIdFromPath(String lastPathSegment) {
|
||||
|
||||
44
lib/utils/route_push.dart
Normal file
44
lib/utils/route_push.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:pilipala/http/search.dart';
|
||||
import 'package:pilipala/models/bangumi/info.dart';
|
||||
import 'package:pilipala/models/common/search_type.dart';
|
||||
import 'package:pilipala/utils/utils.dart';
|
||||
|
||||
class RoutePush {
|
||||
// 番剧跳转
|
||||
static Future<void> bangumiPush(int? seasonId, int? epId,
|
||||
{String? heroTag}) async {
|
||||
SmartDialog.showLoading<dynamic>(msg: '获取中...');
|
||||
try {
|
||||
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId);
|
||||
await SmartDialog.dismiss();
|
||||
if (result['status']) {
|
||||
if (result['data'].episodes.isEmpty) {
|
||||
SmartDialog.showToast('资源获取失败');
|
||||
return;
|
||||
}
|
||||
final BangumiInfoModel bangumiDetail = result['data'];
|
||||
final EpisodeItem episode = bangumiDetail.episodes!.first;
|
||||
final int epId = episode.id!;
|
||||
final int cid = episode.cid!;
|
||||
final String bvid = episode.bvid!;
|
||||
final String cover = episode.cover!;
|
||||
final Map arguments = <String, dynamic>{
|
||||
'pic': cover,
|
||||
'videoType': SearchType.media_bangumi,
|
||||
// 'bangumiItem': bangumiDetail,
|
||||
};
|
||||
arguments['heroTag'] = heroTag ?? Utils.makeHeroTag(cid);
|
||||
Get.toNamed(
|
||||
'/video?bvid=$bvid&cid=$cid&epId=$epId',
|
||||
arguments: arguments,
|
||||
);
|
||||
} else {
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('番剧获取失败:$e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user