Skip to main content

Crate lrc

Crate lrc 

Source
Expand description

§LRC

A pure Rust implementation of LyRiCs which is a computer file format that synchronizes song lyrics with an audio file.

§Examples

use lrc::{Lyrics, TimeTag};

let mut lyrics = Lyrics::new();

lyrics.metadata.set_title("Let's Twist Again").unwrap();
lyrics.metadata.set_album("Hits Of The 60's - Vol. 2 – Oldies").unwrap();

lyrics.add_timed_line(TimeTag::from_str("00:12.00").unwrap(), "Naku Penda Piya-Naku Taka Piya-Mpenziwe").unwrap();
lyrics.add_timed_line(TimeTag::from_str("00:15.30").unwrap(), "Some more lyrics").unwrap();


assert_eq!(
    r"[al: Hits Of The 60's - Vol. 2 – Oldies]
[ti: Let's Twist Again]

[00:12.00]Naku Penda Piya-Naku Taka Piya-Mpenziwe
[00:15.30]Some more lyrics",
    lyrics.to_string()
);
use lrc::{Lyrics, TimeTag};

let lyrics = Lyrics::from_str(r"[00:12.00][01:15.00]Naku Penda Piya-Naku Taka Piya-Mpenziwe
[00:15.30][01:18.00]Some more lyrics ...").unwrap();

assert_eq!(
    Some("Naku Penda Piya-Naku Taka Piya-Mpenziwe"),
    lyrics.line_at(TimeTag::from_str("00:13.00").unwrap())
);

let shifted = lyrics.shifted(1000);

assert_eq!(
    Some("Naku Penda Piya-Naku Taka Piya-Mpenziwe"),
    lyrics.line_at(TimeTag::from_str("00:12.00").unwrap())
);

assert_eq!(None, shifted.line_at(TimeTag::from_str("00:12.00").unwrap()));

assert_eq!(
    Some("Naku Penda Piya-Naku Taka Piya-Mpenziwe"),
    shifted.line_at(TimeTag::from_str("00:13.00").unwrap())
);
use std::io::Cursor;

use lrc::Lyrics;

let lyrics = Lyrics::from_reader(Cursor::new("[ti:Let's Twist Again]\n[00:12.00]Line")).unwrap();

assert_eq!(Some("Let's Twist Again"), lyrics.metadata.title());

let mut output = Vec::new();
lyrics.to_writer(&mut output).unwrap();

assert_eq!("[ti: Let's Twist Again]\n\n[00:12.00]Line", String::from_utf8(output).unwrap());

Re-exports§

pub use metadata::*;
pub use tags::*;

Modules§

metadata
Metadata helpers and storage.
tags
LRC tag types.

Structs§

Lyrics
A complete LRC document with metadata, timed lyric lines, and plain lyric lines.

Enums§

IDTagErrorKind
The invalid part of an ID tag.
LyricsError
Errors that can occur when parsing, building, or writing LRC data.