mirror of
https://git.um-react.app/um/um-react.git
synced 2026-08-30 05:02:02 +00:00
feat: add support for kuwo ios ekey db
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { parseAndroidKuwoEKey, parseIosKuwoEKey } from '../kuwo';
|
||||
|
||||
const makeViewFromBuffer = (buff: Buffer) =>
|
||||
new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
|
||||
|
||||
test('parse kuwo android ekey mmkv file "cn.kuwo.player.mmkv.defaultconfig"', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/kuwo_android.mmkv'));
|
||||
expect(parseAndroidKuwoEKey(view)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"ekey": "xyz123",
|
||||
"quality": "20201kmflac",
|
||||
"rid": "1234567",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
test('parse kuwo ios ekey mmkv file "kw_ekey"', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/kuwo_ios.mmkv'));
|
||||
expect(parseIosKuwoEKey(view)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"ekey": "xyz123",
|
||||
"quality": "20201",
|
||||
"rid": "1234567",
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { parseAndroidQmEKey } from '../qm';
|
||||
|
||||
const makeViewFromBuffer = (buff: Buffer) =>
|
||||
new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
|
||||
|
||||
test('parse qm mmkv file', () => {
|
||||
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/qm.mmkv'));
|
||||
expect(Object.fromEntries(parseAndroidQmEKey(view).entries())).toMatchInlineSnapshot(`
|
||||
{
|
||||
"Lorem Ipsum": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum congue volutpat metus non molestie. Quisque id est sapien. Fusce eget tristique sem. Donec tellus lacus, viverra sed lectus eget, elementum ultrices dolor. Integer non urna justo.",
|
||||
"key": "value",
|
||||
}
|
||||
`);
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import type { StagingKWMv2Key } from '~/features/settings/keyFormats';
|
||||
import { MMKVParser } from '../MMKVParser';
|
||||
|
||||
export function parseAndroidKuwoEKey(view: DataView): Omit<StagingKWMv2Key, 'id'>[] {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result: Omit<StagingKWMv2Key, 'id'>[] = [];
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readString();
|
||||
const idMatch = key.match(/^sec_ekey#(\d+)-(\w+)$/);
|
||||
if (!idMatch) {
|
||||
mmkv.skipContainer();
|
||||
continue;
|
||||
}
|
||||
|
||||
const [_, rid, quality] = idMatch;
|
||||
const ekey = mmkv.readStringValue();
|
||||
if (ekey) {
|
||||
result.push({ rid, quality, ekey });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function parseIosKuwoEKey(view: DataView): Omit<StagingKWMv2Key, 'id'>[] {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result: Omit<StagingKWMv2Key, 'id'>[] = [];
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readKey();
|
||||
const idMatch = key.match(/^(\d+)_(\d+)$/);
|
||||
if (!idMatch) {
|
||||
mmkv.skipContainer();
|
||||
continue;
|
||||
}
|
||||
const [_, rid, quality] = idMatch;
|
||||
const ekey = mmkv.readStringValue();
|
||||
if (ekey) {
|
||||
result.push({ rid, quality, ekey });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { MMKVParser } from '../MMKVParser';
|
||||
|
||||
export function parseAndroidQmEKey(view: DataView): Map<string, string> {
|
||||
const mmkv = new MMKVParser(view);
|
||||
const result = new Map<string, string>();
|
||||
while (!mmkv.eof) {
|
||||
const key = mmkv.readString();
|
||||
const value = mmkv.readStringValue();
|
||||
if (value) {
|
||||
result.set(key, value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user