feat: translate subtitles with an OpenAI-compatible LLM

This commit is contained in:
tri committed 2026-10-27 22:43:03 +07:00
1 parent 48cac86d60
commit 4665bf632a
21 files changed
+1877 -5

No files matched your search

+30
View File
@@ -10,8 +10,10 @@ Kirigami.Page {
property url initialUrl
readonly property alias mediaTitle: mpv.mediaTitle
readonly property alias translator: translator
signal aboutRequested()
signal settingsRequested()
signal fullScreenToggled()
title: KI18n.i18nc("@title", "Player")
@@ -31,6 +33,13 @@ Kirigami.Page {
shortcut: "F"
onTriggered: page.fullScreenToggled()
},
Kirigami.Action {
icon.name: "configure"
text: KI18n.i18nc("@action", "Settings")
displayHint: Kirigami.DisplayHint.AlwaysHide
shortcut: StandardKey.Preferences
onTriggered: page.settingsRequested()
},
Kirigami.Action {
icon.name: "help-about"
text: KI18n.i18nc("@action", "About QtPotato")
@@ -83,6 +92,25 @@ Kirigami.Page {
mpv.showText(KI18n.i18nc("@info:osd", "Subtitle delay: %1 ms", Math.round(delay * 1000)))
}
TranslationService {
id: translator
onTranslated: (subtitleUrl, fromCache) => {
mpv.showSecondarySubtitleFile(subtitleUrl,
KI18n.i18nc("@item:inlistbox subtitle track, %1 is a language", "%1 (translated)", QtPotatoSettings.targetLanguage))
mpv.showText(fromCache
? KI18n.i18nc("@info:osd", "Loaded the saved translation")
: KI18n.i18nc("@info:osd", "Translation ready"))
}
}
Connections {
target: mpv
// A translation belongs to the file it was started for.
function onCurrentUrlChanged() {
translator.cancel()
}
}
function isSubtitleFile(url: url): bool {
return /\.(srt|ass|ssa|vtt|sub|sup)$/i.test(url.toString())
}
@@ -212,6 +240,8 @@ Kirigami.Page {
id: subtitlePopup
objectName: "subtitlePopup"
mpv: mpv
translator: translator
onSettingsRequested: page.settingsRequested()
x: subtitleButton.width - width
y: -height - Kirigami.Units.smallSpacing
}