2 lines
8.3 KiB
JavaScript
2 lines
8.3 KiB
JavaScript
"use strict";(self.webpackChunkmontana_messenger=self.webpackChunkmontana_messenger||[]).push([[2465],{62465(t,e,a){a.r(e),a.d(e,{FlacParser:()=>g});var s=a(17833),r=a(4017),i=a(92304),n=a(94481),o=a(5031),h=a(27232),d=a(61902),m=a(63324),l=a(54489);const c=s("music-metadata:parser:FLAC");class p extends((0,m.fO)("FLAC")){}class g extends n.k{constructor(){super(...arguments),this.vorbisParser=new h._(this.metadata,this.options)}async postId3v2Parse(){if("fLaC"!==(await this.tokenizer.readToken(o.e)).toString())throw new p("Invalid FLAC preamble");let t;do{t=await this.tokenizer.readToken(l.Tw),await this.parseDataBlock(t)}while(!t.lastBlock);if(this.tokenizer.fileInfo.size&&this.metadata.format.duration){const t=this.tokenizer.fileInfo.size-this.tokenizer.position;this.metadata.setFormat("bitrate",8*t/this.metadata.format.duration)}}async parseDataBlock(t){switch(c(`blockHeader type=${t.type}, length=${t.length}`),t.type){case l._B.STREAMINFO:return this.readBlockStreamInfo(t.length);case l._B.PADDING:case l._B.APPLICATION:case l._B.SEEKTABLE:break;case l._B.VORBIS_COMMENT:return this.readComment(t.length);case l._B.CUESHEET:break;case l._B.PICTURE:return void await this.parsePicture(t.length);default:this.metadata.addWarning(`Unknown block type: ${t.type}`)}return this.tokenizer.ignore(t.length).then()}async readBlockStreamInfo(t){if(t!==l.om.len)throw new p("Unexpected block-stream-info length");const e=await this.tokenizer.readToken(l.om);this.metadata.setFormat("container","FLAC"),this.processsStreamInfo(e)}processsStreamInfo(t){this.metadata.setFormat("codec","FLAC"),this.metadata.setFormat("hasAudio",!0),this.metadata.setFormat("lossless",!0),this.metadata.setFormat("numberOfChannels",t.channels),this.metadata.setFormat("bitsPerSample",t.bitsPerSample),this.metadata.setFormat("sampleRate",t.sampleRate),t.totalSamples>0&&this.metadata.setFormat("duration",t.totalSamples/t.sampleRate)}async readComment(t){const e=await this.tokenizer.readToken(new r.Uint8ArrayType(t));return this.parseComment(e)}async parseComment(t){const e=new d.Y(t,0),a=e.readStringUtf8();a.length>0&&this.metadata.setFormat("tool",a);const s=e.readInt32(),r=new Array(s);for(let t=0;t<s;t++)r[t]=e.parseUserComment();await Promise.all(r.map(t=>("ENCODER"===t.key&&this.metadata.setFormat("tool",t.value),this.addTag(t.key,t.value))))}async parsePicture(t){return this.options.skipCovers?this.tokenizer.ignore(t):this.addPictureTag(await this.tokenizer.readToken(new i.xu(t)))}addPictureTag(t){return this.addTag("METADATA_BLOCK_PICTURE",t)}addTag(t,e){return this.vorbisParser.addTag(t,e)}}},54489(t,e,a){a.d(e,{Tw:()=>n,_B:()=>i,om:()=>o});var s=a(56185),r=a(4017);const i={STREAMINFO:0,PADDING:1,APPLICATION:2,SEEKTABLE:3,VORBIS_COMMENT:4,CUESHEET:5,PICTURE:6},n={len:4,get:(t,e)=>({lastBlock:s.mh(t,e,7),type:s.f5(t,e,1,7),length:r.UINT24_BE.get(t,e+1)})},o={len:34,get:(t,e)=>({minimumBlockSize:r.UINT16_BE.get(t,e),maximumBlockSize:r.UINT16_BE.get(t,e+2)/1e3,minimumFrameSize:r.UINT24_BE.get(t,e+4),maximumFrameSize:r.UINT24_BE.get(t,e+7),sampleRate:r.UINT24_BE.get(t,e+10)>>4,channels:s.f5(t,e+12,4,3)+1,bitsPerSample:s.f5(t,e+12,7,5)+1,totalSamples:s.f5(t,e+13,4,36),fileMD5:new r.Uint8ArrayType(16).get(t,e+18)})}},94481(t,e,a){a.d(e,{k:()=>m});var s=a(10718),r=a(17833),i=a(47675),n=a(80400),o=a(68191),h=a(74604);const d=r("music-metadata:parser:ID3");class m extends h.s{constructor(){super(...arguments),this.id3parser=new n.S}static async startsWithID3v2Header(t){return"ID3"===(await t.peekToken(i.yW)).fileIdentifier}async parse(){try{await this.parseID3v2()}catch(t){if(!(t instanceof s.d1))throw t;d("End-of-stream")}}finalize(){}async parseID3v2(){if(await this.tryReadId3v2Headers(),d("End of ID3v2 header, go to MPEG-parser: pos=%s",this.tokenizer.position),await this.postId3v2Parse(),this.options.skipPostHeaders&&this.metadata.hasAny())this.finalize();else{const t=new o.Bn(this.metadata,this.tokenizer,this.options);await t.parse(),this.finalize()}}async tryReadId3v2Headers(){if("ID3"===(await this.tokenizer.peekToken(i.yW)).fileIdentifier)return d("Found ID3v2 header, pos=%s",this.tokenizer.position),await this.id3parser.parse(this.metadata,this.tokenizer,this.options),this.tryReadId3v2Headers()}}},92304(t,e,a){a.d(e,{Sl:()=>o,Z:()=>n,xu:()=>i});var s=a(4017),r=a(47675);class i{static fromBase64(t){return i.fromBuffer(Uint8Array.from(atob(t),t=>t.charCodeAt(0)))}static fromBuffer(t){return new i(t.length).get(t,0)}constructor(t){this.len=t}get(t,e){const a=r.n5[s.UINT32_BE.get(t,e)];e+=4;const i=s.UINT32_BE.get(t,e);e+=4;const n=new s.StringType(i,"utf-8").get(t,e);e+=i;const o=s.UINT32_BE.get(t,e);e+=4;const h=new s.StringType(o,"utf-8").get(t,e);e+=o;const d=s.UINT32_BE.get(t,e);e+=4;const m=s.UINT32_BE.get(t,e);e+=4;const l=s.UINT32_BE.get(t,e);e+=4;const c=s.UINT32_BE.get(t,e);e+=4;const p=s.UINT32_BE.get(t,e);return e+=4,{type:a,format:n,description:h,width:d,height:m,colour_depth:l,indexed_color:c,data:t.slice(e,e+p)}}}const n={len:7,get:(t,e)=>({packetType:s.UINT8.get(t,e),vorbis:new s.StringType(6,"ascii").get(t,e+1)})},o={len:23,get:(t,e)=>({version:s.UINT32_LE.get(t,e+0),channelMode:s.UINT8.get(t,e+4),sampleRate:s.UINT32_LE.get(t,e+5),bitrateMax:s.UINT32_LE.get(t,e+9),bitrateNominal:s.UINT32_LE.get(t,e+13),bitrateMin:s.UINT32_LE.get(t,e+17)})}},61902(t,e,a){a.d(e,{Y:()=>i});var s=a(4017),r=a(12971);class i{constructor(t,e){this.data=t,this.offset=e}readInt32(){const t=s.UINT32_LE.get(this.data,this.offset);return this.offset+=4,t}readStringUtf8(){const t=this.readInt32(),e=(0,r.c)(this.data.subarray(this.offset,this.offset+t),"utf-8");return this.offset+=t,e}parseUserComment(){const t=this.offset,e=this.readStringUtf8(),a=e.indexOf("=");return{key:e.substring(0,a).toUpperCase(),value:e.substring(a+1),len:this.offset-t}}}},27232(t,e,a){a.d(e,{_:()=>m});var s=a(4017),r=a(17833),i=a(61902),n=a(92304),o=a(63324);const h=r("music-metadata:parser:ogg:vorbis1");class d extends((0,o.fO)("Vorbis")){}class m{constructor(t,e){this.pageSegments=[],this.durationOnLastPage=!0,this.metadata=t,this.options=e}async parsePage(t,e){if(this.lastPageHeader=t,t.headerType.firstPage)this.parseFirstPage(t,e);else{if(t.headerType.continued){if(0===this.pageSegments.length)throw new d("Cannot continue on previous page");this.pageSegments.push(e)}if(t.headerType.lastPage||!t.headerType.continued){if(this.pageSegments.length>0){const t=m.mergeUint8Arrays(this.pageSegments);await this.parseFullPage(t)}this.pageSegments=t.headerType.lastPage?[]:[e]}}}static mergeUint8Arrays(t){const e=t.reduce((t,e)=>t+e.length,0),a=new Uint8Array(e);return t.forEach((t,e,s)=>{const r=s.slice(0,e).reduce((t,e)=>t+e.length,0);a.set(t,r)}),a}async flush(){await this.parseFullPage(m.mergeUint8Arrays(this.pageSegments))}async parseUserComment(t,e){const a=new i.Y(t,e).parseUserComment();return await this.addTag(a.key,a.value),a.len}async addTag(t,e){if("METADATA_BLOCK_PICTURE"===t&&"string"==typeof e){if(this.options.skipCovers)return void h("Ignore picture");e=n.xu.fromBase64(e),h(`Push picture: id=${t}, format=${e.format}`)}else h(`Push tag: id=${t}, value=${e}`);await this.metadata.addTag("vorbis",t,e)}calculateDuration(t){this.lastPageHeader&&(t||this.lastPageHeader.headerType.lastPage)&&this.metadata.format.sampleRate&&this.lastPageHeader.absoluteGranulePosition>=0&&(this.metadata.setFormat("numberOfSamples",this.lastPageHeader.absoluteGranulePosition),this.metadata.setFormat("duration",this.lastPageHeader.absoluteGranulePosition/this.metadata.format.sampleRate))}parseFirstPage(t,e){this.metadata.setFormat("codec","Vorbis I"),this.metadata.setFormat("hasAudio",!0),h("Parse first page");const a=n.Z.get(e,0);if("vorbis"!==a.vorbis)throw new d("Metadata does not look like Vorbis");if(1!==a.packetType)throw new d("First Ogg page should be type 1: the identification header");{const t=n.Sl.get(e,n.Z.len);this.metadata.setFormat("sampleRate",t.sampleRate),this.metadata.setFormat("bitrate",t.bitrateNominal),this.metadata.setFormat("numberOfChannels",t.channelMode),h("sample-rate=%s[hz], bitrate=%s[b/s], channel-mode=%s",t.sampleRate,t.bitrateNominal,t.channelMode)}}async parseFullPage(t){const e=n.Z.get(t,0);if(h("Parse full page: type=%s, byteLength=%s",e.packetType,t.byteLength),3===e.packetType)return this.parseUserCommentList(t,n.Z.len)}async parseUserCommentList(t,e){const a=s.UINT32_LE.get(t,e);e+=4,e+=a;let r=s.UINT32_LE.get(t,e);for(e+=4;r-- >0;)e+=await this.parseUserComment(t,e)}}}}]);
|
|
//# sourceMappingURL=2465.7ac3bb6843bf15397340.js.map
|