This commit is contained in:
vapormusic 2022-11-16 23:57:29 +07:00
commit 8c5615d222

View file

@ -3424,227 +3424,229 @@ const app = new Vue({
}, },
loadMXM() { loadMXM() {
let attempt = 0; let attempt = 0;
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);
const id = encodeURIComponent((this.mk.nowPlayingItem != null) ? app.mk.nowPlayingItem._songId ?? (app.mk.nowPlayingItem["songId"] ?? '') : ''); const id = encodeURIComponent(this.mk.nowPlayingItem != null ? app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem["songId"] ?? "" : "");
let lrcfile = ""; let lrcfile = "";
let richsync = []; let richsync = [];
const lang = app.cfg.lyrics.mxm_language // translation language const lang = app.cfg.lyrics.mxm_language; // translation language
function revisedRandId() { function revisedRandId() {
return Math.random().toString(36).replace(/[^a-z]+/g, '').slice(2, 10); return Math.random()
.toString(36)
.replace(/[^a-z]+/g, "")
.slice(2, 10);
} }
/* get token */ /* get token */
function getToken(mode, track, artist, songid, lang, time, id) { function getToken(mode, track, artist, songid, lang, time, id) {
if (attempt > 2) { if (attempt > 2) {
app.loadNeteaseLyrics(); app.loadNeteaseLyrics();
// app.loadAMLyrics(); // app.loadAMLyrics();
} else { } else {
attempt = attempt + 1; attempt = attempt + 1;
let url = "https://apic-desktop.musixmatch.com/ws/1.1/token.get?app_id=web-desktop-app-v1.0&t=" + revisedRandId(); let url = "https://apic-desktop.musixmatch.com/ws/1.1/token.get?app_id=web-desktop-app-v1.0&t=" + revisedRandId();
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.overrideMimeType("application/json"); req.overrideMimeType("application/json");
req.open('GET', url, true); req.open("GET", url, true);
req.setRequestHeader("authority", "apic-desktop.musixmatch.com"); req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req.onload = function () { req.onload = function () {
try { try {
let jsonResponse = JSON.parse(this.responseText); let jsonResponse = JSON.parse(this.responseText);
let status2 = jsonResponse["message"]["header"]["status_code"]; let status2 = jsonResponse["message"]["header"]["status_code"];
if (status2 == 200) { if (status2 == 200) {
let token = jsonResponse["message"]["body"]["user_token"] ?? ''; let token = jsonResponse["message"]["body"]["user_token"] ?? "";
if (token != "" && token != "UpgradeOnlyUpgradeOnlyUpgradeOnlyUpgradeOnly") { if (token != "" && token != "UpgradeOnlyUpgradeOnlyUpgradeOnlyUpgradeOnly") {
console.debug('200 token', mode); console.debug("200 token", mode);
// token good // token good
app.mxmtoken = token; app.mxmtoken = token;
if (mode == 1) { if (mode == 1) {
getMXMSubs(track, artist, app.mxmtoken, lang, time, id); getMXMSubs(track, artist, app.mxmtoken, lang, time, id);
} else { } else {
getMXMTrans(songid, lang, app.mxmtoken); getMXMTrans(songid, lang, app.mxmtoken);
}
} else {
console.debug('fake 200 token');
getToken(mode, track, artist, songid, lang, time)
}
} else {
// console.log('token 4xx');
getToken(mode, track, artist, songid, lang, time)
}
} catch (e) {
console.log('error');
app.loadQQLyrics();
//app.loadAMLyrics();
} }
}; } else {
req.onerror = function () { console.debug("fake 200 token");
console.log('error'); getToken(mode, track, artist, songid, lang, time);
app.loadQQLyrics(); }
// app.loadAMLyrics(); } else {
}; // console.log('token 4xx');
req.send(); getToken(mode, track, artist, songid, lang, time);
} }
} catch (e) {
console.log("error");
app.loadQQLyrics();
//app.loadAMLyrics();
}
};
req.onerror = function () {
console.log("error");
app.loadQQLyrics();
// app.loadAMLyrics();
};
req.send();
}
} }
function getMXMSubs(track, artist, token, lang, time, id) { function getMXMSubs(track, artist, token, lang, time, id) {
let usertoken = encodeURIComponent(token); let usertoken = encodeURIComponent(token);
let richsyncQuery = (app.cfg.lyrics.mxm_karaoke) ? "&optional_calls=track.richsync" : "" let richsyncQuery = app.cfg.lyrics.mxm_karaoke ? "&optional_calls=track.richsync" : "";
let timecustom = (!time || (time && time < 0)) ? '' : `&f_subtitle_length=${time}&q_duration=${time}&f_subtitle_length_max_deviation=40`; let timecustom = !time || (time && time < 0) ? "" : `&f_subtitle_length=${time}&q_duration=${time}&f_subtitle_length_max_deviation=40`;
let itunesid = (id && id != "") ? `&track_itunes_id=${id}` : ''; let itunesid = id && id != "" ? `&track_itunes_id=${id}` : "";
let url = "https://apic-desktop.musixmatch.com/ws/1.1/macro.subtitles.get?format=json&namespace=lyrics_richsynched" + richsyncQuery + "&subtitle_format=lrc&q_artist=" + artist + "&q_track=" + track + itunesid + "&usertoken=" + usertoken + timecustom + "&app_id=web-desktop-app-v1.0&t=" + revisedRandId(); let url = "https://apic-desktop.musixmatch.com/ws/1.1/macro.subtitles.get?format=json&namespace=lyrics_richsynched" + richsyncQuery + "&subtitle_format=lrc&q_artist=" + artist + "&q_track=" + track + itunesid + "&usertoken=" + usertoken + timecustom + "&app_id=web-desktop-app-v1.0&t=" + revisedRandId();
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.overrideMimeType("application/json"); req.overrideMimeType("application/json");
req.open('GET', url, true); req.open("GET", url, true);
req.setRequestHeader("authority", "apic-desktop.musixmatch.com"); req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req.onload = function () { req.onload = function () {
try {
let jsonResponse = JSON.parse(this.responseText);
console.debug(jsonResponse);
let status1 = jsonResponse["message"]["header"]["status_code"];
if (status1 == 200) {
let id = "";
try { try {
let jsonResponse = JSON.parse(this.responseText); 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) {
console.debug(jsonResponse); id = jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["body"]["track"]["track_id"] ?? "";
let status1 = jsonResponse["message"]["header"]["status_code"]; lrcfile = jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["body"]["subtitle_list"][0]["subtitle"]["subtitle_body"];
if (status1 == 200) { try {
let id = ''; let lrcrich = jsonResponse["message"]["body"]["macro_calls"]["track.richsync.get"]["message"]["body"]["richsync"]["richsync_body"];
try { richsync = JSON.parse(lrcrich);
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) { app.richlyrics = richsync;
id = jsonResponse["message"]["body"]["macro_calls"]["matcher.track.get"]["message"]["body"]["track"]["track_id"] ?? ''; } catch (_) {}
lrcfile = jsonResponse["message"]["body"]["macro_calls"]["track.subtitles.get"]["message"]["body"]["subtitle_list"][0]["subtitle"]["subtitle_body"]; }
try { if (lrcfile == "") {
let lrcrich = jsonResponse["message"]["body"]["macro_calls"]["track.richsync.get"]["message"]["body"]["richsync"]["richsync_body"];
richsync = JSON.parse(lrcrich);
app.richlyrics = richsync;
} catch (_) {
}
}
if (lrcfile == "") {
app.loadQQLyrics();
// app.loadAMLyrics()
} else {
if (richsync == [] || richsync.length == 0) {
console.log("ok");
// process lrcfile to json here
app.lyricsMediaItem = lrcfile
let u = app.lyricsMediaItem.split(/[\r\n]/);
let preLrc = []
for (var i = u.length - 1; i >= 0; i--) {
let xline = (/(\[[0-9.:\[\]]*\])+(.*)/).exec(u[i])
let end = (preLrc.length > 0) ? ((preLrc[preLrc.length - 1].startTime) ?? 99999) : 99999
preLrc.push({
startTime: app.toMS(xline[1].substring(1, xline[1].length - 2)) ?? 0,
endTime: end,
line: xline[2],
translation: ''
})
}
if (preLrc.length > 0)
preLrc.push({
startTime: 0,
endTime: preLrc[preLrc.length - 1].startTime,
line: "lrcInstrumental",
translation: ''
});
app.lyrics = preLrc.reverse();
} else {
let preLrc = richsync.map(function (item) {
return {
startTime: item.ts,
endTime: item.te,
line: item.x,
translation: ''
}
})
if (preLrc.length > 0)
preLrc.unshift({
startTime: 0,
endTime: preLrc[0].startTime,
line: "lrcInstrumental",
translation: ''
});
app.lyrics = preLrc;
}
if (lrcfile != null && lrcfile != '') {
// load translation
getMXMTrans(id, lang, token);
} else {
// app.loadAMLyrics()
app.loadQQLyrics();
}
}
} catch (e) {
console.log(e);
app.loadQQLyrics();
// app.loadAMLyrics()
}
} else { //4xx rejected
getToken(1, track, artist, '', lang, time);
}
} catch (e) {
console.log(e);
app.loadQQLyrics(); app.loadQQLyrics();
//app.loadAMLyrics() // app.loadAMLyrics()
} else {
if (richsync == [] || richsync.length == 0) {
console.log("ok");
// process lrcfile to json here
app.lyricsMediaItem = lrcfile;
let u = app.lyricsMediaItem.split(/[\r\n]/);
let preLrc = [];
for (var i = u.length - 1; i >= 0; i--) {
let xline = /(\[[0-9.:\[\]]*\])+(.*)/.exec(u[i]);
let end = preLrc.length > 0 ? preLrc[preLrc.length - 1].startTime ?? 99999 : 99999;
preLrc.push({
startTime: app.toMS(xline[1].substring(1, xline[1].length - 2)) ?? 0,
endTime: end,
line: xline[2],
translation: "",
});
}
if (preLrc.length > 0)
preLrc.push({
startTime: 0,
endTime: preLrc[preLrc.length - 1].startTime,
line: "lrcInstrumental",
translation: "",
});
app.lyrics = preLrc.reverse();
} else {
let preLrc = richsync.map(function (item) {
return {
startTime: item.ts,
endTime: item.te,
line: item.x,
translation: "",
};
});
if (preLrc.length > 0)
preLrc.unshift({
startTime: 0,
endTime: preLrc[0].startTime,
line: "lrcInstrumental",
translation: "",
});
app.lyrics = preLrc;
}
if (lrcfile != null && lrcfile != "") {
// load translation
getMXMTrans(id, lang, token);
} else {
// app.loadAMLyrics()
app.loadQQLyrics();
}
}
} catch (e) {
console.log(e);
app.loadQQLyrics();
// app.loadAMLyrics()
} }
} else {
//4xx rejected
getToken(1, track, artist, "", lang, time);
}
} catch (e) {
console.log(e);
app.loadQQLyrics();
//app.loadAMLyrics()
} }
req.onerror = function () { };
app.loadQQLyrics(); req.onerror = function () {
console.log('error'); app.loadQQLyrics();
// app.loadAMLyrics(); console.log("error");
}; // app.loadAMLyrics();
req.send(); };
req.send();
} }
function getMXMTrans(id, lang, token) { function getMXMTrans(id, lang, token) {
if (lang != "disabled" && id != '') { if (lang != "disabled" && id != "") {
let usertoken = encodeURIComponent(token); let usertoken = encodeURIComponent(token);
let url2 = "https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&selected_language=" + lang + "&track_id=" + id + "&comment_format=text&part=user&format=json&usertoken=" + usertoken + "&app_id=web-desktop-app-v1.0&t=" + revisedRandId(); let url2 = "https://apic-desktop.musixmatch.com/ws/1.1/crowd.track.translations.get?translation_fields_set=minimal&selected_language=" + lang + "&track_id=" + id + "&comment_format=text&part=user&format=json&usertoken=" + usertoken + "&app_id=web-desktop-app-v1.0&t=" + revisedRandId();
let req2 = new XMLHttpRequest(); let req2 = new XMLHttpRequest();
req2.overrideMimeType("application/json"); req2.overrideMimeType("application/json");
req2.open('GET', url2, true); req2.open("GET", url2, true);
req2.setRequestHeader("authority", "apic-desktop.musixmatch.com"); req2.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req2.onload = function () { req2.onload = function () {
try { try {
let jsonResponse2 = JSON.parse(this.responseText); let jsonResponse2 = JSON.parse(this.responseText);
console.log(jsonResponse2); console.log(jsonResponse2);
let status2 = jsonResponse2["message"]["header"]["status_code"]; let status2 = jsonResponse2["message"]["header"]["status_code"];
if (status2 == 200) { if (status2 == 200) {
try { try {
let preTrans = [] let preTrans = [];
let u = app.lyrics; let u = app.lyrics;
let translation_list = jsonResponse2["message"]["body"]["translations_list"]; let translation_list = jsonResponse2["message"]["body"]["translations_list"];
if (translation_list.length > 0) { if (translation_list.length > 0) {
for (var i = 0; i < u.length - 1; i++) { for (var i = 0; i < u.length - 1; i++) {
preTrans[i] = "" preTrans[i] = "";
for (var trans_line of translation_list) { for (var trans_line of translation_list) {
if (u[i].line == " " + trans_line["translation"]["matched_line"] || u[i].line == trans_line["translation"]["matched_line"]) { if (u[i].line == " " + trans_line["translation"]["matched_line"] || u[i].line == trans_line["translation"]["matched_line"]) {
u[i].translation = trans_line["translation"]["description"]; u[i].translation = trans_line["translation"]["description"];
break; break;
} }
}
}
app.lyrics = u;
}
} catch (e) {
/// not found trans -> ignore
}
} else { //4xx rejected
getToken(2, '', '', id, lang, '');
} }
} catch (e) { }
app.lyrics = u;
} }
} catch (e) {
/// not found trans -> ignore
}
} else {
//4xx rejected
getToken(2, "", "", id, lang, "");
} }
req2.send(); } catch (e) {}
} };
req2.send();
}
} }
if (track != "" & track != "No Title Found") { if ((track != "") & (track != "No Title Found")) {
if (app.mxmtoken != null && app.mxmtoken != '') { if (app.mxmtoken != null && app.mxmtoken != "") {
getMXMSubs(track, artist, app.mxmtoken, lang, time, id) getMXMSubs(track, artist, app.mxmtoken, lang, time, id);
} else { } else {
getToken(1, track, artist, '', lang, time); getToken(1, track, artist, "", lang, time);
} }
} }
}, },
loadNeteaseLyrics() { loadNeteaseLyrics() {
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 ?? "" : "");