subtitler

Crates.iosubtitler
lib.rssubtitler
version
sourcesrc
created_at2025-01-08 04:10:24.902156+00
updated_at2025-01-11 03:05:53.825101+00
descriptionSubtitler is a library for parsing and generating subtitles
homepage
repositoryhttps://github.com/subtitle-rs/subtitler
max_upload_size
id1508063
Cargo.toml error:TOML parse error at line 24, column 1 | 24 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
SiwiLiZhao (siwilizhao)

documentation

https://docs.rs/subtitler

README

Subtitler

subtitler is a library for parsing and generating subtitles

Crates.io Crates.io License Build Status Contributors

Install

cargo install subtitler

parse subtitle from url

subtitler url your_subtitle_url

parse subtitle from file

subtitler file your_subtitle_file

Examples

more examples

parse srt file

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(())
}
Commit count: 22

cargo fmt