diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-01 23:34:58 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-01 23:34:58 +1300 |
commit | e6ed59ed74d15143bc9260923aa1447a5a738838 (patch) | |
tree | 76fbbf6ac5380938dc08eb5789a401b62a0bfe21 | |
parent | Bump version number to 0.02 (diff) | |
download | Music-Lyrics-LRC-e6ed59ed74d15143bc9260923aa1447a5a738838.tar.gz Music-Lyrics-LRC-e6ed59ed74d15143bc9260923aa1447a5a738838.zip |
Sort returned and saved lyrics by time
-rw-r--r-- | lib/Music/Lyrics/LRC.pm | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/Music/Lyrics/LRC.pm b/lib/Music/Lyrics/LRC.pm index 0397a14..22ea875 100644 --- a/lib/Music/Lyrics/LRC.pm +++ b/lib/Music/Lyrics/LRC.pm @@ -91,10 +91,10 @@ sub new { return bless \%self, $class; } -# Read-only accessor for lyrics +# Read-only accessor for lyrics, sorted by time sub lyrics { - my $self = shift; - my @lyrics = @{ $self->{lyrics} }; + my $self = shift; + my @lyrics = sort { $a->{time} <=> $b->{time} } @{ $self->{lyrics} }; return \@lyrics; } @@ -203,8 +203,8 @@ sub save { or die "Failed tag write: $ERRNO\n"; } - # Iterate through lyrics - for my $lyric ( @{ $self->{lyrics} } ) { + # Iterate through lyrics (sorted by time) + for my $lyric ( @{ $self->lyrics } ) { # Convert milliseconds to timestamp hash my $msec = $lyric->{time}; |