#pragma once #include #include #include // 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 &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. Next comes \a translationId, the file's // saved translation, when \a fallback is set; without either, \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 &tracks, const QStringList &preferredLanguages, const QStringList &fallbackLanguages, int currentId, bool fallback, int translationId = 0); // 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 &tracks, const QStringList &sourceLanguages, int currentId); }