mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-30 23:58:13 +08:00
feat: show aiConclusion (#1698)
This commit is contained in:
committed by
GitHub
parent
ccb61415f5
commit
1a9d8e35ba
@@ -6,6 +6,8 @@ import 'package:PiliPlus/models/model_video.dart';
|
|||||||
import 'package:PiliPlus/models_new/space/space_archive/item.dart';
|
import 'package:PiliPlus/models_new/space/space_archive/item.dart';
|
||||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||||
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
|
import 'package:PiliPlus/pages/search/widgets/search_text.dart';
|
||||||
|
import 'package:PiliPlus/pages/video/ai_conclusion/view.dart';
|
||||||
|
import 'package:PiliPlus/pages/video/introduction/ugc/controller.dart';
|
||||||
import 'package:PiliPlus/utils/accounts.dart';
|
import 'package:PiliPlus/utils/accounts.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -14,11 +16,10 @@ import 'package:get/get.dart';
|
|||||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||||
|
|
||||||
class VideoCustomAction {
|
class VideoCustomAction {
|
||||||
String title;
|
final String title;
|
||||||
String value;
|
final Widget icon;
|
||||||
Widget icon;
|
final VoidCallback? onTap;
|
||||||
VoidCallback? onTap;
|
const VideoCustomAction(this.title, this.icon, this.onTap);
|
||||||
VideoCustomAction(this.title, this.value, this.icon, this.onTap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class VideoCustomActions {
|
class VideoCustomActions {
|
||||||
@@ -32,7 +33,6 @@ class VideoCustomActions {
|
|||||||
if (videoItem.bvid?.isNotEmpty == true) ...[
|
if (videoItem.bvid?.isNotEmpty == true) ...[
|
||||||
VideoCustomAction(
|
VideoCustomAction(
|
||||||
videoItem.bvid!,
|
videoItem.bvid!,
|
||||||
'copy',
|
|
||||||
const Stack(
|
const Stack(
|
||||||
clipBehavior: Clip.none,
|
clipBehavior: Clip.none,
|
||||||
children: [
|
children: [
|
||||||
@@ -44,25 +44,72 @@ class VideoCustomActions {
|
|||||||
),
|
),
|
||||||
VideoCustomAction(
|
VideoCustomAction(
|
||||||
'稍后再看',
|
'稍后再看',
|
||||||
'pause',
|
|
||||||
const Icon(MdiIcons.clockTimeEightOutline, size: 16),
|
const Icon(MdiIcons.clockTimeEightOutline, size: 16),
|
||||||
() async {
|
() async {
|
||||||
var res = await UserHttp.toViewLater(bvid: videoItem.bvid);
|
var res = await UserHttp.toViewLater(bvid: videoItem.bvid);
|
||||||
SmartDialog.showToast(res['msg']);
|
SmartDialog.showToast(res['msg']);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
VideoCustomAction(
|
||||||
|
'AI总结',
|
||||||
|
const Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.circle_outlined, size: 16),
|
||||||
|
ExcludeSemantics(
|
||||||
|
child: Text(
|
||||||
|
'AI',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 8,
|
||||||
|
height: 1,
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
|
),
|
||||||
|
textScaler: TextScaler.noScaling,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
() async {
|
||||||
|
final res = await UgcIntroController.getAiConclusion(
|
||||||
|
videoItem.bvid!,
|
||||||
|
videoItem.cid!,
|
||||||
|
videoItem.owner.mid,
|
||||||
|
);
|
||||||
|
if (res != null && context.mounted) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return Dialog(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 420),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 14),
|
||||||
|
child: AiConclusionPanel.buildContent(
|
||||||
|
context,
|
||||||
|
theme,
|
||||||
|
res,
|
||||||
|
tap: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
if (videoItem is! SpaceArchiveItem)
|
if (videoItem is! SpaceArchiveItem)
|
||||||
VideoCustomAction(
|
VideoCustomAction(
|
||||||
'访问:${videoItem.owner.name}',
|
'访问:${videoItem.owner.name}',
|
||||||
'visit',
|
|
||||||
const Icon(MdiIcons.accountCircleOutline, size: 16),
|
const Icon(MdiIcons.accountCircleOutline, size: 16),
|
||||||
() => Get.toNamed('/member?mid=${videoItem.owner.mid}'),
|
() => Get.toNamed('/member?mid=${videoItem.owner.mid}'),
|
||||||
),
|
),
|
||||||
if (videoItem is! SpaceArchiveItem)
|
if (videoItem is! SpaceArchiveItem)
|
||||||
VideoCustomAction(
|
VideoCustomAction(
|
||||||
'不感兴趣',
|
'不感兴趣',
|
||||||
'dislike',
|
|
||||||
const Icon(MdiIcons.thumbDownOutline, size: 16),
|
const Icon(MdiIcons.thumbDownOutline, size: 16),
|
||||||
() {
|
() {
|
||||||
String? accessKey = Accounts.get(AccountType.recommend).accessKey;
|
String? accessKey = Accounts.get(AccountType.recommend).accessKey;
|
||||||
@@ -229,7 +276,6 @@ class VideoCustomActions {
|
|||||||
if (videoItem is! SpaceArchiveItem)
|
if (videoItem is! SpaceArchiveItem)
|
||||||
VideoCustomAction(
|
VideoCustomAction(
|
||||||
'拉黑:${videoItem.owner.name}',
|
'拉黑:${videoItem.owner.name}',
|
||||||
'block',
|
|
||||||
const Icon(MdiIcons.cancel, size: 16),
|
const Icon(MdiIcons.cancel, size: 16),
|
||||||
() => showDialog(
|
() => showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -272,7 +318,6 @@ class VideoCustomActions {
|
|||||||
),
|
),
|
||||||
VideoCustomAction(
|
VideoCustomAction(
|
||||||
"${MineController.anonymity.value ? '退出' : '进入'}无痕模式",
|
"${MineController.anonymity.value ? '退出' : '进入'}无痕模式",
|
||||||
'anonymity',
|
|
||||||
MineController.anonymity.value
|
MineController.anonymity.value
|
||||||
? const Icon(MdiIcons.incognitoOff, size: 16)
|
? const Icon(MdiIcons.incognitoOff, size: 16)
|
||||||
: const Icon(MdiIcons.incognito, size: 16),
|
: const Icon(MdiIcons.incognito, size: 16),
|
||||||
@@ -312,11 +357,9 @@ class VideoPopupMenu extends StatelessWidget {
|
|||||||
size: iconSize,
|
size: iconSize,
|
||||||
),
|
),
|
||||||
position: PopupMenuPosition.under,
|
position: PopupMenuPosition.under,
|
||||||
onSelected: (String type) {},
|
|
||||||
itemBuilder: (BuildContext context) =>
|
itemBuilder: (BuildContext context) =>
|
||||||
VideoCustomActions(videoItem, context, onRemove).actions.map((e) {
|
VideoCustomActions(videoItem, context, onRemove).actions.map((e) {
|
||||||
return PopupMenuItem<String>(
|
return PopupMenuItem<Never>(
|
||||||
value: e.value,
|
|
||||||
height: menuItemHeight,
|
height: menuItemHeight,
|
||||||
onTap: e.onTap,
|
onTap: e.onTap,
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|||||||
@@ -18,6 +18,118 @@ class AiConclusionPanel extends CommonSlidePage {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
State<AiConclusionPanel> createState() => _AiDetailState();
|
State<AiConclusionPanel> createState() => _AiDetailState();
|
||||||
|
|
||||||
|
static Widget buildContent(
|
||||||
|
BuildContext context,
|
||||||
|
ThemeData theme,
|
||||||
|
AiConclusionResult res, {
|
||||||
|
Key? key,
|
||||||
|
bool tap = true,
|
||||||
|
}) {
|
||||||
|
return CustomScrollView(
|
||||||
|
key: key,
|
||||||
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
|
slivers: [
|
||||||
|
if (res.summary?.isNotEmpty == true) ...[
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||||
|
child: selectableText(
|
||||||
|
res.summary!,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (res.outline?.isNotEmpty == true)
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: Divider(
|
||||||
|
height: 20,
|
||||||
|
color: theme.dividerColor.withValues(alpha: 0.1),
|
||||||
|
thickness: 6,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
if (res.outline?.isNotEmpty == true)
|
||||||
|
SliverPadding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: 14,
|
||||||
|
right: 14,
|
||||||
|
bottom: MediaQuery.viewPaddingOf(context).bottom + 100,
|
||||||
|
),
|
||||||
|
sliver: SliverList.builder(
|
||||||
|
itemCount: res.outline!.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final item = res.outline![index];
|
||||||
|
return SelectionArea(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (index != 0) const SizedBox(height: 10),
|
||||||
|
Text(
|
||||||
|
item.title!,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
...?item.partOutline?.map(
|
||||||
|
(item) => Wrap(
|
||||||
|
children: [
|
||||||
|
Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: theme.colorScheme.onSurface,
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: DurationUtils.formatDuration(
|
||||||
|
item.timestamp,
|
||||||
|
),
|
||||||
|
style: tap
|
||||||
|
? TextStyle(
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
recognizer: tap
|
||||||
|
? (TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
try {
|
||||||
|
Get.find<VideoDetailController>(
|
||||||
|
tag: Get.arguments['heroTag'],
|
||||||
|
).plPlayerController.seekTo(
|
||||||
|
Duration(
|
||||||
|
seconds: item.timestamp!,
|
||||||
|
),
|
||||||
|
isSeek: false,
|
||||||
|
);
|
||||||
|
} catch (_) {}
|
||||||
|
})
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
const TextSpan(text: ' '),
|
||||||
|
TextSpan(text: item.content!),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _AiDetailState extends State<AiConclusionPanel>
|
class _AiDetailState extends State<AiConclusionPanel>
|
||||||
@@ -65,102 +177,11 @@ class _AiDetailState extends State<AiConclusionPanel>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildList(ThemeData theme) {
|
Widget buildList(ThemeData theme) {
|
||||||
final child = CustomScrollView(
|
final child = AiConclusionPanel.buildContent(
|
||||||
|
context,
|
||||||
|
theme,
|
||||||
|
widget.item,
|
||||||
key: _key,
|
key: _key,
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
|
||||||
slivers: [
|
|
||||||
if (widget.item.summary?.isNotEmpty == true) ...[
|
|
||||||
SliverToBoxAdapter(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
||||||
child: selectableText(
|
|
||||||
widget.item.summary!,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 15,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (widget.item.outline?.isNotEmpty == true)
|
|
||||||
SliverToBoxAdapter(
|
|
||||||
child: Divider(
|
|
||||||
height: 20,
|
|
||||||
color: theme.dividerColor.withValues(alpha: 0.1),
|
|
||||||
thickness: 6,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
if (widget.item.outline?.isNotEmpty == true)
|
|
||||||
SliverPadding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
left: 14,
|
|
||||||
right: 14,
|
|
||||||
bottom: MediaQuery.viewPaddingOf(context).bottom + 100,
|
|
||||||
),
|
|
||||||
sliver: SliverList.builder(
|
|
||||||
itemCount: widget.item.outline!.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final item = widget.item.outline![index];
|
|
||||||
return SelectionArea(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
if (index != 0) const SizedBox(height: 10),
|
|
||||||
Text(
|
|
||||||
item.title!,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 6),
|
|
||||||
...?item.partOutline?.map(
|
|
||||||
(item) => Wrap(
|
|
||||||
children: [
|
|
||||||
Text.rich(
|
|
||||||
TextSpan(
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
color: theme.colorScheme.onSurface,
|
|
||||||
height: 1.5,
|
|
||||||
),
|
|
||||||
children: [
|
|
||||||
TextSpan(
|
|
||||||
text: DurationUtils.formatDuration(
|
|
||||||
item.timestamp,
|
|
||||||
),
|
|
||||||
style: TextStyle(
|
|
||||||
color: theme.colorScheme.primary,
|
|
||||||
),
|
|
||||||
recognizer: TapGestureRecognizer()
|
|
||||||
..onTap = () {
|
|
||||||
try {
|
|
||||||
Get.find<VideoDetailController>(
|
|
||||||
tag: Get.arguments['heroTag'],
|
|
||||||
).plPlayerController.seekTo(
|
|
||||||
Duration(seconds: item.timestamp!),
|
|
||||||
isSeek: false,
|
|
||||||
);
|
|
||||||
} catch (_) {}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const TextSpan(text: ' '),
|
|
||||||
TextSpan(text: item.content!),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
if (_isNested) {
|
if (_isNested) {
|
||||||
return ExtendedVisibilityDetector(
|
return ExtendedVisibilityDetector(
|
||||||
|
|||||||
@@ -753,25 +753,38 @@ class UgcIntroController extends CommonIntroController with ReloadMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ai总结
|
// ai总结
|
||||||
Future aiConclusion() async {
|
static Future<AiConclusionResult?> getAiConclusion(
|
||||||
|
String bvid,
|
||||||
|
int cid,
|
||||||
|
int? mid,
|
||||||
|
) async {
|
||||||
if (!Accounts.heartbeat.isLogin) {
|
if (!Accounts.heartbeat.isLogin) {
|
||||||
SmartDialog.showToast("账号未登录");
|
SmartDialog.showToast("账号未登录");
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
SmartDialog.showLoading(msg: '正在获取AI总结');
|
SmartDialog.showLoading(msg: '正在获取AI总结');
|
||||||
final res = await VideoHttp.aiConclusion(
|
final res = await VideoHttp.aiConclusion(
|
||||||
bvid: bvid,
|
bvid: bvid,
|
||||||
cid: cid.value,
|
cid: cid,
|
||||||
upMid: videoDetail.value.owner?.mid,
|
upMid: mid,
|
||||||
);
|
);
|
||||||
SmartDialog.dismiss();
|
SmartDialog.dismiss();
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
AiConclusionData data = res['data'];
|
AiConclusionData data = res['data'];
|
||||||
aiConclusionResult = data.modelResult;
|
return data.modelResult;
|
||||||
} else if (res['handling']) {
|
} else if (res['handling']) {
|
||||||
SmartDialog.showToast("AI处理中,请稍后再试");
|
SmartDialog.showToast("AI处理中,请稍后再试");
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast("当前视频暂不支持AI视频总结");
|
SmartDialog.showToast("当前视频暂不支持AI视频总结");
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> aiConclusion() async {
|
||||||
|
aiConclusionResult = await getAiConclusion(
|
||||||
|
bvid,
|
||||||
|
cid.value,
|
||||||
|
videoDetail.value.owner?.mid,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user