feat(api): extract an embedded track on demand (#261)
Closes #260.
This commit was merged in pull request #261.
This commit is contained in:
@@ -364,6 +364,23 @@ impl SubtitleCodec {
|
||||
pub const fn is_text(self) -> bool {
|
||||
matches!(self, Self::SubRip | Self::Ass | Self::MovText)
|
||||
}
|
||||
|
||||
/// The inverse of [`Display`](fmt::Display): read back a codec that was
|
||||
/// written out under its `ffprobe` name. `ffprobe`'s own aliases are
|
||||
/// accepted alongside, so a column written by an older probe still
|
||||
/// resolves. Anything unrecognised is [`Self::Other`], which extracts
|
||||
/// nothing — the same answer as a bitmap track.
|
||||
#[must_use]
|
||||
pub fn from_probe_name(name: &str) -> Self {
|
||||
match name {
|
||||
"subrip" | "srt" => Self::SubRip,
|
||||
"ass" | "ssa" => Self::Ass,
|
||||
"mov_text" => Self::MovText,
|
||||
"hdmv_pgs_subtitle" => Self::Pgs,
|
||||
"dvd_subtitle" => Self::VobSub,
|
||||
_ => Self::Other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -490,7 +507,7 @@ pub struct MovieOwner {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{DolbyVisionProfile, HdrFormat, Language, Rule, Verdict};
|
||||
use super::{DolbyVisionProfile, HdrFormat, Language, Rule, SubtitleCodec, Verdict};
|
||||
|
||||
#[test]
|
||||
fn portuguese_variants_are_distinct() {
|
||||
@@ -512,6 +529,26 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn probe_names_round_trip_through_the_codec() {
|
||||
for codec in [
|
||||
SubtitleCodec::SubRip,
|
||||
SubtitleCodec::Ass,
|
||||
SubtitleCodec::MovText,
|
||||
SubtitleCodec::Pgs,
|
||||
SubtitleCodec::VobSub,
|
||||
] {
|
||||
assert_eq!(SubtitleCodec::from_probe_name(&codec.to_string()), codec);
|
||||
}
|
||||
assert_eq!(SubtitleCodec::from_probe_name("srt"), SubtitleCodec::SubRip);
|
||||
assert_eq!(SubtitleCodec::from_probe_name("ssa"), SubtitleCodec::Ass);
|
||||
assert_eq!(
|
||||
SubtitleCodec::from_probe_name("dvb_subtitle"),
|
||||
SubtitleCodec::Other
|
||||
);
|
||||
assert!(!SubtitleCodec::from_probe_name("other").is_text());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_eligible_verdicts_name_the_rule() {
|
||||
let rule = Rule::DolbyVisionProfile(DolbyVisionProfile {
|
||||
|
||||
Reference in New Issue
Block a user