mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-04 08:56:59 +01:00
feat(core,app,android,ios): play the dialogue, not the signs and songs
Anime releases often carry two subtitle tracks in one language, the dialogue and a "Signs & Songs" track, and the second is as often as not the one marked default or forced. mpv, picking by language, played it. pstr_core::subtitles reads a track's name and forced flag for whether it is the dialogue, and every client asks it once per file, after mpv has made its own pick, whether to switch to a track in the same language that is. A subtitle track the viewer chose by name stays, and subtitles that are off stay off.
This commit is contained in:
1 parent
8d615579e2
commit
b1ea076ea3
10 files changed
+353
-7
No files matched your search
@@ -52,4 +52,4 @@ pub use player::{
|
||||
};
|
||||
pub use registry::{PROTOCOL, StreamHandle, StreamRegistry};
|
||||
pub use render::VideoRenderer;
|
||||
pub use tracks::{LANGUAGES, Track, TrackKind, language_name, pick_track};
|
||||
pub use tracks::{LANGUAGES, Track, TrackKind, full_subtitles_instead, language_name, pick_track};
|
||||
@@ -12,6 +12,7 @@
|
||||
//! an empty string.
|
||||
|
||||
use libmpv2::Mpv;
|
||||
use pstr_core::subtitles::{SubtitleTrack, full_instead};
|
||||
|
||||
/// What a track carries.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
@@ -69,6 +70,9 @@ pub struct Track {
|
||||
pub selected: bool,
|
||||
/// Whether the container marks it as the default choice.
|
||||
pub default: bool,
|
||||
/// Whether the container marks it as forced: a subtitle track of the
|
||||
/// on-screen text alone.
|
||||
pub forced: bool,
|
||||
/// True for a track added from outside the file — a sidecar subtitle. None
|
||||
/// of ours are, yet.
|
||||
pub external: bool,
|
||||
@@ -152,6 +156,24 @@ pub fn pick_track(
|
||||
)
|
||||
}
|
||||
|
||||
/// The dialogue track to play in place of the subtitle track mpv chose, when
|
||||
/// mpv chose signs and songs; see [`pstr_core::subtitles::full_instead`].
|
||||
pub fn full_subtitles_instead(tracks: &[Track]) -> Option<i64> {
|
||||
let subtitles: Vec<_> = tracks
|
||||
.iter()
|
||||
.filter(|track| track.kind == TrackKind::Subtitle)
|
||||
.map(|track| SubtitleTrack {
|
||||
id: track.id,
|
||||
language: track.language.clone(),
|
||||
title: track.title.clone(),
|
||||
default: track.default,
|
||||
forced: track.forced,
|
||||
selected: track.selected,
|
||||
})
|
||||
.collect();
|
||||
full_instead(&subtitles)
|
||||
}
|
||||
|
||||
fn read_one(mpv: &Mpv, index: i64) -> Option<Track> {
|
||||
let kind = TrackKind::from_mpv(&text(mpv, index, "type")?)?;
|
||||
let id: i64 = mpv
|
||||
@@ -167,6 +189,7 @@ fn read_one(mpv: &Mpv, index: i64) -> Option<Track> {
|
||||
codec: text(mpv, index, "codec"),
|
||||
selected: flag(mpv, index, "selected"),
|
||||
default: flag(mpv, index, "default"),
|
||||
forced: flag(mpv, index, "forced"),
|
||||
external: flag(mpv, index, "external"),
|
||||
})
|
||||
}
|
||||
@@ -200,6 +223,7 @@ mod tests {
|
||||
codec: None,
|
||||
selected: false,
|
||||
default: false,
|
||||
forced: false,
|
||||
external: false,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user