This commit is contained in:
booploops 2022-07-07 20:37:21 -07:00
commit 761d8d60cb
4 changed files with 43 additions and 111 deletions

View file

@ -243,7 +243,7 @@ export class Store {
"maxContentScale": -1 // -1 default, anything else is a custom scale "maxContentScale": -1 // -1 default, anything else is a custom scale
}, },
"lyrics": { "lyrics": {
"enable_mxm": false, "enable_mxm": true,
"mxm_karaoke": false, "mxm_karaoke": false,
"mxm_language": "en", "mxm_language": "en",
"enable_qq": false, "enable_qq": false,

View file

@ -3065,67 +3065,13 @@ const app = new Vue({
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 */
function getToken(mode, track, artist, songid, lang, time, id) {
if (attempt > 2) {
app.loadNeteaseLyrics();
// app.loadAMLyrics();
} else {
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 req = new XMLHttpRequest();
req.overrideMimeType("application/json");
req.open('GET', url, true);
req.setRequestHeader("authority", "apic-desktop.musixmatch.com");
req.onload = function () {
try {
let jsonResponse = JSON.parse(this.responseText);
let status2 = jsonResponse["message"]["header"]["status_code"];
if (status2 == 200) {
let token = jsonResponse["message"]["body"]["user_token"] ?? '';
if (token != "" && token != "UpgradeOnlyUpgradeOnlyUpgradeOnlyUpgradeOnly") {
console.debug('200 token', mode);
// token good
app.mxmtoken = token;
if (mode == 1) { function getMXMSubs(track, artist, lang, time, id) {
getMXMSubs(track, artist, app.mxmtoken, lang, time, id); let richsyncQuery = app.cfg.lyrics.mxm_karaoke
} else { let itunesid = (id && id != "") ? id : ''; // Mode 1 -> Subs
getMXMTrans(songid, lang, app.mxmtoken); let url = "https://api.cider.sh/v1/lyrics?" + "mode=1" + "&richsyncQuery=" + richsyncQuery + "&track=" + track + "&artist=" + artist + "&songID=" + itunesid + "&source=mxm" + "&lang=" + lang + "&time=" + time;
}
} 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();
}
};
req.onerror = function () {
console.log('error');
app.loadQQLyrics();
// app.loadAMLyrics();
};
req.send();
}
}
function getMXMSubs(track, artist, token, lang, time, id) {
let usertoken = encodeURIComponent(token);
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 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 req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.overrideMimeType("application/json"); req.overrideMimeType("application/json");
req.open('GET', url, true);
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);
@ -3152,7 +3098,7 @@ const app = new Vue({
// app.loadAMLyrics() // app.loadAMLyrics()
} else { } else {
if (richsync == [] || richsync.length == 0) { if (richsync == [] || richsync.length == 0) {
console.log("ok"); console.log("musixmatch worki");
// 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]/);
@ -3195,7 +3141,7 @@ const app = new Vue({
} }
if (lrcfile != null && lrcfile != '') { if (lrcfile != null && lrcfile != '') {
// load translation // load translation
getMXMTrans(id, lang, token); getMXMTrans(id, lang);
} else { } else {
// app.loadAMLyrics() // app.loadAMLyrics()
app.loadQQLyrics(); app.loadQQLyrics();
@ -3206,8 +3152,6 @@ const app = new Vue({
app.loadQQLyrics(); app.loadQQLyrics();
// app.loadAMLyrics() // app.loadAMLyrics()
} }
} else { //4xx rejected
getToken(1, track, artist, '', lang, time);
} }
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -3220,23 +3164,21 @@ const app = new Vue({
console.log('error'); console.log('error');
// app.loadAMLyrics(); // app.loadAMLyrics();
}; };
req.open('POST', url, true);
req.send(); req.send();
} }
function getMXMTrans(id, lang, token) { function getMXMTrans(lang, id) {
if (lang != "disabled" && id != '') { if (lang != "disabled" && id != '') { // Mode 2 -> Trans
let usertoken = encodeURIComponent(token); let url2 = "https://api.cider.sh/v1/lyrics?" + "mode=2" + "&richsyncQuery=false" + "&songID=" + id + "&source=mxm" + "&lang=" + lang + "&time=" + time;
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.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;
@ -3256,23 +3198,19 @@ const app = new Vue({
} catch (e) { } catch (e) {
/// not found trans -> ignore /// not found trans -> ignore
} }
} else { //4xx rejected
getToken(2, '', '', id, lang, '');
} }
} catch (e) { } catch (e) {
} }
} }
req2.open('POST', url2, true);
req2.send(); req2.send();
} }
} }
if (track != "" & track != "No Title Found") { if (track != "" & track != "No Title Found") {
if (app.mxmtoken != null && app.mxmtoken != '') { getMXMSubs(track, artist, lang, time, id)
getMXMSubs(track, artist, app.mxmtoken, lang, time, id) getMXMTrans(track, artist, lang, time, id)
} else {
getToken(1, track, artist, '', lang, time);
}
} }
}, },
loadNeteaseLyrics() { loadNeteaseLyrics() {
@ -4015,8 +3953,7 @@ const app = new Vue({
} }
try { try {
// document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`); // document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`);
} catch (e) { } catch (e) {}
}
} else { } else {
let data = await this.mk.api.v3.music(`/v1/me/library/songs/${this.mk.nowPlayingItem.id}`); let data = await this.mk.api.v3.music(`/v1/me/library/songs/${this.mk.nowPlayingItem.id}`);
data = data.data.data[0]; data = data.data.data[0];

View file

@ -704,21 +704,18 @@
<span>{{$root.getLz('settings.header.lyrics')}}</span> <span>{{$root.getLz('settings.header.lyrics')}}</span>
</div> </div>
<div class="settings-option-body"> <div class="settings-option-body">
<div style="opacity: 0.5; pointer-events: none;"> <div class="md-option-line">
<div class="md-option-line"> <div class="md-option-segment">
<div class="md-option-segment"> {{$root.getLz('settings.option.lyrics.enableMusixmatch')}}
{{$root.getLz('settings.option.lyrics.enableMusixmatch')}} </div>
</div> <div class="md-option-segment md-option-segment_auto">
<div class="md-option-segment md-option-segment_auto"> <label>
<label> <input type="checkbox" v-model="app.cfg.lyrics.enable_mxm" switch />
<input type="checkbox" switch checked /> </label>
</label>
<!-- <input type="checkbox" v-model="app.cfg.lyrics.enable_mxm" switch /> -->
</div>
</div> </div>
</div> </div>
<div class="md-option-line"> <div class="md-option-line">
<!-- <div class="md-option-line" v-if="app.cfg.lyrics.enable_mxm"> --> <div class="md-option-line" v-if="app.cfg.lyrics.enable_mxm">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.lyrics.enableMusixmatchKaraoke')}} {{$root.getLz('settings.option.lyrics.enableMusixmatchKaraoke')}}
</div> </div>

View file

@ -614,30 +614,28 @@
<span>{{$root.getLz('settings.header.lyrics')}}</span> <span>{{$root.getLz('settings.header.lyrics')}}</span>
</div> </div>
<div class="settings-option-body"> <div class="settings-option-body">
<div style="opacity: 0.5; pointer-events: none;">
<div class="md-option-line">
<div class="md-option-segment">
{{$root.getLz('settings.option.lyrics.enableMusixmatch')}}
</div>
<div class="md-option-segment md-option-segment_auto">
<label>
<input type="checkbox" switch checked/>
</label>
<!-- <input type="checkbox" v-model="app.cfg.lyrics.enable_mxm" switch /> -->
</div>
</div>
</div>
<div class="md-option-line"> <div class="md-option-line">
<!-- <div class="md-option-line" v-if="app.cfg.lyrics.enable_mxm"> -->
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.lyrics.enableMusixmatchKaraoke')}} {{$root.getLz('settings.option.lyrics.enableMusixmatch')}}
</div> </div>
<div class="md-option-segment md-option-segment_auto"> <div class="md-option-segment md-option-segment_auto">
<label> <label>
<input type="checkbox" v-model="app.cfg.lyrics.mxm_karaoke" switch/> <input type="checkbox" v-model="app.cfg.lyrics.enable_mxm" switch />
</label> </label>
</div> </div>
</div> </div>
<div class="md-option-line">
<div class="md-option-line" v-if="app.cfg.lyrics.enable_mxm">
<div class="md-option-segment">
{{$root.getLz('settings.option.lyrics.enableMusixmatchKaraoke')}}
</div>
<div class="md-option-segment md-option-segment_auto">
<label>
<input type="checkbox" v-model="app.cfg.lyrics.mxm_karaoke" switch/>
</label>
</div>
</div>
</div>
<div class="md-option-line"> <div class="md-option-line">
<div class="md-option-segment"> <div class="md-option-segment">
{{$root.getLz('settings.option.lyrics.musixmatchPreferredLanguage')}} {{$root.getLz('settings.option.lyrics.musixmatchPreferredLanguage')}}