mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-02 00:58:19 +08:00
feat: save subtitle
Closes #495 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1373,6 +1373,7 @@ class VideoDetailController extends GetxController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dynamic subtitles;
|
||||||
late List<Map<String, String>> _vttSubtitles = <Map<String, String>>[];
|
late List<Map<String, String>> _vttSubtitles = <Map<String, String>>[];
|
||||||
int? vttSubtitlesIndex;
|
int? vttSubtitlesIndex;
|
||||||
late bool showVP = true;
|
late bool showVP = true;
|
||||||
@@ -1499,6 +1500,7 @@ class VideoDetailController extends GetxController
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (res["data"] is List && res["data"].isNotEmpty) {
|
if (res["data"] is List && res["data"].isNotEmpty) {
|
||||||
|
subtitles = res["data"];
|
||||||
var result = await VideoHttp.vttSubtitles(res["data"]);
|
var result = await VideoHttp.vttSubtitles(res["data"]);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
_vttSubtitles = result;
|
_vttSubtitles = result;
|
||||||
@@ -1569,6 +1571,7 @@ class VideoDetailController extends GetxController
|
|||||||
savedDanmaku = null;
|
savedDanmaku = null;
|
||||||
|
|
||||||
// subtitle
|
// subtitle
|
||||||
|
subtitles = null;
|
||||||
vttSubtitlesIndex = null;
|
vttSubtitlesIndex = null;
|
||||||
_vttSubtitles.clear();
|
_vttSubtitles.clear();
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import 'package:PiliPlus/utils/extension.dart';
|
|||||||
import 'package:PiliPlus/utils/id_utils.dart';
|
import 'package:PiliPlus/utils/id_utils.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:canvas_danmaku/canvas_danmaku.dart';
|
import 'package:canvas_danmaku/canvas_danmaku.dart';
|
||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:document_file_save_plus/document_file_save_plus_platform_interface.dart';
|
||||||
import 'package:floating/floating.dart';
|
import 'package:floating/floating.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -30,6 +32,7 @@ import 'package:PiliPlus/plugin/pl_player/index.dart';
|
|||||||
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
|
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:PiliPlus/services/shutdown_timer_service.dart';
|
import 'package:PiliPlus/services/shutdown_timer_service.dart';
|
||||||
|
import 'package:share_plus/share_plus.dart';
|
||||||
import '../../../../models/video/play/CDN.dart';
|
import '../../../../models/video/play/CDN.dart';
|
||||||
import '../../../setting/widgets/select_dialog.dart';
|
import '../../../setting/widgets/select_dialog.dart';
|
||||||
import '../introduction/index.dart';
|
import '../introduction/index.dart';
|
||||||
@@ -386,6 +389,14 @@ class _HeaderControlState extends State<HeaderControl> {
|
|||||||
leading: const Icon(Icons.subtitles_outlined, size: 20),
|
leading: const Icon(Icons.subtitles_outlined, size: 20),
|
||||||
title: const Text('字幕设置', style: titleStyle),
|
title: const Text('字幕设置', style: titleStyle),
|
||||||
),
|
),
|
||||||
|
if (videoDetailCtr.subtitles is List &&
|
||||||
|
videoDetailCtr.subtitles.isNotEmpty)
|
||||||
|
ListTile(
|
||||||
|
dense: true,
|
||||||
|
onTap: () => {Get.back(), onExportSubtitle()},
|
||||||
|
leading: const Icon(Icons.download_outlined, size: 20),
|
||||||
|
title: const Text('保存字幕', style: titleStyle),
|
||||||
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
dense: true,
|
dense: true,
|
||||||
title: const Text('播放信息', style: titleStyle),
|
title: const Text('播放信息', style: titleStyle),
|
||||||
@@ -1035,6 +1046,66 @@ class _HeaderControlState extends State<HeaderControl> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onExportSubtitle() {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
|
contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12),
|
||||||
|
title: const Text('保存字幕'),
|
||||||
|
content: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: (videoDetailCtr.subtitles as List)
|
||||||
|
.map(
|
||||||
|
(item) => ListTile(
|
||||||
|
dense: true,
|
||||||
|
onTap: () async {
|
||||||
|
Get.back();
|
||||||
|
try {
|
||||||
|
final res = await Dio().get(
|
||||||
|
(item['subtitle_url'] as String).http2https,
|
||||||
|
options: Options(
|
||||||
|
responseType: ResponseType.bytes,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
final name =
|
||||||
|
'${videoIntroController.videoDetail.value.title}-${videoDetailCtr.bvid}-${videoDetailCtr.cid.value}-${item['lan_doc']}';
|
||||||
|
try {
|
||||||
|
DocumentFileSavePlusPlatform.instance
|
||||||
|
.saveMultipleFiles(
|
||||||
|
dataList: [res.data],
|
||||||
|
fileNameList: [name],
|
||||||
|
mimeTypeList: ['text/plain'],
|
||||||
|
);
|
||||||
|
SmartDialog.showToast('已保存');
|
||||||
|
} catch (e) {
|
||||||
|
Share.shareXFiles([
|
||||||
|
XFile.fromData(
|
||||||
|
res.data,
|
||||||
|
name: name,
|
||||||
|
mimeType: 'application/json',
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
SmartDialog.showToast(e.toString());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title:
|
||||||
|
Text(item['lan_doc'], style: TextStyle(fontSize: 14)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// 字幕设置
|
/// 字幕设置
|
||||||
void showSetSubtitle() {
|
void showSetSubtitle() {
|
||||||
double subtitleFontScale = widget.controller.subtitleFontScale;
|
double subtitleFontScale = widget.controller.subtitleFontScale;
|
||||||
|
|||||||
@@ -441,6 +441,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
document_file_save_plus:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: document_file_save_plus
|
||||||
|
sha256: ff05c6a3b072377566e8e92666db38eb277786f90c0ac267ea47dc22725c1df3
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
dynamic_color:
|
dynamic_color:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ dependencies:
|
|||||||
live_photo_maker: ^0.0.6
|
live_photo_maker: ^0.0.6
|
||||||
fl_chart: ^0.69.2
|
fl_chart: ^0.69.2
|
||||||
synchronized: ^3.3.0
|
synchronized: ^3.3.0
|
||||||
|
document_file_save_plus: ^2.0.0
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
screen_brightness: ^2.0.1
|
screen_brightness: ^2.0.1
|
||||||
|
|||||||
Reference in New Issue
Block a user