* opt: boundary

* opt: subtitle

* tweaks
This commit is contained in:
My-Responsitories
2025-09-29 22:13:02 +08:00
committed by GitHub
parent 1d723b704b
commit 89e6d5c160
5 changed files with 71 additions and 74 deletions

View File

@@ -1,19 +1,14 @@
class Subtitle {
String? lan;
late String lan;
String? lanDoc;
String? subtitleUrl;
String? subtitleUrlV2;
Subtitle({
this.lan,
this.lanDoc,
this.subtitleUrl,
this.subtitleUrlV2,
});
bool isAi = false;
Subtitle.fromJson(Map<String, dynamic> json) {
lan = json["lan"];
lanDoc = '${json["lan_doc"]}${lan!.startsWith('ai') ? 'AI' : ''}';
isAi = json["type"] == 1;
lanDoc = '${json["lan_doc"]}${isAi ? 'AI' : ''}';
subtitleUrl = json["subtitle_url"];
subtitleUrlV2 = json["subtitle_url_v2"];
}

View File

@@ -7,22 +7,19 @@ class SubtitleInfo {
SubtitleInfo({this.lan, this.lanDoc, this.subtitles});
SubtitleInfo.fromJson(Map<String, dynamic> json) {
lan = json['lan'] as String?;
lanDoc = json['lan_doc'] as String?;
final List? list = json['subtitles'];
if (list != null && list.isNotEmpty) {
subtitles = <Subtitle>[];
int index = 0;
for (var e in list) {
final item = Subtitle.fromJson(e);
if (item.lan!.contains('zh')) {
subtitles!.insert(index, item);
index++;
} else {
subtitles!.add(item);
}
}
}
}
factory SubtitleInfo.fromJson(Map<String, dynamic> json) => SubtitleInfo(
lan: json['lan'] as String?,
lanDoc: json['lan_doc'] as String?,
subtitles:
(json['subtitles'] as List<dynamic>?)
?.map((e) => Subtitle.fromJson(e as Map<String, dynamic>))
.toList()
?..sort((a, b) {
final aHasZh = a.lan.contains('zh');
final bHasZh = b.lan.contains('zh');
if (aHasZh != bHasZh) return aHasZh ? -1 : 1;
if (a.isAi != b.isAi) return a.isAi ? 1 : -1;
return 0;
}),
);
}