chore: Prettified Code
[ci skip]
This commit is contained in:
parent
212874d2cb
commit
cf504b5b1f
1 changed files with 196 additions and 194 deletions
|
@ -3424,15 +3424,18 @@ 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 */
|
||||||
|
@ -3445,16 +3448,16 @@ const app = new Vue({
|
||||||
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;
|
||||||
|
|
||||||
|
@ -3464,21 +3467,21 @@ const app = new Vue({
|
||||||
getMXMTrans(songid, lang, app.mxmtoken);
|
getMXMTrans(songid, lang, app.mxmtoken);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.debug('fake 200 token');
|
console.debug("fake 200 token");
|
||||||
getToken(mode, track, artist, songid, lang, time)
|
getToken(mode, track, artist, songid, lang, time);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// console.log('token 4xx');
|
// console.log('token 4xx');
|
||||||
getToken(mode, track, artist, songid, lang, time)
|
getToken(mode, track, artist, songid, lang, time);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('error');
|
console.log("error");
|
||||||
app.loadQQLyrics();
|
app.loadQQLyrics();
|
||||||
//app.loadAMLyrics();
|
//app.loadAMLyrics();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
req.onerror = function () {
|
req.onerror = function () {
|
||||||
console.log('error');
|
console.log("error");
|
||||||
app.loadQQLyrics();
|
app.loadQQLyrics();
|
||||||
// app.loadAMLyrics();
|
// app.loadAMLyrics();
|
||||||
};
|
};
|
||||||
|
@ -3488,13 +3491,13 @@ const app = new Vue({
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
|
@ -3503,18 +3506,17 @@ const app = new Vue({
|
||||||
let status1 = jsonResponse["message"]["header"]["status_code"];
|
let status1 = jsonResponse["message"]["header"]["status_code"];
|
||||||
|
|
||||||
if (status1 == 200) {
|
if (status1 == 200) {
|
||||||
let id = '';
|
let id = "";
|
||||||
try {
|
try {
|
||||||
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"];
|
||||||
|
|
||||||
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"];
|
||||||
richsync = JSON.parse(lrcrich);
|
richsync = JSON.parse(lrcrich);
|
||||||
app.richlyrics = richsync;
|
app.richlyrics = richsync;
|
||||||
} catch (_) {
|
} catch (_) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lrcfile == "") {
|
if (lrcfile == "") {
|
||||||
|
@ -3524,25 +3526,25 @@ const app = new Vue({
|
||||||
if (richsync == [] || richsync.length == 0) {
|
if (richsync == [] || richsync.length == 0) {
|
||||||
console.log("ok");
|
console.log("ok");
|
||||||
// process lrcfile to json here
|
// process lrcfile to json here
|
||||||
app.lyricsMediaItem = lrcfile
|
app.lyricsMediaItem = lrcfile;
|
||||||
let u = app.lyricsMediaItem.split(/[\r\n]/);
|
let u = app.lyricsMediaItem.split(/[\r\n]/);
|
||||||
let preLrc = []
|
let preLrc = [];
|
||||||
for (var i = u.length - 1; i >= 0; i--) {
|
for (var i = u.length - 1; i >= 0; i--) {
|
||||||
let xline = (/(\[[0-9.:\[\]]*\])+(.*)/).exec(u[i])
|
let xline = /(\[[0-9.:\[\]]*\])+(.*)/.exec(u[i]);
|
||||||
let end = (preLrc.length > 0) ? ((preLrc[preLrc.length - 1].startTime) ?? 99999) : 99999
|
let end = preLrc.length > 0 ? preLrc[preLrc.length - 1].startTime ?? 99999 : 99999;
|
||||||
preLrc.push({
|
preLrc.push({
|
||||||
startTime: app.toMS(xline[1].substring(1, xline[1].length - 2)) ?? 0,
|
startTime: app.toMS(xline[1].substring(1, xline[1].length - 2)) ?? 0,
|
||||||
endTime: end,
|
endTime: end,
|
||||||
line: xline[2],
|
line: xline[2],
|
||||||
translation: ''
|
translation: "",
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (preLrc.length > 0)
|
if (preLrc.length > 0)
|
||||||
preLrc.push({
|
preLrc.push({
|
||||||
startTime: 0,
|
startTime: 0,
|
||||||
endTime: preLrc[preLrc.length - 1].startTime,
|
endTime: preLrc[preLrc.length - 1].startTime,
|
||||||
line: "lrcInstrumental",
|
line: "lrcInstrumental",
|
||||||
translation: ''
|
translation: "",
|
||||||
});
|
});
|
||||||
app.lyrics = preLrc.reverse();
|
app.lyrics = preLrc.reverse();
|
||||||
} else {
|
} else {
|
||||||
|
@ -3551,19 +3553,19 @@ const app = new Vue({
|
||||||
startTime: item.ts,
|
startTime: item.ts,
|
||||||
endTime: item.te,
|
endTime: item.te,
|
||||||
line: item.x,
|
line: item.x,
|
||||||
translation: ''
|
translation: "",
|
||||||
}
|
};
|
||||||
})
|
});
|
||||||
if (preLrc.length > 0)
|
if (preLrc.length > 0)
|
||||||
preLrc.unshift({
|
preLrc.unshift({
|
||||||
startTime: 0,
|
startTime: 0,
|
||||||
endTime: preLrc[0].startTime,
|
endTime: preLrc[0].startTime,
|
||||||
line: "lrcInstrumental",
|
line: "lrcInstrumental",
|
||||||
translation: ''
|
translation: "",
|
||||||
});
|
});
|
||||||
app.lyrics = preLrc;
|
app.lyrics = preLrc;
|
||||||
}
|
}
|
||||||
if (lrcfile != null && lrcfile != '') {
|
if (lrcfile != null && lrcfile != "") {
|
||||||
// load translation
|
// load translation
|
||||||
getMXMTrans(id, lang, token);
|
getMXMTrans(id, lang, token);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3576,30 +3578,31 @@ const app = new Vue({
|
||||||
app.loadQQLyrics();
|
app.loadQQLyrics();
|
||||||
// app.loadAMLyrics()
|
// app.loadAMLyrics()
|
||||||
}
|
}
|
||||||
} else { //4xx rejected
|
} else {
|
||||||
getToken(1, track, artist, '', lang, time);
|
//4xx rejected
|
||||||
|
getToken(1, track, artist, "", lang, time);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
app.loadQQLyrics();
|
app.loadQQLyrics();
|
||||||
//app.loadAMLyrics()
|
//app.loadAMLyrics()
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
req.onerror = function () {
|
req.onerror = function () {
|
||||||
app.loadQQLyrics();
|
app.loadQQLyrics();
|
||||||
console.log('error');
|
console.log("error");
|
||||||
// app.loadAMLyrics();
|
// 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 {
|
||||||
|
@ -3608,12 +3611,12 @@ const app = new Vue({
|
||||||
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"];
|
||||||
|
@ -3626,22 +3629,21 @@ const app = new Vue({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
/// not found trans -> ignore
|
/// not found trans -> ignore
|
||||||
}
|
}
|
||||||
} else { //4xx rejected
|
} else {
|
||||||
getToken(2, '', '', id, lang, '');
|
//4xx rejected
|
||||||
}
|
getToken(2, "", "", id, lang, "");
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
req2.send();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue