Skip to content

Commit

Permalink
Post-updated v3.0-RC2 release
Browse files Browse the repository at this point in the history
- Updated foo_uie_eslyric component to v0.5.4.1011 - thx @ESLyric =)
- Fixed predefined lyric source search order
  • Loading branch information
TT-ReBORN committed Sep 24, 2023
1 parent 246317f commit b14c1e9
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 123 deletions.
Binary file modified profile/configuration/foo_uie_eslyric.dll.cfg
Binary file not shown.
117 changes: 60 additions & 57 deletions profile/eslyric-data/scripts/parser/krc.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@

export function getConfig(cfg) {
cfg.name = "KRC Parser";
cfg.version = "0.1";
cfg.author = "ohyeah";
cfg.name = 'KRC Parser';
cfg.version = '0.2';
cfg.author = 'ohyeah & TT';
cfg.parsePlainText = false;
cfg.fileType = "krc";
cfg.fileType = 'krc';
}

export function parseLyric(context) {
let zipData = xorKRC(context.lyricData);
if (!zipData)
return;
let unzipData = zlib.uncompress(zipData.buffer);
if (unzipData == null)
return;
const zipData = xorKRC(context.lyricData);
if (!zipData) return;

const unzipData = zlib.uncompress(zipData.buffer);
if (unzipData == null) return;

context.lyricText = krc2lrc(arrayBufferToString(unzipData));
}

function xorKRC(rawData) {
if (rawData == null) return;

if (null == rawData)
return;
const dataView = new Uint8Array(rawData);
const magicBytes = [0x6b, 0x72, 0x63, 0x31]; // 'k' , 'r' , 'c' ,'1'
if (dataView.length < magicBytes.length) return;

let dataView = new Uint8Array(rawData);
let magicBytes = [0x6b, 0x72, 0x63, 0x31];// 'k' , 'r' , 'c' ,'1'
if (dataView.length < magicBytes.length)
return;
for (let i = 0; i < magicBytes.length; ++i) {
if (dataView[i] != magicBytes[i])
return;
if (dataView[i] !== magicBytes[i]) return;
}

let decryptedData = new Uint8Array(dataView.length - magicBytes.length);
let encKey = [0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69];
let hdrOffset = magicBytes.length;
const decryptedData = new Uint8Array(dataView.length - magicBytes.length);
const encKey = [0x40, 0x47, 0x61, 0x77, 0x5e, 0x32, 0x74, 0x47, 0x51, 0x36, 0x31, 0x2d, 0xce, 0xd2, 0x6e, 0x69];
const hdrOffset = magicBytes.length;

for (let i = hdrOffset; i < dataView.length; ++i) {
let x = dataView[i];
let y = encKey[(i - hdrOffset) % encKey.length];
const x = dataView[i];
const y = encKey[(i - hdrOffset) % encKey.length];
decryptedData[i - hdrOffset] = x ^ y;
}

Expand All @@ -47,48 +44,54 @@ function xorKRC(rawData) {
// [1000,1200]<0,400,0>word1<400,200,0>word2<600,300,0>word3
// [playback pos, duration]<word offset, word duration, 0>word
function krc2lrc(krcText) {
let lyricText = "";
let lyricText = '';
let matches;
let metaRegex = /^\[(\S+):(\S+)\]$/;
let timestampsRegex = /^\[(\d+),(\d+)\]/;
let timestamps2Regex = /<(\d+),(\d+),(\d+)>([^<]*)/g;
let lines = krcText.split(/[\r\n]/);
const metaRegex = /^\[(\S+):(\S+)\]$/;
const timestampsRegex = /^\[(\d+),(\d+)\]/;
const timestamps2Regex = /<(\d+),(\d+),(\d+)>([^<]*)/g;
const lines = krcText.split(/[\r\n]/);

for (const line of lines) {
if (matches = metaRegex.exec(line)) { // meta info
lyricText += matches[0] + "\r\n";
} else if (matches = timestampsRegex.exec(line)) {
let lyricLine = "";
let startTime = parseInt(matches[1]);
let duration = parseInt(matches[2]);
lyricLine = "[" + formatTime(startTime) + "]";
if ((matches = metaRegex.exec(line))) { // meta info
lyricText += `${matches[0]}\r\n`;
}
else if ((matches = timestampsRegex.exec(line))) {
let lyricLine = '';
const startTime = parseInt(matches[1]);
const duration = parseInt(matches[2]);
lyricLine = `[${formatTime(startTime)}]`;

// parse sub-timestamps
let subMatches;
while (subMatches = timestamps2Regex.exec(line)) {
let offset = parseInt(subMatches[1]);
let subWord = subMatches[4];
lyricLine += "<" + formatTime(startTime + offset) + ">" + subWord;
while ((subMatches = timestamps2Regex.exec(line))) {
const offset = parseInt(subMatches[1]);
const subWord = subMatches[4];
lyricLine += `<${formatTime(startTime + offset)}>${subWord}`;
}
lyricLine += "<" + formatTime(startTime + duration) + ">";
lyricText += lyricLine + "\r\n";

lyricLine += `<${formatTime(startTime + duration)}>`;
lyricText += `${lyricLine}\r\n`;
}
}

return lyricText;
}

function zpad(n) {
var s = n.toString();
return (s.length < 2) ? "0" + s : s;
}

function formatTime(time) {
var t = Math.abs(time / 1000);
var h = Math.floor(t / 3600);
t -= h * 3600;
var m = Math.floor(t / 60);
t -= m * 60;
var s = Math.floor(t);
var ms = t - s;
var str = (h ? zpad(h) + ":" : "") + zpad(m) + ":" + zpad(s) + "." + zpad(Math.floor(ms * 100));
return str;
}
const zpad = (n) => {
const s = n.toString();
return (s.length < 2) ? `0${s}` : s;
};

let t = Math.abs(time / 1000);
const h = Math.floor(t / 3600);
t -= h * 3600;

const m = Math.floor(t / 60);
t -= m * 60;

const s = Math.floor(t);
const ms = t - s;

return `${(h ? `${zpad(h)}:` : '') + zpad(m)}:${zpad(s)}.${zpad(Math.floor(ms * 100))}`;
}
78 changes: 39 additions & 39 deletions profile/eslyric-data/scripts/parser/qrc.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
import * as decoder from "parser_ext.so";
import * as decoder from 'parser_ext.so';

export function getConfig(cfg) {
cfg.name = "QRC Parser";
cfg.version = "0.2";
cfg.author = "wistaria";
cfg.name = 'QRC Parser';
cfg.version = '0.3';
cfg.author = 'wistaria & TT';
cfg.parsePlainText = false;
cfg.fileType = "qrc";
cfg.fileType = 'qrc';
}

export function parseLyric(context) {
var zipData = decoder.decodeQrc(context.lyricData);
const zipData = decoder.decodeQrc(context.lyricData);
if (zipData == null) return;
var unzipData = zlib.uncompress(zipData);

const unzipData = zlib.uncompress(zipData);
if (unzipData == null) return;
var lyricText = qrcToLrc(arrayBufferToString(unzipData));

const lyricText = qrcToLrc(arrayBufferToString(unzipData));
if (lyricText == null) return;

context.lyricText = lyricText;
}

function escapeXml(xmlText)
{
function escapeXml(xmlText) {
return xmlText.replace(/&/g, '&amp;');
}

function qrcToLrc(xmlText) {

if (xmlText != null && typeof xmlText === 'string' && xmlText.indexOf('<?xml') == -1) {
if (xmlText != null && typeof xmlText === 'string' && xmlText.indexOf('<?xml') === -1) {
return xmlText;
}

var xmlRoot = mxml.loadString(xmlText);
let xmlRoot = mxml.loadString(xmlText);
if (xmlRoot == null) {
xmlText = escapeXml(xmlText);
xmlRoot = mxml.loadString(xmlText);
}
if (xmlRoot == null) {
console.log("parse xml failed: " + xmlText);
console.log(`parse xml failed: ${xmlText}`);
return;
}
var lyricElement = xmlRoot.findElement("Lyric_1", mxml.MXML_DESCEND);
if (lyricElement == null)
return null;

var lyricType = lyricElement.getAttr("LyricType");
if (lyricType == null)
return null;
const lyricElement = xmlRoot.findElement('Lyric_1', mxml.MXML_DESCEND);
if (lyricElement == null) return null;

const lyricType = lyricElement.getAttr('LyricType');
if (lyricType == null) return null;

if (parseInt(lyricType) != 1) // unsupported type??? not sure
return null;
if (parseInt(lyricType) !== 1) return null; // unsupported type??? not sure

var qrcText = lyricElement.getAttr("LyricContent");
if (qrcText == null)
return null;
const qrcText = lyricElement.getAttr('LyricContent');
if (qrcText == null) return null;

return qrcText
.replace(/^\[(\d+),(\d+)\]/gm, (_, base, __) => `[${formatTime(+base)}]<${formatTime(+base)}>`)
.replace(/\((\d+),(\d+)\)/g, (_, start, offset) => `<${formatTime(+start + +offset)}>`);
}

function zpad(n) {
var s = n.toString();
return (s.length < 2) ? "0" + s : s;
}

function formatTime(time) {
var t = Math.abs(time / 1000);
var h = Math.floor(t / 3600);
t -= h * 3600;
var m = Math.floor(t / 60);
t -= m * 60;
var s = Math.floor(t);
var ms = t - s;
var str = (h ? zpad(h) + ":" : "") + zpad(m) + ":" + zpad(s) + "." + zpad(Math.floor(ms * 100));
return str;
const zpad = (n) => {
const s = n.toString();
return (s.length < 2) ? `0${s}` : s;
};

let t = Math.abs(time / 1000);
const h = Math.floor(t / 3600);
t -= h * 3600;

const m = Math.floor(t / 60);
t -= m * 60;

const s = Math.floor(t);
const ms = t - s;

return `${(h ? `${zpad(h)}:` : '') + zpad(m)}:${zpad(s)}.${zpad(Math.floor(ms * 100))}`;
}
54 changes: 28 additions & 26 deletions profile/eslyric-data/scripts/parser/srt.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
export function getConfig(cfg) {
cfg.name = "SRT Parser";
cfg.version = "0.3";
cfg.author = "wistaria";
cfg.name = 'SRT Parser';
cfg.version = '0.4';
cfg.author = 'wistaria & TT';
cfg.parsePlainText = true;
cfg.fileType = "srt";
cfg.fileType = 'srt';
}

export function parseLyric(context) {
// https://github.com/bazh/subtitles-parser
// Copyright (c) 2013 bazh <interesno@gmail.com>
let lrcText = '';

////////////////////////////////////////////////
var parser=function(){var r={};r.fromSrt=function(r,e){var n=e?!0:!1;r=r.replace(/\r/g,"");var i=/(\d+)\n(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/g;r=r.split(i),r.shift();for(var a=[],d=0;d<r.length;d+=4)a.push({id:r[d].trim(),startTime:n?t(r[d+1].trim()):r[d+1].trim(),endTime:n?t(r[d+2].trim()):r[d+2].trim(),text:r[d+3].trim()});return a},r.toSrt=function(r){if(!r instanceof Array)return"";for(var t="",n=0;n<r.length;n++){var i=r[n];isNaN(i.startTime)||isNaN(i.endTime)||(i.startTime=e(parseInt(i.startTime,10)),i.endTime=e(parseInt(i.endTime,10))),t+=i.id+"\r\n",t+=i.startTime+" --> "+i.endTime+"\r\n",t+=i.text.replace("\n","\r\n")+"\r\n\r\n"}return t};var t=function(r){var t=/(\d+):(\d{2}):(\d{2}),(\d{3})/,e=t.exec(r);if(null===e)return 0;for(var n=1;5>n;n++)e[n]=parseInt(e[n],10),isNaN(e[n])&&(e[n]=0);return 36e5*e[1]+6e4*e[2]+1e3*e[3]+e[4]},e=function(r){var t=[36e5,6e4,1e3],e=[];for(var n in t){var i=(r/t[n]>>0).toString();i.length<2&&(i="0"+i),r%=t[n],e.push(i)}var a=r.toString();if(a.length<3)for(n=0;n<=3-a.length;n++)a="0"+a;return e.join(":")+","+a};return r}();
/** https://github.com/bazh/subtitles-parser - Copyright (c) 2013 bazh <interesno@gmail.com> */
const parser = (function() { const r = {}; r.fromSrt = function(r, e) { const n = e ? !0 : !1; r = r.replace(/\r/g, ''); const i = /(\d+)\n(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/g; r = r.split(i), r.shift(); for (var a = [], d = 0; d < r.length; d += 4)a.push({ id:r[d].trim(), startTime:n ? t(r[d + 1].trim()) : r[d + 1].trim(), endTime:n ? t(r[d + 2].trim()) : r[d + 2].trim(), text:r[d + 3].trim() }); return a }, r.toSrt = function(r) { if (!r instanceof Array) return ''; for (var t = '', n = 0; n < r.length; n++) { const i = r[n]; isNaN(i.startTime) || isNaN(i.endTime) || (i.startTime = e(parseInt(i.startTime, 10)), i.endTime = e(parseInt(i.endTime, 10))), t += i.id + '\r\n', t += i.startTime + ' --> ' + i.endTime + '\r\n', t += i.text.replace('\n', '\r\n') + '\r\n\r\n' } return t }; var t = function(r) { const t = /(\d+):(\d{2}):(\d{2}),(\d{3})/; const e = t.exec(r); if (e === null) return 0; for (let n = 1; n < 5; n++)e[n] = parseInt(e[n], 10), isNaN(e[n]) && (e[n] = 0); return 36e5 * e[1] + 6e4 * e[2] + 1e3 * e[3] + e[4] }; var e = function(r) { const t = [36e5, 6e4, 1e3]; const e = []; for (var n in t) { let i = (r / t[n] >> 0).toString(); i.length < 2 && (i = '0' + i), r %= t[n], e.push(i) } let a = r.toString(); if (a.length < 3) for (n = 0; n <= 3 - a.length; n++)a = '0' + a; return e.join(':') + ',' + a }; return r }());
////////////////////////////////////////////////

let lrcText = '';
let srtBlocks = parser.fromSrt(context.lyricText, true);
for(const block of srtBlocks) {
lrcText += '[' + formatTime(block.startTime) + ']' + block.text.replace(/\n/g, ' ') + '\r\n';
const srtBlocks = parser.fromSrt(context.lyricText, true);
for (const block of srtBlocks) {
lrcText += `[${formatTime(block.startTime)}]${block.text.replace(/\n/g, ' ')}\r\n`;
}

context.lyricText = lrcText;
}

function zpad(n) {
var s = n.toString();
return (s.length < 2) ? "0" + s : s;
context.lyricText = lrcText;
}

function formatTime(time) {
var t = Math.abs(time / 1000);
var h = Math.floor(t / 3600);
t -= h * 3600;
var m = Math.floor(t / 60);
t -= m * 60;
var s = Math.floor(t);
var ms = t - s;
var str = zpad(m + h*60) + ":" + zpad(s) + "." + zpad(Math.floor(ms * 100));
return str;
const zpad = (n) => {
const s = n.toString();
return (s.length < 2) ? `0${s}` : s;
};

let t = Math.abs(time / 1000);
const h = Math.floor(t / 3600);
t -= h * 3600;

const m = Math.floor(t / 60);
t -= m * 60;

const s = Math.floor(t);
const ms = t - s;

return `${(h ? `${zpad(h)}:` : '') + zpad(m)}:${zpad(s)}.${zpad(Math.floor(ms * 100))}`;
}
2 changes: 1 addition & 1 deletion profile/georgia-reborn/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@

### Updated:
- Updated foo_playcount component to v3.1.5
- Updated foo_uie_eslyric component to v0.5.4.1008
- Updated foo_uie_eslyric component to v0.5.4.1011
<br>


Expand Down
Binary file modified profile/user-components/foo_uie_eslyric/foo_uie_eslyric.dll
Binary file not shown.
Binary file modified profile/user-components/foo_uie_eslyric/x64/foo_uie_eslyric.dll
Binary file not shown.

0 comments on commit b14c1e9

Please sign in to comment.