Struct WebVttSubtitle

Source
pub struct WebVttSubtitle { /* private fields */ }
Expand description

WebVTT (.vtt) subtitle data

Implementations§

Source§

impl WebVttSubtitle

Source

pub fn builder() -> __WebVttSubtitleBuilder<(__Optional<Option<String>>, __Optional<Vec<WebVttCue>>, __Optional<Vec<String>>, __Optional<Vec<String>>)>

Create a new WebVttSubtitle

§Arguments
  • header: Header (optional)
  • cues: List of cues
  • styles: List of styles (strings)
  • regions: List of regions (strings)
Source§

impl WebVttSubtitle

Source

pub fn header(&self) -> Option<&String>

Get header

Examples found in repository?
examples/basic.rs (line 8)
3fn main() -> Result<(), Error> {
4    // We can directly specify the format to open a subtitle file
5    let vtt = WebVttSubtitle::from_path("/path/to/some.vtt")?;
6
7    // and then directly work with its data
8    println!("{}", vtt.header().cloned().unwrap_or_default());
9
10    // or we could use the more general interface to open (timed) subtitle files
11    let sub = TimedSubtitleFile::new("/path/to/file.srt")?;
12
13    // Move the underlying data out in order to access format-specific properties
14    // Note that if the format doesn't match, this will perform a conversion instead of just moving the data
15    let mut srt = SubRipSubtitle::from(sub);
16
17    // Now we can access format-specific methods like SubRipSubtitle::renumber()
18    srt.renumber();
19
20    // Access and modify events
21    for event in srt.events_mut() {
22        event.shift(600.into());
23    }
24
25    // Write the modified subtitle to file
26    srt.export("/path/to/output.srt")?;
27
28    Ok(())
29}
Source

pub fn set_header(&mut self, header: impl Into<Option<String>>)

Change header to specified option

Source

pub fn styles(&self) -> &[String]

Get list of styles as a slice

Source

pub fn styles_mut(&mut self) -> &mut [String]

Get list of styles as a mutable slice

Source

pub fn style(&self, index: usize) -> Option<&String>

Get style at index

Source

pub fn style_mut(&mut self, index: usize) -> Option<&mut String>

Get mutable style at index

Source

pub fn regions(&self) -> &[String]

Get list of regions as a slice

Source

pub fn regions_mut(&mut self) -> &mut [String]

Get list of regions as a mutable slice

Source

pub fn region(&self, index: usize) -> Option<&String>

Get region at index

Source

pub fn region_mut(&mut self, index: usize) -> Option<&mut String>

Get mutable region at index

Trait Implementations§

Source§

impl Clone for WebVttSubtitle

Source§

fn clone(&self) -> WebVttSubtitle

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WebVttSubtitle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WebVttSubtitle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for WebVttSubtitle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&AssSubtitle> for WebVttSubtitle

Source§

fn from(value: &AssSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<&SsaSubtitle> for WebVttSubtitle

Source§

fn from(value: &SsaSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<&SubRipSubtitle> for WebVttSubtitle

Source§

fn from(value: &SubRipSubtitle) -> Self

Convert a SubRip (.srt) subtitle to WebVTT format.

This sets the line number as the cue identifier.

The supported tags are <b>, <i>, and <u>. Any other tags will be stripped from the text.

Bracket tags (of the form {b}) will be converted to HTML tags (<b>).

Source§

impl From<&TimedMicroDvdSubtitle> for WebVttSubtitle

Source§

fn from(value: &TimedMicroDvdSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<&WebVttSubtitle> for AssSubtitle

Source§

fn from(value: &WebVttSubtitle) -> Self

Convert WebVTT (.vtt) format subtitle to .ass format.

For each line, this will convert newlines into the appropriate representation, and it will also convert the basic HTML formatting tags (<b>, <i>, and <u>).

All other tags and styles are discarded.

Source§

impl From<&WebVttSubtitle> for SsaSubtitle

Source§

fn from(value: &WebVttSubtitle) -> Self

Convert WebVTT (.vtt) format subtitle to .ssa format.

For each line, this will convert newlines into the appropriate representation, and it will also convert the basic HTML formatting tags (<b>, <i>, and <u>).

All other tags and styles are discarded.

Source§

impl From<&WebVttSubtitle> for SubRipSubtitle

Source§

fn from(value: &WebVttSubtitle) -> Self

Convert WebVTT (.vtt) subtitle to .srt format

Cue identifiers that are numbers will be treated as line numbers for the corresponding event in the .srt output.

Source§

impl From<&WebVttSubtitle> for TimedMicroDvdSubtitle

Source§

fn from(value: &WebVttSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<AssSubtitle> for WebVttSubtitle

Source§

fn from(value: AssSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<PlainSubtitle> for WebVttSubtitle

Source§

fn from(value: PlainSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<SsaSubtitle> for WebVttSubtitle

Source§

fn from(value: SsaSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<SubRipSubtitle> for WebVttSubtitle

Source§

fn from(value: SubRipSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<TimedMicroDvdSubtitle> for WebVttSubtitle

Source§

fn from(value: TimedMicroDvdSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<TimedSubtitleFile> for WebVttSubtitle

Source§

fn from(value: TimedSubtitleFile) -> Self

Converts to this type from the input type.
Source§

impl From<WebVttSubtitle> for AssSubtitle

Source§

fn from(value: WebVttSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<WebVttSubtitle> for SsaSubtitle

Source§

fn from(value: WebVttSubtitle) -> Self

Converts to this type from the input type.
Source§

impl From<WebVttSubtitle> for SubRipSubtitle

Source§

fn from(value: WebVttSubtitle) -> Self

Converts to this type from the input type.
Source§

impl FromStr for WebVttSubtitle

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Subtitle for WebVttSubtitle

Source§

type Event = WebVttCue

Event type for the given subtitle format
Source§

fn from_path_with_encoding( path: impl AsRef<Path>, encoding: Option<&'static Encoding>, ) -> Result<Self, Error>

Load subtitle format from path using the given encoding Read more
Source§

fn events(&self) -> &[WebVttCue]

Get list of events as a slice
Source§

fn events_mut(&mut self) -> &mut [WebVttCue]

Get list of events as a mutable slice
Source§

fn from_path(path: impl AsRef<Path>) -> Result<Self, Error>

Load subtitle from given path. Automatically attempts to detect the encoding to use from the file contents. Read more
Source§

fn event(&self, index: usize) -> Option<&Self::Event>

Try to get event at given index
Source§

fn event_mut(&mut self, index: usize) -> Option<&mut Self::Event>

Try to get mutable event at given index
Source§

fn export(&self, path: impl AsRef<Path>) -> Result<(), Error>

Write subtitles to file at the given path Read more
Source§

impl TextSubtitle for WebVttSubtitle

Source§

fn strip_formatting(&mut self)

Remove all styling/formatting information from the text and subtitle metadata
Source§

impl TimedSubtitle for WebVttSubtitle

Source§

fn shift(&mut self, delta: TimeDelta)
where <Self as Subtitle>::Event: TimedEvent,

Shift all events in subtitle by given amount of time, in milliseconds.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.