Struct SyncedLyrics
pub struct SyncedLyrics {
pub title: Option<String>,
pub artist: Option<String>,
pub album: Option<String>,
pub author: Option<String>,
pub lyricist: Option<String>,
pub length: Option<Duration>,
pub file_author: Option<String>,
pub tool: Option<LRCTool>,
pub comments: Vec<String>,
pub lines: Vec<LineTag>,
}Expand description
Lyrics grouped into timestamped segments with additional metadata.
Fields§
§title: Option<String>Title of the song.
artist: Option<String>Artist performing the song.
album: Option<String>Album the song is from.
Author of the song.
lyricist: Option<String>Lyricist of the song.
length: Option<Duration>Length of the song.
Author of the LRC file (not the song).
tool: Option<LRCTool>Info on the player or editor that created the LRC file.
comments: Vec<String>Comments found in the lyrics.
lines: Vec<LineTag>LRC segments grouped by lines.
Implementations§
§impl SyncedLyrics
impl SyncedLyrics
pub fn line(
&mut self,
line: LineTag,
) -> Result<&mut SyncedLyrics, TimestampError>
pub fn line( &mut self, line: LineTag, ) -> Result<&mut SyncedLyrics, TimestampError>
Adds a line to the lyrics.
Prefer using this method over manually adding lines to lyrics as it ensures that the
timestamp order stays correct. If you need to add lines manually, use the
check_timestamp_order method to verify the timestamp order.
pub fn lines(
&mut self,
lines: &[LineTag],
) -> Result<&mut SyncedLyrics, TimestampError>
pub fn lines( &mut self, lines: &[LineTag], ) -> Result<&mut SyncedLyrics, TimestampError>
Adds multiple lines to the lyrics.
Prefer using this method over manually adding lines to lyrics as it ensures that the
timestamp order stays correct. If you need to add lines manually, use the
check_timestamp_order method to verify the timestamp order.
pub fn try_new(tags: Vec<LineTag>) -> Result<SyncedLyrics, TimestampError>
pub fn try_new(tags: Vec<LineTag>) -> Result<SyncedLyrics, TimestampError>
Creates an empty synced lyrics struct with some timed tags.
Returns an error if the timestamp order is not correct.
pub fn serialize(self) -> String
pub fn serialize(self) -> String
Serialize the struct to LRC format.
NOTE: This method may not always produce the same output as the input parsed to create the data structure. For instance, the original placement of ID tags and comments is not preserved, and the offset tag is omitted as it is applied by the parser.
It should, however, always produce the same result for input serialized from its output.
For instance:
let input = include_str!("../assets/example.lrc");
let parsed = SyncedLyrics::parse(&input).unwrap();
let parsed_twice = SyncedLyrics::parse(&parsed.clone().serialize())
.unwrap()
.serialize();
assert_eq!(parsed.serialize(), parsed_twice);pub fn parse(input: &str) -> Result<SyncedLyrics, Error>
pub fn parse(input: &str) -> Result<SyncedLyrics, Error>
Parses LRC lyrics data.
§Examples
Parse some lyrics
let content = "[ti:My awesome song]
[00:02.50] La la la
[00:05.10] <00:05.10> La la la <00:06.30> la la la";
let lyrics = SyncedLyrics::parse(content).unwrap();Parser fails to parse content with invalid ID tags
let content = "[fun:I am an invalid ID tag]";
assert_eq!(
SyncedLyrics::parse(content),
Err(Error::UnknownKey { key: "fun".to_string() })
);Parser fails to parse content with invalid timestamp order
let content = "[00:02.10] First line
[00:01.90] My timestamp is wrong!";
assert_eq!(
SyncedLyrics::parse(content),
Err(Error::Timestamp(lrc_rs::TimestampError {
line: Some(1),
segment: None,
expected: lrc_rs::TimestampConstraint::GreaterThan(Duration::from_secs_f32(2.10)),
actual: Duration::from_secs_f32(1.9),
}))
);Trait Implementations§
§impl Clone for SyncedLyrics
impl Clone for SyncedLyrics
§fn clone(&self) -> SyncedLyrics
fn clone(&self) -> SyncedLyrics
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for SyncedLyrics
impl Debug for SyncedLyrics
§impl Default for SyncedLyrics
impl Default for SyncedLyrics
§fn default() -> SyncedLyrics
fn default() -> SyncedLyrics
impl Eq for SyncedLyrics
§impl Hash for SyncedLyrics
impl Hash for SyncedLyrics
§impl LyricsAccess<LineTag> for SyncedLyrics
impl LyricsAccess<LineTag> for SyncedLyrics
§fn is_active(&self, timestamp: Duration) -> bool
fn is_active(&self, timestamp: Duration) -> bool
Returns whether the lyrics are active for the given timestamp.
Lyrics are considered active if timestamp is greater than or equal to the timestamp of the
first line of the lyrics. The first line is assumed to have the earliest timestamp, so if
the line order is not correct this method may return wrong results.
§Examples
let lyrics = SyncedLyrics::try_new(vec![
LineTag {
// Checking whether lyrics are active is delegated to the first line
timestamp: Duration::from_secs(11),
segments: vec![
SegmentTag::new(Duration::from_secs(12), String::new()),
SegmentTag::new(Duration::from_secs(15), String::new())
]
},
// All other stuff doesn't matter
LineTag {
timestamp: Duration::from_secs(17),
segments: vec![SegmentTag::new(Duration::from_secs(17), String::new())]
}
])
.unwrap();
assert!(!lyrics.is_active(Duration::default()));
assert!(!lyrics.is_active(Duration::from_secs(3)));
assert!(lyrics.is_active(Duration::from_secs(11)));
assert!(lyrics.is_active(Duration::from_secs(67)));
assert!(lyrics.is_active(Duration::from_secs(u64::MAX)));§fn to_unsynced(self) -> String
fn to_unsynced(self) -> String
§fn active_tag_index(&self, timestamp: Duration) -> Option<usize>
fn active_tag_index(&self, timestamp: Duration) -> Option<usize>
§fn active_tag(&self, timestamp: Duration) -> Option<&LineTag>
fn active_tag(&self, timestamp: Duration) -> Option<&LineTag>
§fn check_timestamp_order(&self) -> Result<(), TimestampError>
fn check_timestamp_order(&self) -> Result<(), TimestampError>
§fn is_enhanced_lrc(&self) -> bool
fn is_enhanced_lrc(&self) -> bool
§impl Ord for SyncedLyrics
impl Ord for SyncedLyrics
§fn cmp(&self, other: &SyncedLyrics) -> Ordering
fn cmp(&self, other: &SyncedLyrics) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialEq for SyncedLyrics
impl PartialEq for SyncedLyrics
§impl PartialOrd for SyncedLyrics
impl PartialOrd for SyncedLyrics
impl StructuralPartialEq for SyncedLyrics
Auto Trait Implementations§
impl Freeze for SyncedLyrics
impl RefUnwindSafe for SyncedLyrics
impl Send for SyncedLyrics
impl Sync for SyncedLyrics
impl Unpin for SyncedLyrics
impl UnsafeUnpin for SyncedLyrics
impl UnwindSafe for SyncedLyrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().