| Crates.io | subtitler |
| lib.rs | subtitler |
| version | 0.0.4 |
| created_at | 2025-01-08 04:10:24.902156+00 |
| updated_at | 2025-01-11 03:05:53.825101+00 |
| description | Subtitler is a library for parsing and generating subtitles |
| homepage | |
| repository | https://github.com/subtitle-rs/subtitler |
| max_upload_size | |
| id | 1508063 |
| size | 63,513 |
subtitler is a library for parsing and generating subtitles
cargo install subtitler
subtitler url your_subtitle_url
subtitler file your_subtitle_file
more examples。
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("json error {0:?}")]
Json(#[from] serde_json::Error),
#[error("IO error {0:?}")]
IO(#[from] std::io::Error),
#[error("any error {0:?}")]
Any(#[from] anyhow::Error),
}
pub type Result<T> = std::result::Result<T, Error>;
#[macro_use]
extern crate tracing;
use std::env;
use std::path::PathBuf;
use subtitler::srt::parse_file;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;
#[tokio::main]
async fn main() -> Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let mut file_path: PathBuf = env::current_dir().expect("Failed to get current_dir");
file_path.push("examples/example.srt");
let subtitle = parse_file(file_path.to_str().unwrap()).await?;
info!("subtitle {:#?}", subtitle);
info!("subtitle json {}", serde_json::to_string_pretty(&subtitle)?);
Ok(())
}