fix(mpv): auto-select subtitle and audio tracks on file open (#12)
Closes #7 mpv only turns on a subtitle that is flagged default or matches `slang`, so releases like VisionQuest (Russian dub by default, ru/ru/en subtitles, none flagged) open with subtitles off, which also disabled **Translate subtitle**. - New `TrackSelection` helpers in `qtpotato_core` with unit tests. - On file load: audio follows *Preferred languages* (Playback settings); subtitle follows *Preferred languages* (Subtitles settings), else keeps mpv's choice, else (new *Turn on a subtitle when none matches*, on by default) picks a full text subtitle in the system language, then English, then the audio language, then the default/first track. - Translate is enabled whenever the file has a text subtitle; with none or a bitmap subtitle shown it translates the best text track (English first). Verified in the real app on VisionQuest S01E01: subtitle 3 (en) is selected on open; with audio set to `en` and auto-select off, audio switches to track 7, subtitle stays off and Translate stays enabled with the English source. Reviewed-on: #12 Co-authored-by: Tri Vo Khac <git@trivk.dev>
This commit was merged in pull request #12.
This commit is contained in:
1 parent
32c686e0e3
commit
b34a01a92f
13 files changed
+437
-1
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
// Which audio and subtitle tracks to turn on when a file opens. mpv only turns on a
|
||||
// subtitle that is flagged default or matches --slang, so many files open with none.
|
||||
namespace TrackSelection
|
||||
{
|
||||
struct Track {
|
||||
int id = 0;
|
||||
QString lang;
|
||||
QString codec;
|
||||
bool forced = false;
|
||||
bool isDefault = false;
|
||||
};
|
||||
|
||||
// True for picture-based subtitles (PGS, VobSub, DVB), which can't be translated.
|
||||
// \a codec is the FFmpeg codec name that mpv reports.
|
||||
bool isBitmapSubtitle(const QString &codec);
|
||||
|
||||
// Compares language tags written as ISO 639-1/2 codes ("en", "eng"), with a region
|
||||
// ("en-US") or as English names ("English").
|
||||
bool sameLanguage(const QString &a, const QString &b);
|
||||
|
||||
// The first audio track in a \a preferredLanguages language, else \a currentId.
|
||||
int pickAudio(const QList<Track> &tracks, const QStringList &preferredLanguages, int currentId);
|
||||
|
||||
// The subtitle to turn on when the file opens. A track in one of \a preferredLanguages
|
||||
// wins over mpv's own choice \a currentId; without one, \a currentId is kept. When mpv
|
||||
// chose nothing and \a fallback is set, picks a full (not forced) subtitle in the first
|
||||
// of \a fallbackLanguages that has one, then one flagged default, then the first one.
|
||||
// Text subtitles win over bitmap ones in the same step. Returns 0 for no subtitle.
|
||||
int pickSubtitle(const QList<Track> &tracks, const QStringList &preferredLanguages, const QStringList &fallbackLanguages, int currentId, bool fallback);
|
||||
|
||||
// The subtitle to translate: \a currentId when it is a text subtitle, else a full text
|
||||
// subtitle in the first of \a sourceLanguages that has one, then one flagged default,
|
||||
// then the first one. 0 when there is no text subtitle.
|
||||
int pickTranslationSource(const QList<Track> &tracks, const QStringList &sourceLanguages, int currentId);
|
||||
}
|
||||
Reference in new issue
Block a user