the amount of brain cells that I have lost because of mxm trans
This commit is contained in:
parent
abc8a4decb
commit
4c08d075ff
1 changed files with 39 additions and 44 deletions
|
@ -3054,7 +3054,7 @@ const app = new Vue({
|
||||||
const track = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.title ?? '' : '');
|
const track = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.title ?? '' : '');
|
||||||
const artist = encodeURIComponent((this.mk.nowPlayingItem != null) ? this.mk.nowPlayingItem.artistName ?? '' : '');
|
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);
|
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('')}
|
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"] ?? '') : '');}
|
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) {
|
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"] ?? '';
|
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"];
|
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 {
|
try {
|
||||||
let lrcrich = jsonResponse["message"]["body"]["macro_calls"]["track.richsync.get"]["message"]["body"]["richsync"]["richsync_body"];
|
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;
|
app.lyrics = preLrc;
|
||||||
}
|
}
|
||||||
if (lrcfile != null && lrcfile != '') {
|
|
||||||
// load translation
|
// Load translation
|
||||||
getMXMTrans(id, lang);
|
getMXMTrans(lang, vanity_id);
|
||||||
} else {
|
|
||||||
// app.loadAMLyrics()
|
|
||||||
app.loadQQLyrics();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
@ -3168,49 +3166,46 @@ const app = new Vue({
|
||||||
req.send();
|
req.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMXMTrans(lang, id) {
|
function getMXMTrans(lang, vanity_id) {
|
||||||
if (lang != "disabled" && id != '') { // Mode 2 -> Trans
|
lang = 'english';
|
||||||
let url2 = "https://api.cider.sh/v1/lyrics?" + "mode=2" + "&richsyncQuery=false" + "&songID=" + id + "&source=mxm" + "&lang=" + lang + "&time=" + time;
|
try {
|
||||||
let req2 = new XMLHttpRequest();
|
if (lang != "disabled" && vanity_id != '') { // Mode 2 -> Trans
|
||||||
req2.overrideMimeType("application/json");
|
fetch('https://www.musixmatch.com/lyrics/' + vanity_id +'/translation/' + lang, {
|
||||||
req2.onload = function () {
|
method: 'GET',
|
||||||
try {
|
headers: {
|
||||||
let jsonResponse2 = JSON.parse(this.responseText);
|
'Host': 'musixmatch.com',
|
||||||
console.log(jsonResponse2);
|
'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",
|
||||||
let status2 = jsonResponse2["message"]["header"]["status_code"];
|
'authority': "www.musixmatch.com"
|
||||||
if (status2 === 200) {
|
},
|
||||||
try {
|
})
|
||||||
let preTrans = []
|
.then(async (res) => {
|
||||||
let u = app.lyrics;
|
let html = document.createElement('html'); html.innerHTML = await res.text()
|
||||||
let translation_list = jsonResponse2["message"]["body"]["translations_list"];
|
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")
|
||||||
if (translation_list.length > 0) {
|
let raw_lines = lyric_isolated.getElementsByClassName("col-xs-6 col-sm-6 col-md-6 col-ml-6 col-lg-6")
|
||||||
for (var i = 0; i < u.length - 1; i++) {
|
let applied = 0;
|
||||||
preTrans[i] = ""
|
|
||||||
for (var trans_line of translation_list) {
|
for (let i = 1; applied < app.lyrics.length; i+=2) {
|
||||||
if (u[i].line == " " + trans_line["translation"]["matched_line"] || u[i].line == trans_line["translation"]["matched_line"]) {
|
console.log("i = " + i + '\n' + raw_lines[i].childNodes[0].childNodes[0])
|
||||||
u[i].translation = trans_line["translation"]["description"];
|
if (app.lyrics[applied].line === "lrcInstrumental") {
|
||||||
break;
|
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,' ')) {
|
||||||
app.lyrics = u;
|
// 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);
|
} catch (e) {console.debug("Error while parsing MXM Trans: " + e)}
|
||||||
req2.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (track != "" & track != "No Title Found") {
|
if (track != "" & track != "No Title Found") {
|
||||||
getMXMSubs(track, artist, lang, time, id)
|
getMXMSubs(track, artist, lang, time, id);
|
||||||
getMXMTrans(track, artist, lang, time, id)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loadNeteaseLyrics() {
|
loadNeteaseLyrics() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue