pub mod srt;
pub mod ssa;
pub mod idx;
pub mod common;
use SubtitleFile;
use ParseSubtitleString;
use errors::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SubtitleFormat {
SubRip,
SubStationAlpha,
VobSubIdx,
}
pub fn get_subtitle_format_by_ending(path: &str) -> Option<SubtitleFormat> {
if path.ends_with(".srt") {
Some(SubtitleFormat::SubRip)
} else if path.ends_with(".ssa") || path.ends_with(".ass") {
Some(SubtitleFormat::SubStationAlpha)
} else if path.ends_with(".idx") {
Some(SubtitleFormat::VobSubIdx)
} else {
None
}
}
pub fn get_subtitle_format_by_ending_err(path: &str) -> Result<SubtitleFormat> {
match get_subtitle_format_by_ending(path) {
Some(format) => Ok(format),
None => Err(Error::from(ErrorKind::UnknownFileFormat)),
}
}
pub trait ClonableSubtitleFile: SubtitleFile {
fn clone(&self) -> Box<ClonableSubtitleFile>;
}
impl<T> ClonableSubtitleFile for T
where T: SubtitleFile + Clone + 'static
{
fn clone(&self) -> Box<ClonableSubtitleFile> {
Box::new(Clone::clone(self))
}
}
pub fn parse_file_from_string(format: SubtitleFormat, content: String) -> Result<Box<ClonableSubtitleFile>> {
match format {
SubtitleFormat::SubRip => Ok(Box::new(srt::SrtFile::parse_from_string(content)?)),
SubtitleFormat::SubStationAlpha => Ok(Box::new(ssa::SsaFile::parse_from_string(content)?)),
SubtitleFormat::VobSubIdx => Ok(Box::new(idx::IdxFile::parse_from_string(content)?)),
}
}