forked from um/web
simplify: decrypt/ncm-cache & decrypt/common
This commit is contained in:
parent
f0875ad175
commit
48f879cb58
@ -8,35 +8,35 @@ import {Decrypt as KwmDecrypt} from "@/decrypt/kwm";
|
|||||||
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
import {Decrypt as RawDecrypt} from "@/decrypt/raw";
|
||||||
import {Decrypt as TmDecrypt} from "@/decrypt/tm";
|
import {Decrypt as TmDecrypt} from "@/decrypt/tm";
|
||||||
import {DecryptResult, FileInfo} from "@/decrypt/entity";
|
import {DecryptResult, FileInfo} from "@/decrypt/entity";
|
||||||
|
import {SplitFilename} from "@/decrypt/utils";
|
||||||
|
|
||||||
|
|
||||||
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
||||||
let raw_ext = file.name.substring(file.name.lastIndexOf(".") + 1, file.name.length).toLowerCase();
|
const raw = SplitFilename(file.name)
|
||||||
let raw_filename = file.name.substring(0, file.name.lastIndexOf("."));
|
|
||||||
let rt_data: DecryptResult;
|
let rt_data: DecryptResult;
|
||||||
switch (raw_ext) {
|
switch (raw.ext) {
|
||||||
case "ncm":// Netease Mp3/Flac
|
case "ncm":// Netease Mp3/Flac
|
||||||
rt_data = await NcmDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await NcmDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break;
|
break;
|
||||||
case "uc":// Netease Cache
|
case "uc":// Netease Cache
|
||||||
rt_data = await NcmCacheDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await NcmCacheDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break;
|
break;
|
||||||
case "kwm":// Kuwo Mp3/Flac
|
case "kwm":// Kuwo Mp3/Flac
|
||||||
rt_data = await KwmDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await KwmDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break
|
break
|
||||||
case "xm": // Xiami Wav/M4a/Mp3/Flac
|
case "xm": // Xiami Wav/M4a/Mp3/Flac
|
||||||
case "wav":// Xiami/Raw Wav
|
case "wav":// Xiami/Raw Wav
|
||||||
case "mp3":// Xiami/Raw Mp3
|
case "mp3":// Xiami/Raw Mp3
|
||||||
case "flac":// Xiami/Raw Flac
|
case "flac":// Xiami/Raw Flac
|
||||||
case "m4a":// Xiami/Raw M4a
|
case "m4a":// Xiami/Raw M4a
|
||||||
rt_data = await XmDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await XmDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break;
|
break;
|
||||||
case "ogg":// Raw Ogg
|
case "ogg":// Raw Ogg
|
||||||
rt_data = await RawDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await RawDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break;
|
break;
|
||||||
case "tm0":// QQ Music IOS Mp3
|
case "tm0":// QQ Music IOS Mp3
|
||||||
case "tm3":// QQ Music IOS Mp3
|
case "tm3":// QQ Music IOS Mp3
|
||||||
rt_data = await RawDecrypt(file.raw, raw_filename, "mp3");
|
rt_data = await RawDecrypt(file.raw, raw.name, "mp3");
|
||||||
break;
|
break;
|
||||||
case "qmc3"://QQ Music Android Mp3
|
case "qmc3"://QQ Music Android Mp3
|
||||||
case "qmc2"://QQ Music Android Ogg
|
case "qmc2"://QQ Music Android Ogg
|
||||||
@ -53,26 +53,26 @@ export async function CommonDecrypt(file: FileInfo): Promise<DecryptResult> {
|
|||||||
case "6f6767"://QQ Music Weiyun Ogg
|
case "6f6767"://QQ Music Weiyun Ogg
|
||||||
case "6d3461"://QQ Music Weiyun M4a
|
case "6d3461"://QQ Music Weiyun M4a
|
||||||
case "776176"://QQ Music Weiyun Wav
|
case "776176"://QQ Music Weiyun Wav
|
||||||
rt_data = await QmcDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await QmcDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break;
|
break;
|
||||||
case "tm2":// QQ Music IOS M4a
|
case "tm2":// QQ Music IOS M4a
|
||||||
case "tm6":// QQ Music IOS M4a
|
case "tm6":// QQ Music IOS M4a
|
||||||
rt_data = await TmDecrypt(file.raw, raw_filename);
|
rt_data = await TmDecrypt(file.raw, raw.name);
|
||||||
break;
|
break;
|
||||||
case "cache"://QQ Music Cache
|
case "cache"://QQ Music Cache
|
||||||
rt_data = await QmcCacheDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await QmcCacheDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break;
|
break;
|
||||||
case "vpr":
|
case "vpr":
|
||||||
case "kgm":
|
case "kgm":
|
||||||
case "kgma":
|
case "kgma":
|
||||||
rt_data = await KgmDecrypt(file.raw, raw_filename, raw_ext);
|
rt_data = await KgmDecrypt(file.raw, raw.name, raw.ext);
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw "不支持此文件格式"
|
throw "不支持此文件格式"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rt_data.rawExt) rt_data.rawExt = raw_ext;
|
if (!rt_data.rawExt) rt_data.rawExt = raw.ext;
|
||||||
if (!rt_data.rawFilename) rt_data.rawFilename = raw_filename;
|
if (!rt_data.rawFilename) rt_data.rawFilename = raw.name;
|
||||||
console.log(rt_data);
|
console.log(rt_data);
|
||||||
return rt_data;
|
return rt_data;
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,15 @@ 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, raw_ext: string)
|
||||||
: Promise<DecryptResult> {
|
: Promise<DecryptResult> {
|
||||||
let ext = raw_ext;
|
|
||||||
if (detect) {
|
|
||||||
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
const buffer = new Uint8Array(await GetArrayBuffer(file));
|
||||||
let length = buffer.length
|
let length = buffer.length
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
buffer[i] ^= 163
|
buffer[i] ^= 163
|
||||||
}
|
}
|
||||||
ext = SniffAudioExt(buffer, raw_ext);
|
const ext = SniffAudioExt(buffer, raw_ext);
|
||||||
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]})
|
if (ext !== raw_ext) file = new Blob([buffer], {type: AudioMimeType[ext]})
|
||||||
}
|
|
||||||
const tag = await metaParseBlob(file);
|
const tag = await metaParseBlob(file);
|
||||||
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist)
|
const {title, artist} = GetMetaFromFile(raw_filename, tag.common.title, tag.common.artist)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user