How to use id3 method in tracetest

Best JavaScript code snippet using tracetest

id3_parser.js

Source:id3_parser.js Github

copy

Full Screen

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 be3// found in the LICENSE file.4/**5 * Protocol + host parts of extension URL.6 *7 * The __FILE_NAME suffix is because the same string constant is used in8 * multiple JS files, and JavaScript doesn't have C's #define mechanism (which9 * only affects the file its in). Without the suffix, we'd have "constant10 * FILE_MANAGER_HOST assigned a value more than once" compiler warnings.11 *12 * @type {string}13 * @const14 */15var FILE_MANAGER_HOST__ID3_PARSER =16 'chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj';17importScripts(18 FILE_MANAGER_HOST__ID3_PARSER +19 '/foreground/js/metadata/function_sequence.js');20importScripts(21 FILE_MANAGER_HOST__ID3_PARSER +22 '/foreground/js/metadata/function_parallel.js');23/**24 * ID3 parser.25 *26 * @param {MetadataParserLogger} parent A metadata dispatcher.27 * @constructor28 * @struct29 * @extends {MetadataParser}30 */31function Id3Parser(parent) {32 MetadataParser.call(this, parent, 'id3', /\.(mp3)$/i);33}34Id3Parser.prototype.__proto__ = MetadataParser.prototype;35/**36 * Reads synchsafe integer.37 * 'SynchSafe' term is taken from id3 documentation.38 *39 * @param {ByteReader} reader Reader to use.40 * @param {number} length Rytes to read.41 * @return {number} Synchsafe value.42 * @private43 */44Id3Parser.readSynchSafe_ = function(reader, length) {45 var rv = 0;46 switch (length) {47 case 4:48 rv = reader.readScalar(1, false) << 21;49 case 3:50 rv |= reader.readScalar(1, false) << 14;51 case 2:52 rv |= reader.readScalar(1, false) << 7;53 case 1:54 rv |= reader.readScalar(1, false);55 }56 return rv;57};58/**59 * Reads 3bytes integer.60 *61 * @param {ByteReader} reader Reader to use.62 * @return {number} Uint24 value.63 * @private64 */65Id3Parser.readUInt24_ = function(reader) {66 return reader.readScalar(2, false) << 16 | reader.readScalar(1, false);67};68/**69 * Reads string from reader with specified encoding70 *71 * @param {ByteReader} reader Reader to use.72 * @param {number} encoding String encoding.73 * @param {number} size Maximum string size. Actual result may be shorter.74 * @return {string} String value.75 * @private76 */77Id3Parser.prototype.readString_ = function(reader, encoding, size) {78 switch (encoding) {79 case Id3Parser.v2.ENCODING.ISO_8859_1:80 return reader.readNullTerminatedString(size);81 case Id3Parser.v2.ENCODING.UTF_16:82 return reader.readNullTerminatedStringUTF16(true, size);83 case Id3Parser.v2.ENCODING.UTF_16BE:84 return reader.readNullTerminatedStringUTF16(false, size);85 case Id3Parser.v2.ENCODING.UTF_8:86 // TODO: implement UTF_8.87 this.log('UTF8 encoding not supported, used ISO_8859_1 instead');88 return reader.readNullTerminatedString(size);89 default: {90 this.log('Unsupported encoding in ID3 tag: ' + encoding);91 return '';92 }93 }94};95/**96 * Reads text frame from reader.97 *98 * @param {ByteReader} reader Reader to use.99 * @param {number} majorVersion Major id3 version to use.100 * @param {Object} frame Frame so store data at.101 * @param {number} end Frame end position in reader.102 * @private103 */104Id3Parser.prototype.readTextFrame_ = function(reader,105 majorVersion,106 frame,107 end) {108 frame.encoding = reader.readScalar(1, false, end);109 frame.value = this.readString_(reader, frame.encoding, end - reader.tell());110};111/**112 * Reads user defined text frame from reader.113 *114 * @param {ByteReader} reader Reader to use.115 * @param {number} majorVersion Major id3 version to use.116 * @param {Object} frame Frame so store data at.117 * @param {number} end Frame end position in reader.118 * @private119 */120Id3Parser.prototype.readUserDefinedTextFrame_ = function(reader,121 majorVersion,122 frame,123 end) {124 frame.encoding = reader.readScalar(1, false, end);125 frame.description = this.readString_(126 reader,127 frame.encoding,128 end - reader.tell());129 frame.value = this.readString_(130 reader,131 frame.encoding,132 end - reader.tell());133};134/**135 * @param {ByteReader} reader Reader to use.136 * @param {number} majorVersion Major id3 version to use.137 * @param {Object} frame Frame so store data at.138 * @param {number} end Frame end position in reader.139 * @private140 */141Id3Parser.prototype.readPIC_ = function(reader, majorVersion, frame, end) {142 frame.encoding = reader.readScalar(1, false, end);143 frame.format = reader.readNullTerminatedString(3, end - reader.tell());144 frame.pictureType = reader.readScalar(1, false, end);145 frame.description = this.readString_(reader,146 frame.encoding,147 end - reader.tell());148 if (frame.format == '-->') {149 frame.imageUrl = reader.readNullTerminatedString(end - reader.tell());150 } else {151 frame.imageUrl = reader.readImage(end - reader.tell());152 }153};154/**155 * @param {ByteReader} reader Reader to use.156 * @param {number} majorVersion Major id3 version to use.157 * @param {Object} frame Frame so store data at.158 * @param {number} end Frame end position in reader.159 * @private160 */161Id3Parser.prototype.readAPIC_ = function(reader, majorVersion, frame, end) {162 this.vlog('Extracting picture');163 frame.encoding = reader.readScalar(1, false, end);164 frame.mime = reader.readNullTerminatedString(end - reader.tell());165 frame.pictureType = reader.readScalar(1, false, end);166 frame.description = this.readString_(167 reader,168 frame.encoding,169 end - reader.tell());170 if (frame.mime == '-->') {171 frame.imageUrl = reader.readNullTerminatedString(end - reader.tell());172 } else {173 frame.imageUrl = reader.readImage(end - reader.tell());174 }175};176/**177 * Reads string from reader with specified encoding178 *179 * @param {ByteReader} reader Reader to use.180 * @param {number} majorVersion Major id3 version to use.181 * @return {Object} Frame read.182 * @private183 */184Id3Parser.prototype.readFrame_ = function(reader, majorVersion) {185 if (reader.eof())186 return null;187 var frame = {};188 reader.pushSeek(reader.tell(), ByteReader.SEEK_BEG);189 var position = reader.tell();190 frame.name = (majorVersion == 2) ? reader.readNullTerminatedString(3) :191 reader.readNullTerminatedString(4);192 if (frame.name == '')193 return null;194 this.vlog('Found frame ' + (frame.name) + ' at position ' + position);195 switch (majorVersion) {196 case 2:197 frame.size = Id3Parser.readUInt24_(reader);198 frame.headerSize = 6;199 break;200 case 3:201 frame.size = reader.readScalar(4, false);202 frame.headerSize = 10;203 frame.flags = reader.readScalar(2, false);204 break;205 case 4:206 frame.size = Id3Parser.readSynchSafe_(reader, 4);207 frame.headerSize = 10;208 frame.flags = reader.readScalar(2, false);209 break;210 }211 this.vlog('Found frame [' + frame.name + '] with size [' + frame.size + ']');212 if (Id3Parser.v2.HANDLERS[frame.name]) {213 Id3Parser.v2.HANDLERS[frame.name].call(214 this,215 reader,216 majorVersion,217 frame,218 reader.tell() + frame.size);219 } else if (frame.name.charAt(0) == 'T' || frame.name.charAt(0) == 'W') {220 this.readTextFrame_(221 reader,222 majorVersion,223 frame,224 reader.tell() + frame.size);225 }226 reader.popSeek();227 reader.seek(frame.size + frame.headerSize, ByteReader.SEEK_CUR);228 return frame;229};230/**231 * @param {File} file File object to parse.232 * @param {Object} metadata Metadata object of the file.233 * @param {function(Object)} callback Success callback.234 * @param {function(string)} onError Error callback.235 */236Id3Parser.prototype.parse = function(file, metadata, callback, onError) {237 var self = this;238 this.log('Starting id3 parser for ' + file.name);239 var id3v1Parser = new FunctionSequence(240 'id3v1parser',241 [242 /**243 * Reads last 128 bytes of file in bytebuffer,244 * which passes further.245 * In last 128 bytes should be placed ID3v1 tag if available.246 * @param {File} file File which bytes to read.247 */248 function readTail(file) {249 MetadataParser.readFileBytes(file, file.size - 128, file.size,250 this.nextStep, this.onError);251 },252 /**253 * Attempts to extract ID3v1 tag from 128 bytes long ByteBuffer254 * @param {File} file File which tags are being extracted. Could be used255 * for logging purposes.256 * @param {ByteReader} reader ByteReader of 128 bytes.257 */258 function extractId3v1(file, reader) {259 if (reader.readString(3) == 'TAG') {260 this.logger.vlog('id3v1 found');261 var id3v1 = metadata.id3v1 = {};262 var title = reader.readNullTerminatedString(30).trim();263 if (title.length > 0) {264 metadata.title = title;265 }266 reader.seek(3 + 30, ByteReader.SEEK_BEG);267 var artist = reader.readNullTerminatedString(30).trim();268 if (artist.length > 0) {269 metadata.artist = artist;270 }271 reader.seek(3 + 30 + 30, ByteReader.SEEK_BEG);272 var album = reader.readNullTerminatedString(30).trim();273 if (album.length > 0) {274 metadata.album = album;275 }276 }277 this.nextStep();278 }279 ],280 this,281 function() {},282 function(error) {});283 var id3v2Parser = new FunctionSequence(284 'id3v2parser',285 [286 function readHead(file) {287 MetadataParser.readFileBytes(file, 0, 10, this.nextStep,288 this.onError);289 },290 /**291 * Check if passed array of 10 bytes contains ID3 header.292 * @param {File} file File to check and continue reading if ID3293 * metadata found.294 * @param {ByteReader} reader Reader to fill with stream bytes.295 */296 function checkId3v2(file, reader) {297 if (reader.readString(3) == 'ID3') {298 this.logger.vlog('id3v2 found');299 var id3v2 = metadata.id3v2 = {};300 id3v2.major = reader.readScalar(1, false);301 id3v2.minor = reader.readScalar(1, false);302 id3v2.flags = reader.readScalar(1, false);303 id3v2.size = Id3Parser.readSynchSafe_(reader, 4);304 MetadataParser.readFileBytes(file, 10, 10 + id3v2.size,305 this.nextStep, this.onError);306 } else {307 this.finish();308 }309 },310 /**311 * Extracts all ID3v2 frames from given bytebuffer.312 * @param {File} file File being parsed.313 * @param {ByteReader} reader Reader to use for metadata extraction.314 */315 function extractFrames(file, reader) {316 var id3v2 = metadata.id3v2;317 if ((id3v2.major > 2) &&318 (id3v2.flags & Id3Parser.v2.FLAG_EXTENDED_HEADER != 0)) {319 // Skip extended header if found320 if (id3v2.major == 3) {321 reader.seek(reader.readScalar(4, false) - 4);322 } else if (id3v2.major == 4) {323 reader.seek(Id3Parser.readSynchSafe_(reader, 4) - 4);324 }325 }326 var frame;327 while (frame = self.readFrame_(reader, id3v2.major)) {328 metadata.id3v2[frame.name] = frame;329 }330 this.nextStep();331 },332 /**333 * Adds 'description' object to metadata.334 * 'description' used to unify different parsers and make335 * metadata parser-aware.336 * Description is array if value-type pairs. Type should be used337 * to properly format value before displaying to user.338 */339 function prepareDescription() {340 var id3v2 = metadata.id3v2;341 if (id3v2['APIC'])342 metadata.thumbnailURL = id3v2['APIC'].imageUrl;343 else if (id3v2['PIC'])344 metadata.thumbnailURL = id3v2['PIC'].imageUrl;345 metadata.description = [];346 for (var key in id3v2) {347 if (typeof(Id3Parser.v2.MAPPERS[key]) != 'undefined' &&348 id3v2[key].value.trim().length > 0) {349 metadata.description.push({350 key: Id3Parser.v2.MAPPERS[key],351 value: id3v2[key].value.trim()352 });353 }354 }355 /**356 * @param {string} propName357 * @param {...string} tags358 */359 function extract(propName, tags) {360 for (var i = 1; i != arguments.length; i++) {361 var tag = id3v2[arguments[i]];362 if (tag && tag.value) {363 metadata[propName] = tag.value;364 break;365 }366 }367 }368 extract('album', 'TALB', 'TAL');369 extract('title', 'TIT2', 'TT2');370 extract('artist', 'TPE1', 'TP1');371 metadata.description.sort(function(a, b) {372 return Id3Parser.METADATA_ORDER.indexOf(a.key) -373 Id3Parser.METADATA_ORDER.indexOf(b.key);374 });375 this.nextStep();376 }377 ],378 this,379 function() {},380 function(error) {});381 var metadataParser = new FunctionParallel(382 'mp3metadataParser',383 [id3v1Parser, id3v2Parser],384 this,385 function() {386 callback.call(null, metadata);387 },388 onError);389 id3v1Parser.setCallback(metadataParser.nextStep);390 id3v2Parser.setCallback(metadataParser.nextStep);391 id3v1Parser.setFailureCallback(metadataParser.onError);392 id3v2Parser.setFailureCallback(metadataParser.onError);393 this.vlog('Passed argument : ' + file);394 metadataParser.start(file);395};396/**397 * Metadata order to use for metadata generation398 * @type {Array<string>}399 * @const400 */401Id3Parser.METADATA_ORDER = [402 'ID3_TITLE',403 'ID3_LEAD_PERFORMER',404 'ID3_YEAR',405 'ID3_ALBUM',406 'ID3_TRACK_NUMBER',407 'ID3_BPM',408 'ID3_COMPOSER',409 'ID3_DATE',410 'ID3_PLAYLIST_DELAY',411 'ID3_LYRICIST',412 'ID3_FILE_TYPE',413 'ID3_TIME',414 'ID3_LENGTH',415 'ID3_FILE_OWNER',416 'ID3_BAND',417 'ID3_COPYRIGHT',418 'ID3_OFFICIAL_AUDIO_FILE_WEBPAGE',419 'ID3_OFFICIAL_ARTIST',420 'ID3_OFFICIAL_AUDIO_SOURCE_WEBPAGE',421 'ID3_PUBLISHERS_OFFICIAL_WEBPAGE'422];423/**424 * Id3v1 constants.425 * @type {Object<*>}426 */427Id3Parser.v1 = {428 /**429 * Genres list as described in id3 documentation. We aren't going to430 * localize this list, because at least in Russian (and I think most431 * other languages), translation exists at least for 10% and most time432 * translation would degrade to transliteration.433 */434 GENRES: [435 'Blues',436 'Classic Rock',437 'Country',438 'Dance',439 'Disco',440 'Funk',441 'Grunge',442 'Hip-Hop',443 'Jazz',444 'Metal',445 'New Age',446 'Oldies',447 'Other',448 'Pop',449 'R&B',450 'Rap',451 'Reggae',452 'Rock',453 'Techno',454 'Industrial',455 'Alternative',456 'Ska',457 'Death Metal',458 'Pranks',459 'Soundtrack',460 'Euro-Techno',461 'Ambient',462 'Trip-Hop',463 'Vocal',464 'Jazz+Funk',465 'Fusion',466 'Trance',467 'Classical',468 'Instrumental',469 'Acid',470 'House',471 'Game',472 'Sound Clip',473 'Gospel',474 'Noise',475 'AlternRock',476 'Bass',477 'Soul',478 'Punk',479 'Space',480 'Meditative',481 'Instrumental Pop',482 'Instrumental Rock',483 'Ethnic',484 'Gothic',485 'Darkwave',486 'Techno-Industrial',487 'Electronic',488 'Pop-Folk',489 'Eurodance',490 'Dream',491 'Southern Rock',492 'Comedy',493 'Cult',494 'Gangsta',495 'Top 40',496 'Christian Rap',497 'Pop/Funk',498 'Jungle',499 'Native American',500 'Cabaret',501 'New Wave',502 'Psychadelic',503 'Rave',504 'Showtunes',505 'Trailer',506 'Lo-Fi',507 'Tribal',508 'Acid Punk',509 'Acid Jazz',510 'Polka',511 'Retro',512 'Musical',513 'Rock & Roll',514 'Hard Rock',515 'Folk',516 'Folk-Rock',517 'National Folk',518 'Swing',519 'Fast Fusion',520 'Bebob',521 'Latin',522 'Revival',523 'Celtic',524 'Bluegrass',525 'Avantgarde',526 'Gothic Rock',527 'Progressive Rock',528 'Psychedelic Rock',529 'Symphonic Rock',530 'Slow Rock',531 'Big Band',532 'Chorus',533 'Easy Listening',534 'Acoustic',535 'Humour',536 'Speech',537 'Chanson',538 'Opera',539 'Chamber Music',540 'Sonata',541 'Symphony',542 'Booty Bass',543 'Primus',544 'Porn Groove',545 'Satire',546 'Slow Jam',547 'Club',548 'Tango',549 'Samba',550 'Folklore',551 'Ballad',552 'Power Ballad',553 'Rhythmic Soul',554 'Freestyle',555 'Duet',556 'Punk Rock',557 'Drum Solo',558 'A capella',559 'Euro-House',560 'Dance Hall',561 'Goa',562 'Drum & Bass',563 'Club-House',564 'Hardcore',565 'Terror',566 'Indie',567 'BritPop',568 'Negerpunk',569 'Polsk Punk',570 'Beat',571 'Christian Gangsta Rap',572 'Heavy Metal',573 'Black Metal',574 'Crossover',575 'Contemporary Christian',576 'Christian Rock',577 'Merengue',578 'Salsa',579 'Thrash Metal',580 'Anime',581 'Jpop',582 'Synthpop'583 ]584};585/**586 * Id3v2 constants.587 * @type {Object<*>}588 */589Id3Parser.v2 = {590 FLAG_EXTENDED_HEADER: 1 << 5,591 ENCODING: {592 /**593 * ISO-8859-1 [ISO-8859-1]. Terminated with $00.594 *595 * @const596 * @type {number}597 */598 ISO_8859_1: 0,599 /**600 * [UTF-16] encoded Unicode [UNICODE] with BOM. All601 * strings in the same frame SHALL have the same byteorder.602 * Terminated with $00 00.603 *604 * @const605 * @type {number}606 */607 UTF_16: 1,608 /**609 * UTF-16BE [UTF-16] encoded Unicode [UNICODE] without BOM.610 * Terminated with $00 00.611 *612 * @const613 * @type {number}614 */615 UTF_16BE: 2,616 /**617 * UTF-8 [UTF-8] encoded Unicode [UNICODE]. Terminated with $00.618 *619 * @const620 * @type {number}621 */622 UTF_8: 3623 },624 HANDLERS: {625 //User defined text information frame626 TXX: Id3Parser.prototype.readUserDefinedTextFrame_,627 //User defined URL link frame628 WXX: Id3Parser.prototype.readUserDefinedTextFrame_,629 //User defined text information frame630 TXXX: Id3Parser.prototype.readUserDefinedTextFrame_,631 //User defined URL link frame632 WXXX: Id3Parser.prototype.readUserDefinedTextFrame_,633 //User attached image634 PIC: Id3Parser.prototype.readPIC_,635 //User attached image636 APIC: Id3Parser.prototype.readAPIC_637 },638 MAPPERS: {639 TALB: 'ID3_ALBUM',640 TBPM: 'ID3_BPM',641 TCOM: 'ID3_COMPOSER',642 TDAT: 'ID3_DATE',643 TDLY: 'ID3_PLAYLIST_DELAY',644 TEXT: 'ID3_LYRICIST',645 TFLT: 'ID3_FILE_TYPE',646 TIME: 'ID3_TIME',647 TIT2: 'ID3_TITLE',648 TLEN: 'ID3_LENGTH',649 TOWN: 'ID3_FILE_OWNER',650 TPE1: 'ID3_LEAD_PERFORMER',651 TPE2: 'ID3_BAND',652 TRCK: 'ID3_TRACK_NUMBER',653 TYER: 'ID3_YEAR',654 WCOP: 'ID3_COPYRIGHT',655 WOAF: 'ID3_OFFICIAL_AUDIO_FILE_WEBPAGE',656 WOAR: 'ID3_OFFICIAL_ARTIST',657 WOAS: 'ID3_OFFICIAL_AUDIO_SOURCE_WEBPAGE',658 WPUB: 'ID3_PUBLISHERS_OFFICIAL_WEBPAGE'659 }660};...

Full Screen

Full Screen

id3.js

Source:id3.js Github

copy

Full Screen

1/**2 * ID3 parser3 */4 class ID3 {5 /**6 * Returns true if an ID3 header can be found at offset in data7 * @param {Uint8Array} data - The data to search in8 * @param {number} offset - The offset at which to start searching9 * @return {boolean} - True if an ID3 header is found10 */11 static isHeader(data, offset) {12 /*13 * http://id3.org/id3v2.3.014 * [0] = 'I'15 * [1] = 'D'16 * [2] = '3'17 * [3,4] = {Version}18 * [5] = {Flags}19 * [6-9] = {ID3 Size}20 *21 * An ID3v2 tag can be detected with the following pattern:22 * $49 44 33 yy yy xx zz zz zz zz23 * Where yy is less than $FF, xx is the 'flags' byte and zz is less than $8024 */25 if (offset + 10 <= data.length) {26 //look for 'ID3' identifier27 if (data[offset] === 0x49 && data[offset+1] === 0x44 && data[offset+2] === 0x33) {28 //check version is within range29 if (data[offset+3] < 0xFF && data[offset+4] < 0xFF) {30 //check size is within range31 if (data[offset+6] < 0x80 && data[offset+7] < 0x80 && data[offset+8] < 0x80 && data[offset+9] < 0x80) {32 return true;33 }34 }35 }36 }37 return false;38 }39 /**40 * Returns true if an ID3 footer can be found at offset in data41 * @param {Uint8Array} data - The data to search in42 * @param {number} offset - The offset at which to start searching43 * @return {boolean} - True if an ID3 footer is found44 */45 static isFooter(data, offset) {46 /*47 * The footer is a copy of the header, but with a different identifier48 */49 if (offset + 10 <= data.length) {50 //look for '3DI' identifier51 if (data[offset] === 0x33 && data[offset+1] === 0x44 && data[offset+2] === 0x49) {52 //check version is within range53 if (data[offset+3] < 0xFF && data[offset+4] < 0xFF) {54 //check size is within range55 if (data[offset+6] < 0x80 && data[offset+7] < 0x80 && data[offset+8] < 0x80 && data[offset+9] < 0x80) {56 return true;57 }58 }59 }60 }61 return false;62 }63 /**64 * Returns any adjacent ID3 tags found in data starting at offset, as one block of data65 * @param {Uint8Array} data - The data to search in66 * @param {number} offset - The offset at which to start searching67 * @return {Uint8Array} - The block of data containing any ID3 tags found68 */69 static getID3Data(data, offset) {70 const front = offset;71 let length = 0;72 while (ID3.isHeader(data, offset)) {73 //ID3 header is 10 bytes74 length += 10;75 const size = ID3._readSize(data, offset + 6);76 length += size;77 if (ID3.isFooter(data, offset + 10)) {78 //ID3 footer is 10 bytes79 length += 10;80 }81 offset += length;82 }83 if (length > 0) {84 return data.subarray(front, front + length);85 }86 return undefined;87 }88 static _readSize(data, offset) {89 let size = 0;90 size = ((data[offset] & 0x7f) << 21);91 size |= ((data[offset+1] & 0x7f) << 14);92 size |= ((data[offset+2] & 0x7f) << 7);93 size |= (data[offset+3] & 0x7f);94 return size;95 }96 /**97 * Searches for the Elementary Stream timestamp found in the ID3 data chunk98 * @param {Uint8Array} data - Block of data containing one or more ID3 tags99 * @return {number} - The timestamp100 */101 static getTimeStamp(data) {102 const frames = ID3.getID3Frames(data);103 for(let i = 0; i < frames.length; i++) {104 const frame = frames[i];105 if (ID3.isTimeStampFrame(frame)) {106 return ID3._readTimeStamp(frame);107 }108 }109 return undefined;110 }111 /**112 * Returns true if the ID3 frame is an Elementary Stream timestamp frame113 * @param {ID3 frame} frame114 */115 static isTimeStampFrame(frame) {116 return (frame && frame.key === 'PRIV' && frame.info === 'com.apple.streaming.transportStreamTimestamp');117 }118 static _getFrameData(data) {119 /*120 Frame ID $xx xx xx xx (four characters)121 Size $xx xx xx xx122 Flags $xx xx123 */124 const type = String.fromCharCode(data[0], data[1], data[2], data[3]);125 const size = ID3._readSize(data, 4);126 //skip frame id, size, and flags127 let offset = 10;128 return { type, size, data: data.subarray(offset, offset + size) };129 }130 /**131 * Returns an array of ID3 frames found in all the ID3 tags in the id3Data132 * @param {Uint8Array} id3Data - The ID3 data containing one or more ID3 tags133 * @return {ID3 frame[]} - Array of ID3 frame objects134 */135 static getID3Frames(id3Data) {136 let offset = 0;137 const frames = [];138 while (ID3.isHeader(id3Data, offset)) {139 const size = ID3._readSize(id3Data, offset + 6);140 //skip past ID3 header141 offset += 10;142 const end = offset + size;143 //loop through frames in the ID3 tag144 while (offset + 8 < end) {145 const frameData = ID3._getFrameData(id3Data.subarray(offset));146 const frame = ID3._decodeFrame(frameData);147 if (frame) {148 frames.push(frame);149 }150 //skip frame header and frame data151 offset += frameData.size + 10;152 }153 if (ID3.isFooter(id3Data, offset)) {154 offset += 10;155 }156 }157 return frames;158 }159 static _decodeFrame(frame) {160 if (frame.type === 'PRIV') {161 return ID3._decodePrivFrame(frame);162 } else if (frame.type[0] === 'T') {163 return ID3._decodeTextFrame(frame);164 } else if (frame.type[0] === 'W') {165 return ID3._decodeURLFrame(frame);166 }167 return undefined;168 }169 static _readTimeStamp(timeStampFrame) {170 if (timeStampFrame.data.byteLength === 8) {171 const data = new Uint8Array(timeStampFrame.data);172 // timestamp is 33 bit expressed as a big-endian eight-octet number,173 // with the upper 31 bits set to zero.174 const pts33Bit = data[3] & 0x1;175 let timestamp = (data[4] << 23) +176 (data[5] << 15) +177 (data[6] << 7) +178 data[7];179 timestamp /= 45;180 if (pts33Bit) {181 timestamp += 47721858.84; // 2^32 / 90182 }183 return Math.round(timestamp);184 }185 return undefined;186 }187 static _decodePrivFrame(frame) {188 /*189 Format: <text string>\0<binary data>190 */191 if (frame.size < 2) {192 return undefined;193 }194 const owner = ID3._utf8ArrayToStr(frame.data);195 const privateData = new Uint8Array(frame.data.subarray(owner.length + 1));196 return { key: frame.type, info: owner, data: privateData.buffer };197 }198 static _decodeTextFrame(frame) {199 if (frame.size < 2) {200 return undefined;201 }202 if (frame.type === 'TXXX') {203 /*204 Format:205 [0] = {Text Encoding}206 [1-?] = {Description}\0{Value}207 */208 let index = 1;209 const description = ID3._utf8ArrayToStr(frame.data.subarray(index));210 index += description.length + 1;211 const value = ID3._utf8ArrayToStr(frame.data.subarray(index));212 return { key: frame.type, info: description, data: value };213 } else {214 /*215 Format:216 [0] = {Text Encoding}217 [1-?] = {Value}218 */219 const text = ID3._utf8ArrayToStr(frame.data.subarray(1));220 return { key: frame.type, data: text };221 }222 }223 static _decodeURLFrame(frame) {224 if (frame.type === 'WXXX') {225 /*226 Format:227 [0] = {Text Encoding}228 [1-?] = {Description}\0{URL}229 */230 if (frame.size < 2) {231 return undefined;232 }233 let index = 1;234 const description = ID3._utf8ArrayToStr(frame.data.subarray(index));235 index += description.length + 1;236 const value = ID3._utf8ArrayToStr(frame.data.subarray(index));237 return { key: frame.type, info: description, data: value };238 } else {239 /*240 Format:241 [0-?] = {URL}242 */243 const url = ID3._utf8ArrayToStr(frame.data);244 return { key: frame.type, data: url };245 }246 }247 // http://stackoverflow.com/questions/8936984/uint8array-to-string-in-javascript/22373197248 // http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt249 /* utf.js - UTF-8 <=> UTF-16 convertion250 *251 * Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>252 * Version: 1.0253 * LastModified: Dec 25 1999254 * This library is free. You can redistribute it and/or modify it.255 */256 static _utf8ArrayToStr(array) {257 let char2;258 let char3;259 let out = '';260 let i = 0;261 let length = array.length;262 while (i < length) {263 let c = array[i++];264 switch (c >> 4) {265 case 0:266 return out;267 case 1: case 2: case 3: case 4: case 5: case 6: case 7:268 // 0xxxxxxx269 out += String.fromCharCode(c);270 break;271 case 12: case 13:272 // 110x xxxx 10xx xxxx273 char2 = array[i++];274 out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));275 break;276 case 14:277 // 1110 xxxx 10xx xxxx 10xx xxxx278 char2 = array[i++];279 char3 = array[i++];280 out += String.fromCharCode(((c & 0x0F) << 12) |281 ((char2 & 0x3F) << 6) |282 ((char3 & 0x3F) << 0));283 break;284 }285 }286 return out;287 }288}...

Full Screen

Full Screen

common.js

Source:common.js Github

copy

Full Screen

1window.addEventListener("load", loader, false);2function loader(){3 var liElems = document.getElementsByTagName("li");4 var iElem, // Elem <i>5 liElem, // Elem <li>6 ulElem, // Elem <Ul>7 liElemIdFest,8 liElemIdLast;9 var arrayItemsLiId = [];10 document.addEventListener("click", clickItem, false);11 function clickItem(e){ // event target12 var iElem = e.target;13 var liElem = e.target.parentNode;14 var liElemId = liElem.id;15 var liElemIdFest = +liElemId.charAt(liElemId.length - 2); //penultimate number id Item - Li16 var liElemIdLast = +liElemId.charAt(liElemId.length - 1); //last nomber id Item - Li17 matrixSquea(liElemIdFest, liElemIdLast);18 function matrixSquea(liId3, liId4) {19 if (liId3 === 0 && liId4 === 0){20 target(liId3, liId4);21 right(liId3, liId4);22 down(liId3, liId4);23 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));24 } else if (liId3 === 6 && liId4 === 0){25 target(liId3, liId4);26 right(liId3, liId4);27 up(liId3, liId4);28 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));29 } else if (liId3 === 0 && liId4 === 5){30 target(liId3, liId4);31 left(liId3, liId4);32 down(liId3, liId4);33 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));34 } else if (liId3 === 6 && liId4 === 5){35 target(liId3, liId4);36 left(liId3, liId4);37 up(liId3, liId4);38 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));39 } else if (liId3 && liId4 === 0){40 target(liId3, liId4);41 up(liId3, liId4);42 down(liId3, liId4);43 right(liId3, liId4);44 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));45 } else if (liId3 && liId4 === 5){46 target(liId3, liId4);47 up(liId3, liId4);48 down(liId3, liId4);49 left(liId3, liId4);50 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));51 } else if (liId3 === 0 && liId4){52 target(liId3, liId4);53 left(liId3, liId4);54 right(liId3, liId4);55 down(liId3, liId4);56 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));57 } else if (liId3 === 6 && liId4){58 target(liId3, liId4);59 left(liId3, liId4);60 right(liId3, liId4);61 up(liId3, liId4);62 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));63 } else if (liId3 && liId4){64 target(liId3, liId4);65 left(liId3, liId4);66 right(liId3, liId4);67 up(liId3, liId4);68 down(liId3, liId4);69 //console.log("target: " + liId3 + " - " + typeof(liId3) + ", " + liId4 + " - "+ typeof(liId4));70 }71 }72 function target(elemFest, elemLast) { //Target Element 73 //console.log("target - " + elemFest + " " + elemLast);74 newItemTarget= "li" + elemFest + elemLast;75 verifyItemDel(newItemTarget);76 }77 function left(elemFest, elemLast) { //Element from Left Side78 var elemLast = elemLast - 1;79 //console.log("left - " + elemFest + " - " + typeof(elemFest) + " , " + elemLast + " - " + typeof(elemLast));80 newItemLeft= "li" + elemFest + elemLast;81 verifyItemDel(newItemLeft);82 }83 function right(elemFest, elemLast) { //Element from Rite Side84 var elemLast = elemLast + 1;85 //console.log("right - " + elemFest + " - " + typeof(elemFest) + " , " + elemLast + " - " + typeof(elemLast));86 newItemRight= "li" + elemFest + elemLast87 verifyItemDel(newItemRight);88 }89 function up(elemFest, elemLast) { //Element from the top (up)90 var elemFest = elemFest - 1;91 //console.log("up - " + elemFest + " - " + typeof(elemFest) + " , " + elemLast + " - " + typeof(elemLast));92 newItemUp= "li" + elemFest + elemLast93 verifyItemDel(newItemUp);94 }95 function down(elemFest, elemLast) { //Element from the bottom96 var elemFest = elemFest + 1;97 //console.log("down - " + elemFest + " - " + typeof(elemFest) + " , " + elemLast + " - " + typeof(elemLast));98 newItemDown= "li" + elemFest + elemLast99 verifyItemDel(newItemDown);100 }101 function verifyItemDel(liid) { //Verify Element by className and id102 for (var i = 0; i<liElems.length; i++) {103 if (liElems[i].id === liid && liElems[i].firstChild.className === iElem.className){104 liElems[i].firstChild.style.display = "none";105 //liElems[i].style.background = "red";106 verifyPush(liid)107 }108 }109 }110 function verifyPush(liIdPush) { //Push Elements to Array, and verify to unique 111 if (arrayItemsLiId.indexOf(liIdPush) === -1) {112 arrayItemsLiId.push(liIdPush);113 arrayItems();114 }115 }116 function arrayItems() { // All elements of Array is verify, and extracting 2 last numbers117 for (var key in arrayItemsLiId) {118 if (arrayItemsLiId.hasOwnProperty(key)) {119 //console.log( arrayItemsLiId[key]+ " , " + typeof(arrayItemsLiId[key]) + " new version verify" );120 var liElemIdUpFast = +arrayItemsLiId[key].charAt(arrayItemsLiId[key].length - 2);121 var liElemIdUpLast = +arrayItemsLiId[key].charAt(arrayItemsLiId[key].length - 1);122 //console.log(liElemIdUpFast + " - " + typeof(liElemIdUpFast) + " , " + liElemIdUpLast + " - " + typeof(liElemIdUpLast));123 matrixSquea(liElemIdUpFast, liElemIdUpLast)124 }125 }126 }127 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2var id3 = tracetest.id3;3var id3 = tracetest.id3;4var id3 = tracetest.id3;5var id3 = tracetest.id3;6var id4 = tracetest.id4;7var id4 = tracetest.id4;8var id4 = tracetest.id4;9var id4 = tracetest.id4;10var id5 = tracetest.id5;11var id5 = tracetest.id5;12var id5 = tracetest.id5;13var id5 = tracetest.id5;14var id6 = tracetest.id6;15var id6 = tracetest.id6;16var id6 = tracetest.id6;17var id6 = tracetest.id6;18var id7 = tracetest.id7;19var id7 = tracetest.id7;20var id7 = tracetest.id7;21var id7 = tracetest.id7;22var id8 = tracetest.id8;23var id8 = tracetest.id8;24var id8 = tracetest.id8;25var id8 = tracetest.id8;26var id9 = tracetest.id9;27var id9 = tracetest.id9;28var id9 = tracetest.id9;29var id9 = tracetest.id9;30var id10 = tracetest.id10;31var id10 = tracetest.id10;32var id10 = tracetest.id10;33var id10 = tracetest.id10;34var id11 = tracetest.id11;35var id11 = tracetest.id11;36var id11 = tracetest.id11;37var id11 = tracetest.id11;38var id12 = tracetest.id12;

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('tracetest');2tracetest.id3();3var id3 = function() {4 console.log('id3');5}6exports.id3 = id3;7 at Function.Module._resolveFilename (module.js:338:15)8 at Function.Module._load (module.js:280:25)9 at Module.require (module.js:364:17)10 at require (module.js:380:17)11 at Object. (/home/robert/Projects/nodejs/test.js:2:14)12 at Module._compile (module.js:456:26)13 at Object.Module._extensions..js (module.js:474:10)14 at Module.load (module.js:356:32)15 at Function.Module._load (module.js:312:12)16 at Function.Module.runMain (module.js:497:10)

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('tracetest');2trace.id3(3, 4);3exports.id3 = function(a, b) {4 console.log(a + b);5};6var trace = require('tracetest');7var sum = trace.sum(3, 4);8console.log(sum);9exports.sum = function(a, b) {10 return a + b;11};12var trace = require('tracetest');13var sum = trace.testObj.sum(3, 4);14console.log(sum);15exports.testObj = {16 sum: function(a, b) {17 return a + b;18 }19};20var trace = require('tracetest');21var sum = trace.testObj.sum(3, 4);22console.log(sum);23function Test() {24 this.sum = function(a, b) {25 return a + b;26 }27 this.sub = function(a, b) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var trace = require('tracetest');2trace.id3("Hello World");3exports.id3 = function(id3) {4 console.log(id3);5}6delete require.cache[require.resolve('./tracetest.js')];

Full Screen

Using AI Code Generation

copy

Full Screen

1var tracetest = require('./tracetest');2var id3 = tracetest.id3;3function foo() {4 var stack = id3();5 console.log(stack);6}7function bar() {8 foo();9}10bar();11var id = 0;12function id1() {13 return id++;14}15function id2() {16 return id++;17}18function id3() {19 return id++;20}21exports.id1 = id1;22exports.id2 = id2;23exports.id3 = id3;24var tracetest = require('./tracetest');25var id3 = tracetest.id3;26function foo() {27 var stack = id3();28 console.log(stack);29}30function bar() {31 foo();32}33bar();

Full Screen

Using AI Code Generation

copy

Full Screen

1var id3 = require('./id3.js');2var mp3file = 'test.mp3';3id3({ file: mp3file, type: id3.OPEN_LOCAL }, function(err, tags) {4 console.log(tags);5});6var id3 = require('./id3');

Full Screen

Using AI Code Generation

copy

Full Screen

1var id3 = require('id3js');2var path = require('path');3var fs = require('fs');4var path = require('path');5var dir = 'C:\\Users\\Admin\\Desktop\\Music\\';6var files = fs.readdirSync(dir);7var FILENAME = "C:\\Users\\Admin\\Desktop\\Music\\";8var FILENAME2 = "C:\\Users\\Admin\\Desktop\\Music\\";9var FILENAME3 = "C:\\Users\\Admin\\Desktop\\Music\\";10var FILENAME4 = "C:\\Users\\Admin\\Desktop\\Music\\";11var FILENAME5 = "C:\\Users\\Admin\\Desktop\\Music\\";12var FILENAME6 = "C:\\Users\\Admin\\Desktop\\Music\\";13var file = "C:\\Users\\Admin\\Desktop\\Music\\";14var file2 = "C:\\Users\\Admin\\Desktop\\Music\\";15var file3 = "C:\\Users\\Admin\\Desktop\\Music\\";16var file4 = "C:\\Users\\Admin\\Desktop\\Music\\";17var file5 = "C:\\Users\\Admin\\Desktop\\Music\\";18var file6 = "C:\\Users\\Admin\\Desktop\\Music\\";19var file7 = "C:\\Users\\Admin\\Desktop\\Music\\";20var file8 = "C:\\Users\\Admin\\Desktop\\Music\\";21var file9 = "C:\\Users\\Admin\\Desktop\\Music\\";22var file10 = "C:\\Users\\Admin\\Desktop\\Music\\";23var file11 = "C:\\Users\\Admin\\Desktop\\Music\\";24var file12 = "C:\\Users\\Admin\\Desktop\\Music\\";25var file13 = "C:\\Users\\Admin\\Desktop\\Music\\";26var file14 = "C:\\Users\\Admin\\Desktop\\Music\\";

Full Screen

Using AI Code Generation

copy

Full Screen

1gulp.task('build', ['clean'], function() {2 return gulp.src(['app/**/*', '!app/**/*.js'])3 .pipe(gulp.dest('dist'))4 .pipe(plugins.uglify())5 .pipe(gulp.dest('dist'));6});7gulp.task('build', ['clean'], function() {8 return gulp.src(['app/**/*', '!app/**/*.js'])9 .pipe(gulp.dest('dist'))10 .pipe(plugins.uglify())11 .pipe(gulp.dest('dist'));12});13gulp.task('build', ['clean'], function() {14 return gulp.src(['app/**/*', '!app/**/*.js'])15 .pipe(gulp.dest('dist'))16 .pipe(plugins.uglify())17 .pipe(gulp.dest('dist'));18});19gulp.task('build', ['clean'], function() {20 return gulp.src(['app/**/*', '!app/**/*.js'])21 .pipe(gulp.dest('dist'))22 .pipe(plugins.uglify())23 .pipe(gulp.dest('dist'));24});25gulp.task('build', ['clean'], function() {26 return gulp.src(['app/**/*', '!app/**/*.js'])27 .pipe(gulp.dest('dist'))

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tracetest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful