|
@ -1,34 +1,41 @@ |
|
|
import {AudioMimeType, GetArrayBuffer, GetCoverFromFile, GetMetaFromFile, SniffAudioExt} from "@/decrypt/utils.ts"; |
|
|
import { |
|
|
|
|
|
AudioMimeType, |
|
|
|
|
|
GetArrayBuffer, |
|
|
|
|
|
GetCoverFromFile, |
|
|
|
|
|
GetMetaFromFile, |
|
|
|
|
|
SniffAudioExt, |
|
|
|
|
|
SplitFilename |
|
|
|
|
|
} from "@/decrypt/utils.ts"; |
|
|
|
|
|
|
|
|
import {Decrypt as QmcDecrypt} from "@/decrypt/qmc"; |
|
|
import {Decrypt as QmcDecrypt, HandlerMap} from "@/decrypt/qmc"; |
|
|
|
|
|
|
|
|
import {DecryptResult} from "@/decrypt/entity"; |
|
|
import {DecryptResult} from "@/decrypt/entity"; |
|
|
|
|
|
|
|
|
import {parseBlob as metaParseBlob} from "music-metadata-browser"; |
|
|
import {parseBlob as metaParseBlob} from "music-metadata-browser"; |
|
|
|
|
|
|
|
|
export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, detect: boolean = true) |
|
|
export async function Decrypt(file: Blob, raw_filename: string, _: string) |
|
|
: Promise<DecryptResult> { |
|
|
: Promise<DecryptResult> { |
|
|
let ext = raw_ext; |
|
|
const buffer = new Uint8Array(await GetArrayBuffer(file)); |
|
|
if (detect) { |
|
|
let length = buffer.length |
|
|
const buffer = new Uint8Array(await GetArrayBuffer(file)); |
|
|
for (let i = 0; i < length; i++) { |
|
|
let length = buffer.length |
|
|
buffer[i] ^= 0xf4 |
|
|
for (let i = 0; i < length; i++) { |
|
|
if (buffer[i] <= 0x3f) buffer[i] = buffer[i] * 4; |
|
|
buffer[i] ^= 0xf4 |
|
|
else if (buffer[i] <= 0x7f) buffer[i] = (buffer[i] - 0x40) * 4 + 1; |
|
|
if(buffer[i] <= 0x3f)buffer[i] = buffer[i] * 4; |
|
|
else if (buffer[i] <= 0xbf) buffer[i] = (buffer[i] - 0x80) * 4 + 2; |
|
|
else if(buffer[i] <= 0x7f)buffer[i] = (buffer[i] - 0x40) * 4 + 1; |
|
|
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3; |
|
|
else if(buffer[i] <= 0xbf)buffer[i] = (buffer[i] - 0x80) * 4 + 2; |
|
|
|
|
|
else buffer[i] = (buffer[i] - 0xc0) * 4 + 3; |
|
|
|
|
|
} |
|
|
|
|
|
ext = SniffAudioExt(buffer, raw_ext); |
|
|
|
|
|
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]}) |
|
|
|
|
|
else { |
|
|
|
|
|
file = new Blob([buffer], {type: "application/octet-stream"}) |
|
|
|
|
|
let ext = raw_filename.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase(); |
|
|
|
|
|
if (ext !== "mgg" && ext !== "mflac") throw "不支持的QQ音乐缓存格式:" + raw_filename + ".cache"; |
|
|
|
|
|
return QmcDecrypt(file, raw_filename, ext+".cache"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
const tag = await metaParseBlob(file); |
|
|
let ext = SniffAudioExt(buffer, ""); |
|
|
|
|
|
const newName = SplitFilename(raw_filename) |
|
|
|
|
|
let audioBlob: Blob |
|
|
|
|
|
if (ext !== "" || newName.ext === "mp3") { |
|
|
|
|
|
audioBlob = new Blob([buffer], {type: AudioMimeType[ext]}) |
|
|
|
|
|
} else if (newName.ext in HandlerMap) { |
|
|
|
|
|
audioBlob = new Blob([buffer], {type: "application/octet-stream"}) |
|
|
|
|
|
return QmcDecrypt(audioBlob, newName.name, newName.ext); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw "不支持的QQ音乐缓存格式" |
|
|
|
|
|
} |
|
|
|
|
|
const tag = await metaParseBlob(audioBlob); |
|
|
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist) |
|
|
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist) |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
@ -37,8 +44,8 @@ export async function Decrypt(file: Blob, raw_filename: string, raw_ext: string, |
|
|
ext, |
|
|
ext, |
|
|
album: tag.common.album, |
|
|
album: tag.common.album, |
|
|
picture: GetCoverFromFile(tag), |
|
|
picture: GetCoverFromFile(tag), |
|
|
file: URL.createObjectURL(file), |
|
|
file: URL.createObjectURL(audioBlob), |
|
|
blob: file, |
|
|
blob: audioBlob, |
|
|
mime: AudioMimeType[ext] |
|
|
mime: AudioMimeType[ext] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|