Struct aspasia::SubRipSubtitle

source ·
pub struct SubRipSubtitle { /* private fields */ }
Expand description

SubRip (.srt) subtitle data, containing only a list of events.

Implementations§

source§

impl SubRipSubtitle

source

pub fn from_events(events: Vec<SubRipEvent>) -> Self

Creates a new SubRip (.srt) subtitle from an already existing list of SubRipEvents

source

pub fn renumber(&mut self)

Renumbers all events according to the order they are stored in.

This modifies the line number of all events, starting from 1 for the first event and incrementing by 1 for each subsequent event.

Examples found in repository?
examples/basic.rs (line 18)
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(())
}

Trait Implementations§

source§

impl Clone for SubRipSubtitle

source§

fn clone(&self) -> SubRipSubtitle

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 SubRipSubtitle

source§

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

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

impl Display for SubRipSubtitle

source§

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

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

impl From<&AssSubtitle> for SubRipSubtitle

source§

fn from(value: &AssSubtitle) -> Self

Convert Advanced SubStation Alpha (.ass) subtitles to .srt format

Replaces SubStation newline indicators (\N) with actual newlines. Additionally, converts .ass style formatting tags to .srt formatting tags. Currently, bolded, italicised, underlined, or coloured text will be converted to their .srt counterparts. All other tags will be discarded.

source§

impl From<&SsaSubtitle> for SubRipSubtitle

source§

fn from(value: &SsaSubtitle) -> Self

Convert SubStation Alpha (.ssa) subtitles to .srt format

Replaces SubStation newline indicators (\N) with actual newlines. Additionally, converts .ssa style formatting tags to .srt formatting tags. Currently, bolded, italicised, or coloured text will be converted to their .srt counterparts. All other tags will be discarded.

source§

impl From<&SubRipSubtitle> for AssSubtitle

source§

fn from(value: &SubRipSubtitle) -> Self

Convert SubRip (.srt) subtitle to .ass format.

This will replace newlines and convert HTML formatting tags (<b>, <i>, etc.) into .ass style formatting tags

source§

impl From<&SubRipSubtitle> for SsaSubtitle

source§

fn from(value: &SubRipSubtitle) -> Self

Convert SubRip (.srt) subtitle to .ssa format.

This will replace newlines and convert HTML formatting tags (<b>, <i>, etc.) into .ssa style formatting tags

source§

impl From<&SubRipSubtitle> for TimedMicroDvdSubtitle

source§

fn from(value: &SubRipSubtitle) -> 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 SubRipSubtitle

source§

fn from(value: &TimedMicroDvdSubtitle) -> Self

Converts to this type from the input type.
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<AssSubtitle> for SubRipSubtitle

source§

fn from(value: AssSubtitle) -> Self

Converts to this type from the input type.
source§

impl From<PlainSubtitle> for SubRipSubtitle

source§

fn from(value: PlainSubtitle) -> Self

Converts to this type from the input type.
source§

impl From<SsaSubtitle> for SubRipSubtitle

source§

fn from(value: SsaSubtitle) -> Self

Converts to this type from the input type.
source§

impl From<SubRipSubtitle> for AssSubtitle

source§

fn from(value: SubRipSubtitle) -> Self

Converts to this type from the input type.
source§

impl From<SubRipSubtitle> for SsaSubtitle

source§

fn from(value: SubRipSubtitle) -> 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 SubRipSubtitle

source§

fn from(value: TimedMicroDvdSubtitle) -> Self

Converts to this type from the input type.
source§

impl From<TimedSubtitleFile> for SubRipSubtitle

source§

fn from(value: TimedSubtitleFile) -> 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 SubRipSubtitle

§

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 SubRipSubtitle

§

type Event = SubRipEvent

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) -> &[SubRipEvent]

Get list of events as a slice
source§

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

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 SubRipSubtitle

source§

fn strip_formatting(&mut self)

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

impl TimedSubtitle for SubRipSubtitle

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.