subx_cli/core/formats/
mod.rs1#![allow(dead_code)]
3
4pub mod ass;
5pub mod converter;
6pub mod encoding;
7pub mod manager;
8pub mod srt;
9pub mod styling;
10pub mod sub;
11pub mod transformers;
12pub mod vtt;
13
14use std::time::Duration;
15
16#[derive(Debug, Clone, PartialEq, Eq)]
18pub enum SubtitleFormatType {
19 Srt,
20 Ass,
21 Vtt,
22 Sub,
23}
24
25impl SubtitleFormatType {
26 pub fn as_str(&self) -> &'static str {
28 match self {
29 SubtitleFormatType::Srt => "srt",
30 SubtitleFormatType::Ass => "ass",
31 SubtitleFormatType::Vtt => "vtt",
32 SubtitleFormatType::Sub => "sub",
33 }
34 }
35}
36
37impl std::fmt::Display for SubtitleFormatType {
38 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39 write!(f, "{}", self.as_str())
40 }
41}
42
43#[derive(Debug, Clone)]
45pub struct Subtitle {
46 pub entries: Vec<SubtitleEntry>,
47 pub metadata: SubtitleMetadata,
48 pub format: SubtitleFormatType,
49}
50
51#[derive(Debug, Clone)]
53pub struct SubtitleEntry {
54 pub index: usize,
55 pub start_time: Duration,
56 pub end_time: Duration,
57 pub text: String,
58 pub styling: Option<StylingInfo>,
59}
60
61#[derive(Debug, Clone)]
63pub struct SubtitleMetadata {
64 pub title: Option<String>,
65 pub language: Option<String>,
66 pub encoding: String,
67 pub frame_rate: Option<f32>,
68 pub original_format: SubtitleFormatType,
69}
70
71#[derive(Debug, Clone, Default)]
73pub struct StylingInfo {
74 pub font_name: Option<String>,
75 pub font_size: Option<u32>,
76 pub color: Option<String>,
77 pub bold: bool,
78 pub italic: bool,
79 pub underline: bool,
80}
81
82pub trait SubtitleFormat {
84 fn parse(&self, content: &str) -> crate::Result<Subtitle>;
86
87 fn serialize(&self, subtitle: &Subtitle) -> crate::Result<String>;
89
90 fn detect(&self, content: &str) -> bool;
92
93 fn format_name(&self) -> &'static str;
95
96 fn file_extensions(&self) -> &'static [&'static str];
98}