1 /*
2 * LRC lyrics file format decoder
3 * Copyright (c) 2014 StarBrilliant <m13253@hotmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <inttypes.h>
23 #include <stdint.h>
24 #include <string.h>
25
33
38
40 {
42 while(p[offset] == ' ' || p[offset] == '\t') {
43 offset++;
44 }
45 if(p[offset] == '[' && p[offset + 1] >= 'a' && p[offset + 1] <= 'z') {
47 } else {
48 return -1;
49 }
50 }
51
53 {
55 int in_brackets = 0;
56
57 for(;;) {
58 if(p[offset] == ' ' || p[offset] == '\t') {
59 offset++;
60 } else if(p[offset] == '[') {
61 offset++;
62 in_brackets++;
63 } else if (p[offset] == ']' && in_brackets) {
64 offset++;
65 in_brackets--;
66 } else if(in_brackets &&
67 (p[offset] == ':' || p[offset] == '.' || p[offset] == '-' ||
68 (p[offset] >= '0' && p[offset] <= '9'))) {
69 offset++;
70 } else {
71 break;
72 }
73 }
75 }
76
78 {
80 uint64_t mm, ss, cs;
81
82 while(p[offset] == ' ' || p[offset] == '\t') {
83 offset++;
84 }
85 if(p[offset] != '[') {
86 return 0;
87 }
88 if(sscanf(p, "[-%"SCNu64":%"SCNu64".%"SCNu64"]", &mm, &ss, &cs) == 3) {
89 /* Just in case negative pts, players may drop it but we won't. */
90 *start = -(int64_t) (mm*60000 + ss*1000 + cs*10);
91 } else if(sscanf(p, "[%"SCNu64":%"SCNu64".%"SCNu64"]", &mm, &ss, &cs) == 3) {
92 *start = mm*60000 + ss*1000 + cs*10;
93 } else {
94 return 0;
95 }
96 do {
97 offset++;
98 } while(p[offset] && p[offset-1] != ']');
100 }
101
103 {
105
109 if(c != '\r') {
111 }
112 if(c == '\n') {
113 break;
114 }
115 }
116 return pos;
117 }
118
120 {
122 int64_t mm;
123 uint64_t ss, cs;
125
126 if(!memcmp(p->
buf,
"\xef\xbb\xbf", 3)) {
// Skip UTF-8 BOM header
127 offset += 3;
128 }
129 while(p->
buf[offset] ==
'\n' || p->
buf[offset] ==
'\r') {
130 offset++;
131 }
132 if(p->
buf[offset] !=
'[') {
133 return 0;
134 }
135 offset++;
136 // Common metadata item but not exist in ff_lrc_metadata_conv
137 if(!memcmp(p->
buf + offset,
"offset:", 7)) {
138 return 40;
139 }
140 if(sscanf(p->
buf + offset,
"%"SCNd64
":%"SCNu64
".%"SCNu64
"]",
141 &mm, &ss, &cs) == 3) {
142 return 50;
143 }
144 // Metadata items exist in ff_lrc_metadata_conv
146 metadata_item->
native; metadata_item++) {
147 size_t metadata_item_len = strlen(metadata_item->
native);
148 if(p->
buf[offset + metadata_item_len] ==
':' &&
149 !memcmp(p->
buf + offset, metadata_item->
native, metadata_item_len)) {
150 return 40;
151 }
152 }
153 return 5; // Give it 5 scores since it starts with a bracket
154 }
155
157 {
161
163 if(!st) {
165 }
171
175 if(header_offset >= 0) {
176 char *comma_offset = strchr(line.str, ':');
177 if(comma_offset) {
178 char *right_bracket_offset = strchr(line.str, ']');
179 if(!right_bracket_offset) {
180 continue;
181 }
182
183 *right_bracket_offset = *comma_offset = '0円';
184 if(strcmp(line.str + 1, "offset") ||
185 sscanf(comma_offset + 1,
"%"SCNd64, &lrc->
ts_offset) != 1) {
187 }
188 *comma_offset = ':';
189 *right_bracket_offset = ']';
190 }
191
192 } else {
195 int64_t ts_stroffset = 0;
196 int64_t ts_stroffset_incr = 0;
197 int64_t ts_strlength =
count_ts(line.str);
198
199 while((ts_stroffset_incr =
read_ts(line.str + ts_stroffset,
200 &ts_start)) != 0) {
201 ts_stroffset += ts_stroffset_incr;
203 line.len - ts_strlength, 0);
204 if(!sub) {
206 }
210 }
211 }
212 }
215 return 0;
216 }
217
219 {
222 }
223
225 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
226 {
229 min_ts, ts, max_ts, flags);
230 }
231
233 {
236 return 0;
237 }
238
248 };