the amount of brain cells that I have lost because of mxm trans

This commit is contained in:
maikirakiwi 2022-07-08 04:29:51 -07:00
parent abc8a4decb
commit 4c08d075ff

View file

@ -3054,7 +3054,7 @@ const app = new Vue({
const track = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.title ?? '' : '');
const artist = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.artistName ?? '' : '');
const time = encodeURIComponent((this.mk.nowPlayingItem != null) ? (Math.round((this.mk.nowPlayingItem.attributes["durationInMillis"] ?? -1000) / 1000) ?? -1) : -1);
let id = null;
let id = null; let vanity_id = null;
if (this.mk.nowPlayingItem != null && app.mk.nowPlayingItem.localFilesMetadata != null) {const id = encodeURIComponent('')}
else {id = encodeURIComponent((this.mk.nowPlayingItem != null) ? (app.mk.nowPlayingItem._songId) ?? (app.mk.nowPlayingItem["songId"] ?? '') : '');}
@ -3084,6 +3084,7 @@ const app = new Vue({
if (jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["header"]["status_code"] == 200 && jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["header"]["status_code"] == 200) {
id = jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["body"]["track"]["track_id"] ?? '';
lrcfile = jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["body"]["subtitle_list"][0]["subtitle"]["subtitle_body"];
vanity_id = jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["body"]["track"]["commontrack_vanity_id"];
try {
let lrcrich = jsonResponse["message"]["body"]["macro_calls"]["track.richsync.get"]["message"]["body"]["richsync"]["richsync_body"];
@ -3139,13 +3140,10 @@ const app = new Vue({
});
app.lyrics = preLrc;
}
if (lrcfile != null && lrcfile != '') {
// load translation
getMXMTrans(id, lang);
} else {
// app.loadAMLyrics()
app.loadQQLyrics();
}
// Load translation
getMXMTrans(lang, vanity_id);
}
} catch (e) {
console.log(e);
@ -3168,49 +3166,46 @@ const app = new Vue({
req.send();
}
function getMXMTrans(lang, id) {
if (lang != "disabled" && id != '') { // Mode 2 -> Trans
let url2 = "https://api.cider.sh/v1/lyrics?" + "mode=2" + "&richsyncQuery=false" + "&songID=" + id + "&source=mxm" + "&lang=" + lang + "&time=" + time;
let req2 = new XMLHttpRequest();
req2.overrideMimeType("application/json");
req2.onload = function () {
try {
let jsonResponse2 = JSON.parse(this.responseText);
console.log(jsonResponse2);
let status2 = jsonResponse2["message"]["header"]["status_code"];
if (status2 === 200) {
try {
let preTrans = []
let u = app.lyrics;
let translation_list = jsonResponse2["message"]["body"]["translations_list"];
if (translation_list.length > 0) {
for (var i = 0; i < u.length - 1; i++) {
preTrans[i] = ""
for (var trans_line of translation_list) {
if (u[i].line == " " + trans_line["translation"]["matched_line"] || u[i].line == trans_line["translation"]["matched_line"]) {
u[i].translation = trans_line["translation"]["description"];
break;
}
}
}
app.lyrics = u;
function getMXMTrans(lang, vanity_id) {
lang = 'english';
try {
if (lang != "disabled" && vanity_id != '') { // Mode 2 -> Trans
fetch('https://www.musixmatch.com/lyrics/' + vanity_id +'/translation/' + lang, {
method: 'GET',
headers: {
'Host': 'musixmatch.com',
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
'authority': "www.musixmatch.com"
},
})
.then(async (res) => {
let html = document.createElement('html'); html.innerHTML = await res.text()
let lyric_isolated = html.querySelector("#site > div > div > div > main > div > div > div.mxm-track-lyrics-container > div.container > div > div > div > div.col-sm-12.col-md-10.col-ml-9.col-lg-9 > div.mxm-lyrics.translated > div.row > div.col-xs-12.col-sm-12.col-md-12.col-ml-12.col-lg-12")
let raw_lines = lyric_isolated.getElementsByClassName("col-xs-6 col-sm-6 col-md-6 col-ml-6 col-lg-6")
let applied = 0;
for (let i = 1; applied < app.lyrics.length; i+=2) {
console.log("i = " + i + '\n' + raw_lines[i].childNodes[0].childNodes[0])
if (app.lyrics[applied].line === "lrcInstrumental") {
app.lyrics[applied+1].translation = raw_lines[i].childNodes[0].childNodes[0].textContent.replace(/\s+/g,' ');
applied +=2;
}
else if (app.lyrics[applied].translation == raw_lines[i].childNodes[0].childNodes[0].textContent.replace(/\s+/g,' ')) {
// Do nothing
}
else {
app.lyrics[applied].translation = raw_lines[i].childNodes[0].childNodes[0].textContent.replace(/\s+/g,' ');
applied +=1;
}
} catch (e) {
/// not found trans -> ignore
}
}
} catch (e) {
}
})
}
req2.open('POST', url2, true);
req2.send();
}
} catch (e) {console.debug("Error while parsing MXM Trans: " + e)}
}
if (track != "" & track != "No Title Found") {
getMXMSubs(track, artist, lang, time, id)
getMXMTrans(track, artist, lang, time, id)
getMXMSubs(track, artist, lang, time, id);
}
},
loadNeteaseLyrics() {