fix(mpv): auto-select subtitle and audio tracks on file open
This commit is contained in:
1 parent
32c686e0e3
commit
23cf7e31a9
13 files changed
+437
-1
No files matched your search
+1
-1
@@ -389,7 +389,7 @@ Item {
|
||||
}
|
||||
|
||||
property Action translateSubtitle: Action {
|
||||
enabled: root.shortcutsEnabled && root.hasFile && root.mpv.subtitleId > 0 && !root.translator.busy
|
||||
enabled: root.shortcutsEnabled && root.hasFile && root.mpv.subtitleTracks.some(track => !track.bitmap) && !root.translator.busy
|
||||
text: KI18n.i18nc("@action", "Translate Subtitle into %1", QtPotatoSettings.targetLanguage)
|
||||
icon.name: "translate"
|
||||
shortcut: "Ctrl+T"
|
||||
|
||||
@@ -51,6 +51,11 @@ ApplicationWindow {
|
||||
if (track && translatedSubtitleUrls.includes(track.externalFilename) && lastTranslationTrack) {
|
||||
track = video.subtitleTracks.find(track => track.id === lastTranslationTrack.id)
|
||||
}
|
||||
// No subtitle shown, or a picture-based one: translate the best text subtitle.
|
||||
if (!track || track.bitmap) {
|
||||
const sourceId = video.translationSourceId()
|
||||
track = video.subtitleTracks.find(track => track.id === sourceId)
|
||||
}
|
||||
if (track) {
|
||||
lastTranslationTrack = track
|
||||
lastTranslationVideo = video.currentUrl
|
||||
|
||||
@@ -34,6 +34,9 @@ MpvItem {
|
||||
Kirigami.Theme.inherit: false
|
||||
|
||||
loadUserConfig: QtPotatoSettings.loadMpvConfig
|
||||
preferredAudioLanguages: QtPotatoSettings.preferredAudioLanguages
|
||||
preferredSubtitleLanguages: QtPotatoSettings.preferredSubtitleLanguages
|
||||
autoSelectSubtitle: QtPotatoSettings.autoSelectSubtitle
|
||||
|
||||
// Set once the saved volume is applied; mpv reports its default volume before that.
|
||||
property bool volumeRestored: false
|
||||
|
||||
@@ -72,5 +72,25 @@ SettingsBasePage {
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:textbox", "Preferred languages")
|
||||
Kirigami.FormData.buddyFor: audioLanguagesField
|
||||
|
||||
TextField {
|
||||
id: audioLanguagesField
|
||||
text: QtPotatoSettings.preferredAudioLanguages.join(", ")
|
||||
placeholderText: KI18n.i18nc("@info:placeholder language codes", "e.g. ja, en")
|
||||
onEditingFinished: {
|
||||
QtPotatoSettings.preferredAudioLanguages = text.split(/[,;\s]+/).filter(Boolean)
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
}
|
||||
|
||||
ToolTipButton {
|
||||
toolTipText: KI18n.i18nc("@info:tooltip", "Audio track turned on when a file opens, first match wins. Use language codes or English names, separated by commas. Leave empty to keep the file's default track.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,49 @@ SettingsBasePage {
|
||||
|
||||
Kirigami.FormLayout {
|
||||
|
||||
SettingsHeader {
|
||||
text: KI18n.i18nc("@title", "Track Selection")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:textbox", "Preferred languages")
|
||||
Kirigami.FormData.buddyFor: subtitleLanguagesField
|
||||
|
||||
TextField {
|
||||
id: subtitleLanguagesField
|
||||
text: QtPotatoSettings.preferredSubtitleLanguages.join(", ")
|
||||
placeholderText: KI18n.i18nc("@info:placeholder language codes", "e.g. vi, en")
|
||||
onEditingFinished: {
|
||||
QtPotatoSettings.preferredSubtitleLanguages = text.split(/[,;\s]+/).filter(Boolean)
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
}
|
||||
|
||||
ToolTipButton {
|
||||
toolTipText: KI18n.i18nc("@info:tooltip", "Subtitle turned on when a file opens, first match wins. Use language codes or English names, separated by commas. Subtitle files next to the video count too.")
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
text: KI18n.i18nc("@option:check", "Turn on a subtitle when none matches")
|
||||
checked: QtPotatoSettings.autoSelectSubtitle
|
||||
onToggled: {
|
||||
QtPotatoSettings.autoSelectSubtitle = checked
|
||||
QtPotatoSettings.save()
|
||||
}
|
||||
|
||||
ToolTip.text: KI18n.i18nc("@info:tooltip", "Many files have no default subtitle, so they open with subtitles off. Picks one in the system language instead, then English, then the audio language.")
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||
}
|
||||
|
||||
SettingsHeader {
|
||||
text: KI18n.i18nc("@title", "Appearance")
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
Kirigami.FormData.label: KI18n.i18nc("@label:spinbox", "Font size")
|
||||
|
||||
Reference in new issue
Block a user