OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 importScripts('function_sequence.js'); | 5 importScripts('function_sequence.js'); |
6 importScripts('function_parallel.js'); | 6 importScripts('function_parallel.js'); |
7 | 7 |
8 function Id3Parser(parent) { | 8 function Id3Parser(parent) { |
9 MetadataParser.call(this, parent, 'id3', /\.(mp3)$/i); | 9 MetadataParser.call(this, parent, 'id3', /\.(mp3)$/i); |
10 } | 10 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 249 |
250 this.log('Starting id3 parser for ' + file.name); | 250 this.log('Starting id3 parser for ' + file.name); |
251 | 251 |
252 var id3v1Parser = new FunctionSequence( | 252 var id3v1Parser = new FunctionSequence( |
253 'id3v1parser', | 253 'id3v1parser', |
254 [ | 254 [ |
255 /** | 255 /** |
256 * Reads last 128 bytes of file in bytebuffer, | 256 * Reads last 128 bytes of file in bytebuffer, |
257 * which passes further. | 257 * which passes further. |
258 * In last 128 bytes should be placed ID3v1 tag if available. | 258 * In last 128 bytes should be placed ID3v1 tag if available. |
259 * @param file - file which bytes to read. | 259 * @param {File} file File which bytes to read. |
260 */ | 260 */ |
261 function readTail(file) { | 261 function readTail(file) { |
262 util.readFileBytes(file, file.size - 128, file.size, | 262 util.readFileBytes(file, file.size - 128, file.size, |
263 this.nextStep, this.onError, this); | 263 this.nextStep, this.onError, this); |
264 }, | 264 }, |
265 | 265 |
266 /** | 266 /** |
267 * Attempts to extract ID3v1 tag from 128 bytes long ByteBuffer | 267 * Attempts to extract ID3v1 tag from 128 bytes long ByteBuffer |
268 * @param file file which tags are being extracted. | 268 * @param {File} file File which tags are being extracted. Could be used |
269 * Could be used for logging purposes. | 269 * for logging purposes. |
270 * @param {ByteReader} reader ByteReader of 128 bytes. | 270 * @param {ByteReader} reader ByteReader of 128 bytes. |
271 */ | 271 */ |
272 function extractId3v1(file, reader) { | 272 function extractId3v1(file, reader) { |
273 if (reader.readString(3) == 'TAG') { | 273 if (reader.readString(3) == 'TAG') { |
274 this.logger.vlog('id3v1 found'); | 274 this.logger.vlog('id3v1 found'); |
275 var id3v1 = metadata.id3v1 = {}; | 275 var id3v1 = metadata.id3v1 = {}; |
276 | 276 |
277 var title = reader.readNullTerminatedString(30).trim(); | 277 var title = reader.readNullTerminatedString(30).trim(); |
278 | 278 |
279 if (title.length > 0) { | 279 if (title.length > 0) { |
(...skipping 23 matching lines...) Expand all Loading... |
303 var id3v2Parser = new FunctionSequence( | 303 var id3v2Parser = new FunctionSequence( |
304 'id3v2parser', | 304 'id3v2parser', |
305 [ | 305 [ |
306 function readHead(file) { | 306 function readHead(file) { |
307 util.readFileBytes(file, 0, 10, this.nextStep, this.onError, | 307 util.readFileBytes(file, 0, 10, this.nextStep, this.onError, |
308 this); | 308 this); |
309 }, | 309 }, |
310 | 310 |
311 /** | 311 /** |
312 * Check if passed array of 10 bytes contains ID3 header. | 312 * Check if passed array of 10 bytes contains ID3 header. |
313 * @param file to check and continue reading if ID3 metadata found. | 313 * @param {File} file File to check and continue reading if ID3 |
314 * @param {ByteReader} reader reader to fill with stream bytes. | 314 * metadata found |
| 315 * @param {ByteReader} reader Reader to fill with stream bytes. |
315 */ | 316 */ |
316 function checkId3v2(file, reader) { | 317 function checkId3v2(file, reader) { |
317 if (reader.readString(3) == 'ID3') { | 318 if (reader.readString(3) == 'ID3') { |
318 this.logger.vlog('id3v2 found'); | 319 this.logger.vlog('id3v2 found'); |
319 var id3v2 = metadata.id3v2 = {}; | 320 var id3v2 = metadata.id3v2 = {}; |
320 id3v2.major = reader.readScalar(1, false); | 321 id3v2.major = reader.readScalar(1, false); |
321 id3v2.minor = reader.readScalar(1, false); | 322 id3v2.minor = reader.readScalar(1, false); |
322 id3v2.flags = reader.readScalar(1, false); | 323 id3v2.flags = reader.readScalar(1, false); |
323 id3v2.size = Id3Parser.readSynchSafe_(reader, 4); | 324 id3v2.size = Id3Parser.readSynchSafe_(reader, 4); |
324 | 325 |
325 util.readFileBytes(file, 10, 10 + id3v2.size, this.nextStep, | 326 util.readFileBytes(file, 10, 10 + id3v2.size, this.nextStep, |
326 this.onError, this); | 327 this.onError, this); |
327 } else { | 328 } else { |
328 this.finish(); | 329 this.finish(); |
329 } | 330 } |
330 }, | 331 }, |
331 | 332 |
332 /** | 333 /** |
333 * Extracts all ID3v2 frames from given bytebuffer. | 334 * Extracts all ID3v2 frames from given bytebuffer. |
334 * @param file being parsed. | 335 * @param {File} file File being parsed. |
335 * @param {ByteReader} reader to use for metadata extraction. | 336 * @param {ByteReader} reader Reader to use for metadata extraction. |
336 */ | 337 */ |
337 function extractFrames(file, reader) { | 338 function extractFrames(file, reader) { |
338 var id3v2 = metadata.id3v2; | 339 var id3v2 = metadata.id3v2; |
339 | 340 |
340 if ((id3v2.major > 2) && | 341 if ((id3v2.major > 2) && |
341 (id3v2.flags & Id3Parser.v2.FLAG_EXTENDED_HEADER != 0)) { | 342 (id3v2.flags & Id3Parser.v2.FLAG_EXTENDED_HEADER != 0)) { |
342 // Skip extended header if found | 343 // Skip extended header if found |
343 if (id3v2.major == 3) { | 344 if (id3v2.major == 3) { |
344 reader.seek(reader.readScalar(4, false) - 4); | 345 reader.seek(reader.readScalar(4, false) - 4); |
345 } else if (id3v2.major == 4) { | 346 } else if (id3v2.major == 4) { |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 TYER: 'ID3_YEAR', | 698 TYER: 'ID3_YEAR', |
698 WCOP: 'ID3_COPYRIGHT', | 699 WCOP: 'ID3_COPYRIGHT', |
699 WOAF: 'ID3_OFFICIAL_AUDIO_FILE_WEBPAGE', | 700 WOAF: 'ID3_OFFICIAL_AUDIO_FILE_WEBPAGE', |
700 WOAR: 'ID3_OFFICIAL_ARTIST', | 701 WOAR: 'ID3_OFFICIAL_ARTIST', |
701 WOAS: 'ID3_OFFICIAL_AUDIO_SOURCE_WEBPAGE', | 702 WOAS: 'ID3_OFFICIAL_AUDIO_SOURCE_WEBPAGE', |
702 WPUB: 'ID3_PUBLISHERS_OFFICIAL_WEBPAGE' | 703 WPUB: 'ID3_PUBLISHERS_OFFICIAL_WEBPAGE' |
703 } | 704 } |
704 }; | 705 }; |
705 | 706 |
706 MetadataDispatcher.registerParserClass(Id3Parser); | 707 MetadataDispatcher.registerParserClass(Id3Parser); |
OLD | NEW |