Struct aspasia::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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() -> Result<(), Error> {
    // We can directly specify the format to open a subtitle file
    let vtt = WebVttSubtitle::from_path("/path/to/some.vtt")?;

    // and then directly work with its data
    println!("{}", vtt.header().cloned().unwrap_or_default());

    // or we could use the more general interface to open (timed) subtitle files
    let sub = TimedSubtitleFile::new("/path/to/file.srt")?;

    // Move the underlying data out in order to access format-specific properties
    // Note that if the format doesn't match, this will perform a conversion instead of just moving the data
    let mut srt = SubRipSubtitle::from(sub);

    // Now we can access format-specific methods like SubRipSubtitle::renumber()
    srt.renumber();

    // Access and modify events
    for event in srt.events_mut() {
        event.shift(600.into());
    }

    // Write the modified subtitle to file
    srt.export("/path/to/output.srt")?;

    Ok(())
}
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

§

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

§

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> 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,

§

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§

default 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>,

§

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>,

§

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.