add lyrics & fix playlists

This commit is contained in:
vapormusic 2022-04-12 22:34:09 +07:00
parent a5f73117fb
commit 09b4c9fe97
4 changed files with 82 additions and 10 deletions

View file

@ -593,6 +593,10 @@ export class BrowserWindow {
if (itspod != null) if (itspod != null)
details.requestHeaders["Cookie"] = `itspod=${itspod}`; details.requestHeaders["Cookie"] = `itspod=${itspod}`;
} }
if (details.url.startsWith("https://music.163.com")) {
details.requestHeaders["Referer"] = "https://music.163.com/";
details.requestHeaders["user-agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cider/1.0.0 Chrome/96.0.4664.45 Electron/16.0.0 Safari/537.36";
}
callback({requestHeaders: details.requestHeaders}); callback({requestHeaders: details.requestHeaders});
} }
); );

View file

@ -2685,7 +2685,8 @@ const app = new Vue({
/* 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.loadAMLyrics(); app.loadNeteaseLyrics();
// 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();
@ -2719,12 +2720,14 @@ const app = new Vue({
} }
} catch (e) { } catch (e) {
console.log('error'); console.log('error');
app.loadAMLyrics(); app.loadNeteaseLyrics();
//app.loadAMLyrics();
} }
}; };
req.onerror = function () { req.onerror = function () {
console.log('error'); console.log('error');
app.loadAMLyrics(); app.loadNeteaseLyrics();
// app.loadAMLyrics();
}; };
req.send(); req.send();
} }
@ -2762,7 +2765,8 @@ const app = new Vue({
} }
if (lrcfile == "") { if (lrcfile == "") {
app.loadAMLyrics() app.loadNeteaseLyrics();
// app.loadAMLyrics()
} else { } else {
if (richsync == [] || richsync.length == 0) { if (richsync == [] || richsync.length == 0) {
console.log("ok"); console.log("ok");
@ -2810,24 +2814,28 @@ const app = new Vue({
// load translation // load translation
getMXMTrans(id, lang, token); getMXMTrans(id, lang, token);
} else { } else {
app.loadAMLyrics() // app.loadAMLyrics()
app.loadNeteaseLyrics();
} }
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
app.loadAMLyrics() app.loadNeteaseLyrics();
// app.loadAMLyrics()
} }
} else { //4xx rejected } else { //4xx rejected
getToken(1, track, artist, '', lang, time); getToken(1, track, artist, '', lang, time);
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
app.loadAMLyrics() app.loadNeteaseLyrics();
//app.loadAMLyrics()
} }
} }
req.onerror = function () { req.onerror = function () {
app.loadNeteaseLyrics();
console.log('error'); console.log('error');
app.loadAMLyrics(); // app.loadAMLyrics();
}; };
req.send(); req.send();
} }
@ -2883,6 +2891,66 @@ const app = new Vue({
} }
} }
}, },
loadNeteaseLyrics() {
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);
var url = `http://music.163.com/api/search/get/?csrf_token=hlpretag=&hlposttag=&s=${track+" "+artist}&type=1&offset=0&total=true&limit=6`;
var req = new XMLHttpRequest();
req.overrideMimeType("application/json");
req.open('GET', url, true);
req.onload = function () {
try {
var jsonResponse = JSON.parse(req.responseText);
var id = jsonResponse["result"]["songs"][0]["id"];
var url2 = "https://music.163.com/api/song/lyric?os=pc&id=" + id + "&lv=-1&kv=-1&tv=-1";
var req2 = new XMLHttpRequest();
req2.overrideMimeType("application/json");
req2.open('GET', url2, true);
req2.onload = function () {
try {
var jsonResponse2 = JSON.parse(req2.responseText);
var lrcfile = jsonResponse2["lrc"]["lyric"];
app.lyricsMediaItem = lrcfile
let u = app.lyricsMediaItem.split(/[\n]/);
let preLrc = []
for (var i = u.length - 1; i >= 0; i--) {
let xline = (/(\[[0-9.:\[\]]*\])+(.*)/).exec(u[i])
if (xline != null) {
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();
}
catch (e) {
app.lyrics = "";
}
};
req2.onerror = function(){
}
req2.send();
} catch (e) {
app.lyrics = "";
}
};
req.send();
req.onerror = function(){
}
},
toMS(str) { toMS(str) {
let rawTime = str.match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/); let rawTime = str.match(/(\d+:)?(\d+:)?(\d+)(\.\d+)?/);
let hours = (rawTime[2] != null) ? (rawTime[1].replace(":", "")) : 0; let hours = (rawTime[2] != null) ? (rawTime[1].replace(":", "")) : 0;

View file

@ -47,7 +47,7 @@
{{getArtistName(data)}} {{getArtistName(data)}}
</div> </div>
<template v-if="useArtistChip"> <template v-if="useArtistChip">
<artist-chip v-for="artist in data.relationships.artists.data" <artist-chip v-for="artist in data.relationships.artists?.data"
:item="artist"></artist-chip> :item="artist"></artist-chip>
</template> </template>
<div class="playlist-desc" v-if="(data.attributes.description && (data.attributes.description.standard || data.attributes.description.short)) || (data.attributes.editorialNotes && (data.attributes.editorialNotes.standard || data.attributes.editorialNotes.short))"> <div class="playlist-desc" v-if="(data.attributes.description && (data.attributes.description.standard || data.attributes.description.short)) || (data.attributes.editorialNotes && (data.attributes.editorialNotes.standard || data.attributes.editorialNotes.short))">

View file

@ -55,7 +55,7 @@
{{getArtistName(data)}} {{getArtistName(data)}}
</div> </div>
<template v-if="useArtistChip"> <template v-if="useArtistChip">
<artist-chip v-for="artist in data.relationships.artists.data" <artist-chip v-for="artist in data.relationships.artists?.data"
:item="artist"></artist-chip> :item="artist"></artist-chip>
</template> </template>
<div class="playlist-desc" v-if="(data.attributes.description && (data.attributes.description.standard || data.attributes.description.short)) || (data.attributes.editorialNotes && (data.attributes.editorialNotes.standard || data.attributes.editorialNotes.short))"> <div class="playlist-desc" v-if="(data.attributes.description && (data.attributes.description.standard || data.attributes.description.short)) || (data.attributes.editorialNotes && (data.attributes.editorialNotes.standard || data.attributes.editorialNotes.short))">