Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
dom
2026-01-22 15:51:22 +08:00
parent 92e5fae29c
commit b9b54ce4f7
34 changed files with 627 additions and 665 deletions

View File

@@ -1456,7 +1456,7 @@ class VideoDetailController extends GetxController
}
RxList<Subtitle> subtitles = RxList<Subtitle>();
late final Map<int, String> vttSubtitles = {};
final Map<int, ({bool isData, String id})> vttSubtitles = {};
late final RxInt vttSubtitlesIndex = (-1).obs;
late final RxBool showVP = true.obs;
late final RxList<ViewPointSegment> viewPointList = <ViewPointSegment>[].obs;
@@ -1471,19 +1471,21 @@ class VideoDetailController extends GetxController
return;
}
Future<void> setSub(String subtitle) async {
Future<void> setSub(({bool isData, String id}) subtitle) async {
final sub = subtitles[index - 1];
await plPlayerController.videoPlayerController?.setSubtitleTrack(
SubtitleTrack.data(
subtitle,
title: sub.lanDoc,
language: sub.lan,
SubtitleTrack(
subtitle.id,
sub.lanDoc,
sub.lan,
uri: !subtitle.isData,
data: subtitle.isData,
),
);
vttSubtitlesIndex.value = index;
}
String? subtitle = vttSubtitles[index - 1];
({bool isData, String id})? subtitle = vttSubtitles[index - 1];
if (subtitle != null) {
await setSub(subtitle);
} else {
@@ -1491,8 +1493,9 @@ class VideoDetailController extends GetxController
subtitles[index - 1].subtitleUrl!,
);
if (!isClosed && result != null) {
vttSubtitles[index - 1] = result;
await setSub(result);
final subtitle = (isData: true, id: result);
vttSubtitles[index - 1] = subtitle;
await setSub(subtitle);
}
}
}
@@ -1665,6 +1668,8 @@ class VideoDetailController extends GetxController
?..removeListener(scrollListener)
..dispose();
animController?.dispose();
subtitles.clear();
vttSubtitles.clear();
super.onClose();
}

View File

@@ -324,7 +324,6 @@ class _DownloadPanelState extends State<DownloadPanel> {
required ugc.BaseEpisodeItem episode,
}) {
late String title;
String? cover;
num? duration;
int? pubdate;
int? view;
@@ -332,6 +331,11 @@ class _DownloadPanelState extends State<DownloadPanel> {
bool? isCharging;
int? cid;
String? cover;
int? width;
int? height;
bool cacheWidth = false;
switch (episode) {
case Part part:
cid = part.cid;
@@ -339,15 +343,27 @@ class _DownloadPanelState extends State<DownloadPanel> {
title = part.part ?? widget.videoDetail!.title!;
duration = part.duration;
pubdate = part.ctime;
if (part.dimension case final dimension?) {
width = dimension.width;
height = dimension.height;
}
break;
case ugc.EpisodeItem item:
cid = item.cid;
title = item.title!;
cover = item.arc?.pic;
duration = item.arc?.duration;
pubdate = item.arc?.pubdate;
view = item.arc?.stat?.view;
danmaku = item.arc?.stat?.danmaku;
if (item.arc case final arc?) {
cover = arc.pic;
duration = arc.duration;
pubdate = arc.pubdate;
if (arc.stat case final stat?) {
view = stat.view;
danmaku = stat.danmaku;
}
if (arc.dimension case final dimension?) {
width = dimension.width;
height = dimension.height;
}
}
if (item.attribute == 8) {
isCharging = true;
}
@@ -363,8 +379,15 @@ class _DownloadPanelState extends State<DownloadPanel> {
duration = item.duration == null ? null : item.duration! ~/ 1000;
}
pubdate = item.pubTime;
if (item.dimension case final dimension?) {
width = dimension.width;
height = dimension.height;
}
break;
}
if (width != null && height != null) {
cacheWidth = width <= height;
}
late final primary = theme.colorScheme.primary;
return Padding(
@@ -401,6 +424,7 @@ class _DownloadPanelState extends State<DownloadPanel> {
src: cover,
width: 140.8,
height: 88,
cacheWidth: cacheWidth,
),
if (duration != null && duration > 0)
PBadge(

View File

@@ -1,5 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:convert' show jsonDecode, utf8;
import 'dart:io';
import 'dart:math';
@@ -717,34 +717,41 @@ class HeaderControlState extends State<HeaderControl>
final first = file.files.first;
final path = first.path;
if (path != null) {
final file = File(path);
final stream = file.openRead().transform(
utf8.decoder,
);
final buffer = StringBuffer();
await for (final chunk in stream) {
if (!mounted) return;
buffer.write(chunk);
}
if (!mounted) return;
String sub = buffer.toString();
final name = first.name;
final length = videoDetailCtr.subtitles.length;
if (name.endsWith('.json')) {
final file = File(path);
final stream = file.openRead().transform(
utf8.decoder,
);
final buffer = StringBuffer();
await for (final chunk in stream) {
if (!mounted) return;
buffer.write(chunk);
}
if (!mounted) return;
String sub = buffer.toString();
sub = await compute<List, String>(
VideoHttp.processList,
jsonDecode(sub)['body'],
);
if (!mounted) return;
videoDetailCtr.vttSubtitles[length] = (
isData: true,
id: sub,
);
} else {
videoDetailCtr.vttSubtitles[length] = (
isData: false,
id: path,
);
}
final length = videoDetailCtr.subtitles.length;
videoDetailCtr
..subtitles.add(
Subtitle(
lan: '',
lanDoc: name.split('.').firstOrNull ?? name,
),
)
..vttSubtitles[length] = sub;
videoDetailCtr.subtitles.add(
Subtitle(
lan: '',
lanDoc: name.split('.').firstOrNull ?? name,
),
);
await videoDetailCtr.setSubtitle(length + 1);
}
}