aboutsummaryrefslogtreecommitdiff
path: root/README.markdown
blob: df43a02673a1c74d53d2bfc2604ed82535e1f4c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# NAME

Music::Lyrics::LRC - Manipulate LRC karaoke timed lyrics files

# VERSION

Version 0.15

# DESCRIPTION

Read, write, and do simple manipulations of the LRC lyrics files used for some
karaoke devices.

For details on the LRC file format, please see Wikipedia:

[https://en.wikipedia.org/wiki/LRC\_(file\_format)](https://en.wikipedia.org/wiki/LRC_\(file_format\))

# SYNOPSIS

    use Music::Lyrics::LRC;
    ...
    my $lrc = Music::Lyrics::LRC->new();
    open my $rfh, '<', 'mylyrics.lrc';
    $lrc->load($rfh);
    ...
    my $lyrics = $lrc->lyrics();  # arrayref of hashrefs: time (msec), text
    my $tags = $lrc->tags();  # hashref, name => value
    ...
    $lrc->add_lyric(5500, q(Now I'm singin' at exactly 5.5 seconds...));
    $lrc->set_tag('author', 'Justin A. Perlhacker');
    $lrc->unset_tag('author');
    ...
    open my $wfh, '>', 'savelyrics.lrc';
    $lrc->save($wfh);

# SUBROUTINES/METHODS

## `new(%opts)`

Constructor method. Accepts a hash with one attribute `verbose`. This
specifies whether the module will `warn` explicitly when it cannot parse an
input line from a file. It defaults to 0.

    my $lrc = Music::Lyrics::LRC->new();
    ...
    my $lrc_verbose = Music::Lyrics::LRC->new(verbose => 1);
    ...

## `lyrics()`

Retrieve an arrayref of hashrefs representing lyric lines, sorted by time
ascending. Each one has `time` and `text` keys. The time is in milliseconds.

    [
        {
            time => 5500,
            text => 'Now I\'m singin\' at exactly 5.5 seconds...',
        },
        {
            time => 6001,
            text => 'And now a moment after the sixth...',
        },
    ...
    ]

## `tags()`

Retrieve a hashref of tag names to tag values for this lyrics file.

    {
        ar => 'Justin A. Perlhacker',
        ti => 'Perl timekeeping blues',
        ...
    }

## `add_lyric($time, $text)`

Add a lyric at the given non-negative time in milliseconds and with the given
text. The text must not include newlines or carriage returns.

## `set_tag($name, $value)`

Set a tag with the given name and value. The name must be at least one
character and cannot have colons. Neither the name nor the value can include
newlines or carriage returns.

## `unset_tag($name)`

Clear a tag with the given name. Raises a warning if the tag has not been set.

## `load($fh)`

Load lyrics from the given readable filehandle.

## `save($fh)`

Save lyrics to the given writeable filehandle.

# DIAGNOSTICS

- `Bad lyric time`

    A lyric could not be added with the given time. It may have been negative.

- `Bad lyric line`

    The line you tried to add had illegal characters in it, probably a carriage
    return or a newline.

- `Bad tag name`

    The tag you tried to set had an illegal name. It needs to be at least one
    character, and can't include colons or whitespace.

- `Bad tag value`

    You tried to set a tag to an illegal value. The value probably had a carriage
    return or a newline in it.

- `Tag not set`

    You tried to clear a tag that had not already been set.

- `Unknown format for line %s`

    The parser ran across a line in the LRC file that it could not understand. It
    tolerates blank lines, tags, and lyric lines, and doesn't know anything else.

- `Failed file read: %s`

    The file read failed with the given system error.

- `Not a filehandle`

    You passed `load()` or `save()` something that wasn't a filehandle.

- `Failed tag write: %s`

    An attempt to write a tag to the output filehandle in `save()` failed with the
    given system error.

- `Failed lyric write: %s`

    An attempt to write a lyric timestamp and line to the output filehandle in
    `save()` failed with the given system error.

# CONFIGURATION AND ENVIRONMENT

You'll need to make sure that you're passing in a filehandle with the
appropriate I/O layers you want, especially encoding.

# DEPENDENCIES

- Perl 5.6 or newer
- [Carp](https://metacpan.org/pod/Carp)
- [English](https://metacpan.org/pod/English)

# INCOMPATIBILITIES

This module does not support any "extended" or "enhanced" LRC format; in
particular, at the time of writing it can't handle per-word times syntax. This
may change in future revisions.

# BUGS AND LIMITATIONS

The format accepted here is very liberal, and needs to be tested with lots of
different LRC files from the wild.

Fractional seconds of any length can be parsed, and preserved in the
millisecond count return by `lyrics()`, but any resolution beyond 2 decimal
places is lost on `save()`.

# AUTHOR

Tom Ryder `<tom@sanctum.geek.nz>`

# LICENSE AND COPYRIGHT

Copyright (C) 2017 Tom Ryder

This program is free software; you can redistribute it and/or modify it under
the terms of the Artistic License (2.0). You may obtain a copy of the full
license at:

[http://www.perlfoundation.org/artistic\_license\_2\_0](http://www.perlfoundation.org/artistic_license_2_0)

Any use, modification, and distribution of the Standard or Modified Versions is
governed by this Artistic License. By using, modifying or distributing the
Package, you accept this license. Do not use, modify, or distribute the
Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by
someone other than you, you are nevertheless required to ensure that your
Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark,
tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent
license to make, have made, use, offer to sell, sell, import and otherwise
transfer the Package with respect to any patent claims licensable by the
Copyright Holder that are necessarily infringed by the Package. If you
institute patent litigation (including a cross-claim or counterclaim) against
any party alleging that the Package constitutes direct or contributory patent
infringement, then this Artistic License to you shall terminate on the date
that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW.
UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY
OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.