pub struct Subtitle {
pub entries: Vec<SubtitleEntry>,
pub metadata: SubtitleMetadata,
pub format: SubtitleFormatType,
}Expand description
Unified subtitle data structure containing entries, metadata, and format information.
This structure represents a complete subtitle file in memory, providing a format-agnostic representation that can be converted between different subtitle formats while preserving as much information as possible.
§Examples
use subx_cli::core::formats::{Subtitle, SubtitleEntry, SubtitleMetadata, SubtitleFormatType};
use std::time::Duration;
let subtitle = Subtitle {
entries: vec![
SubtitleEntry {
index: 1,
start_time: Duration::from_secs(10),
end_time: Duration::from_secs(13),
text: "Hello, world!".to_string(),
styling: None,
}
],
metadata: SubtitleMetadata {
title: Some("Movie Title".to_string()),
language: Some("en".to_string()),
encoding: "UTF-8".to_string(),
frame_rate: Some(23.976),
original_format: SubtitleFormatType::Srt,
},
format: SubtitleFormatType::Srt,
};
println!("Subtitle has {} entries", subtitle.entries.len());Fields§
§entries: Vec<SubtitleEntry>Collection of subtitle entries with timing and text content.
metadata: SubtitleMetadataMetadata information about the subtitle file.
format: SubtitleFormatTypeCurrent format type of the subtitle data.
Implementations§
Source§impl Subtitle
impl Subtitle
Sourcepub fn new(format: SubtitleFormatType, metadata: SubtitleMetadata) -> Self
pub fn new(format: SubtitleFormatType, metadata: SubtitleMetadata) -> Self
Create a new subtitle with the given format and metadata.
§Arguments
format- The subtitle format typemetadata- Metadata associated with the subtitle
§Examples
use subx_cli::core::formats::{Subtitle, SubtitleMetadata, SubtitleFormatType};
let metadata = SubtitleMetadata::default();
let subtitle = Subtitle::new(SubtitleFormatType::Srt, metadata);
assert_eq!(subtitle.entries.len(), 0);Sourcepub fn total_duration(&self) -> Duration
pub fn total_duration(&self) -> Duration
Sourcepub fn has_overlaps(&self) -> bool
pub fn has_overlaps(&self) -> bool
Check if subtitle entries have any timing overlaps.
Returns true if any entry’s start time is before the previous
entry’s end time, indicating overlapping subtitles.
Sourcepub fn sort_entries(&mut self)
pub fn sort_entries(&mut self)
Sort entries by start time to ensure chronological order.
This method is useful after manual manipulation of entries or when merging subtitles from multiple sources.