This commit is contained in:
child_duckling 2022-01-16 19:08:18 -08:00
parent 919729f618
commit 6b82771697

View file

@ -378,8 +378,7 @@ const app = new Vue({
let data = await response.text();
return data;
},
getSocialBadges(cb = () => {
}) {
getSocialBadges(cb = () => {}) {
let self = this
try {
app.mk.api.v3.music("/v1/social/badging-map").then(data => {
@ -464,9 +463,7 @@ const app = new Vue({
}
this.modals.addToPlaylist = false
await app.mk.api.v3.music(
`/v1/me/library/playlists/${playlist_id}/tracks`,
{},
{
`/v1/me/library/playlists/${playlist_id}/tracks`, {}, {
fetchOptions: {
method: "POST",
body: JSON.stringify({
@ -486,6 +483,7 @@ const app = new Vue({
this.mk = MusicKit.getInstance()
this.mk.authorize().then(() => {
self.mkIsReady = true
document.location.reload()
})
this.$forceUpdate()
if (this.isDev) {
@ -561,7 +559,8 @@ const app = new Vue({
lastItem = JSON.parse(lastItem)
let kind = lastItem.attributes.playParams.kind;
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
app.mk.setQueue({[truekind]: [lastItem.attributes.playParams.id]})
app.mk.setQueue({
[truekind]: [lastItem.attributes.playParams.id] })
app.mk.mute()
setTimeout(() => {
app.mk.play().then(() => {
@ -580,8 +579,7 @@ const app = new Vue({
if (!(i == 0 && ids[0] == lastItem.attributes.playParams.id)) {
try {
app.mk.playLater({ songs: [id] })
} catch (err) {
}
} catch (err) {}
}
i++;
}
@ -630,8 +628,7 @@ const app = new Vue({
let previewURL = null
try {
previewURL = app.mk.nowPlayingItem.previewURL
} catch (e) {
}
} catch (e) {}
if (!previewURL) {
app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${app.mk.nowPlayingItem._songId ?? app.mk.nowPlayingItem.relationships.catalog.data[0].id}`).then((response) => {
previewURL = response.data.data[0].attributes.previews[0].url
@ -643,14 +640,12 @@ const app = new Vue({
ipcRenderer.send('getPreviewURL', previewURL)
}
} catch (e) {
}
} catch (e) {}
}
try {
a = a.item.attributes;
} catch (_) {
}
} catch (_) {}
let type = (self.mk.nowPlayingItem != null) ? self.mk.nowPlayingItem["type"] ? ? '' : '';
if (type.includes("musicVideo") || type.includes("uploadedVideo") || type.includes("music-movie")) {
@ -777,8 +772,7 @@ const app = new Vue({
},
playlistHeaderContextMenu(event) {
let menu = {
items: [
{
items: [{
name: "New Playlist",
action: () => {
this.newPlaylist()
@ -797,9 +791,7 @@ const app = new Vue({
async editPlaylistFolder(id, name = "New Playlist") {
let self = this
this.mk.api.v3.music(
`/v1/me/library/playlist-folders/${id}`,
{},
{
`/v1/me/library/playlist-folders/${id}`, {}, {
fetchOptions: {
method: "PATCH",
body: JSON.stringify({
@ -814,9 +806,7 @@ const app = new Vue({
async editPlaylist(id, name = "New Playlist") {
let self = this
this.mk.api.v3.music(
`/v1/me/library/playlists/${id}`,
{},
{
`/v1/me/library/playlists/${id}`, {}, {
fetchOptions: {
method: "PATCH",
body: JSON.stringify({
@ -839,23 +829,17 @@ const app = new Vue({
if (tracks.length > 0) {
request.tracks = tracks
}
app.mk.api.v3.music(`/v1/me/library/playlists`, {},
{
app.mk.api.v3.music(`/v1/me/library/playlists`, {}, {
fetchOptions: {
method: "POST",
body: JSON.stringify(
{
"attributes":
{ "name": name },
"relationships":
{ "tracks":
{ "data": tracks },
body: JSON.stringify({
"attributes": { "name": name },
"relationships": {
"tracks": { "data": tracks },
}
})
}
)
}
}
).then(res => {
}).then(res => {
res = res.data.data[0]
console.log(res)
self.appRoute(`playlist_` + res.id);
@ -877,13 +861,11 @@ const app = new Vue({
deletePlaylist(id) {
let self = this
if (confirm(`Are you sure you want to delete this playlist?`)) {
app.mk.api.v3.music(`/v1/me/library/playlists/${id}`, {},
{
app.mk.api.v3.music(`/v1/me/library/playlists/${id}`, {}, {
fetchOptions: {
method: "DELETE"
}
}
).then(res => {
}).then(res => {
// remove this playlist from playlists.listing if it exists
let found = self.playlists.listing.find(item => item.id == id)
if (found) {
@ -1076,7 +1058,8 @@ const app = new Vue({
return `${mins}:${seconds.replace("0.", "")}`
},
hashCode(str) {
let hash = 0, i, chr;
let hash = 0,
i, chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
@ -1112,8 +1095,7 @@ const app = new Vue({
},
routeView(item) {
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ? ? (item.type ? ? '')) : (item.type ? ? ''));
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));
;
let id = (item.attributes.playParams ? (item.attributes.playParams.id ? ? (item.id ? ? '')) : (item.id ? ? ''));;
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ? ? false) : false;
console.log(kind, id, isLibrary)
@ -1195,8 +1177,7 @@ const app = new Vue({
artistId = artistId.substring(artistId.lastIndexOf('ids=') + 4, artistId.lastIndexOf('-'))
}
}
} catch (_) {
}
} catch (_) {}
if (artistId == "") {
let artistQuery = (await app.mk.api.v3.music(`v1/catalog/${app.mk.storefrontId}/search?term=${item.attributes.artistName}`, {
@ -1208,8 +1189,7 @@ const app = new Vue({
artistId = artistQuery.artists.data[0].id;
console.log(artistId)
}
} catch (e) {
}
} catch (e) {}
}
console.log(artistId);
if (artistId != "")
@ -1230,8 +1210,7 @@ const app = new Vue({
albumId = albumId.substring(0, albumId.indexOf("?i="))
}
}
} catch (_) {
}
} catch (_) {}
if (albumId == "") {
try {
@ -1243,8 +1222,7 @@ const app = new Vue({
albumId = albumQuery.albums.data[0].id;
console.log(albumId)
}
} catch (e) {
}
} catch (e) {}
}
if (albumId != "") {
self.appRoute(`album/${albumId}`)
@ -1254,8 +1232,7 @@ const app = new Vue({
let labelId = '';
try {
labelId = item.relationships['record-labels'].data[0].id
} catch (_) {
}
} catch (_) {}
if (labelId == "") {
try {
@ -1267,8 +1244,7 @@ const app = new Vue({
labelId = labelQuery["record-labels"].data[0].id;
console.log(labelId)
}
} catch (e) {
}
} catch (e) {}
}
if (labelId != "") {
app.showingPlaylist = []
@ -1289,8 +1265,7 @@ const app = new Vue({
},
playMediaItem(item) {
let kind = (item.attributes.playParams ? (item.attributes.playParams.kind ? ? (item.type ? ? '')) : (item.type ? ? ''));
let id = (item.attributes.playParams ? (item.attributes.playParams.id ?? (item.id ?? '')) : (item.id ?? ''));
;
let id = (item.attributes.playParams ? (item.attributes.playParams.id ? ? (item.id ? ? '')) : (item.id ? ? ''));;
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ? ? false) : false;
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
console.log(kind, id, isLibrary)
@ -1398,8 +1373,7 @@ const app = new Vue({
} else {
this.getPlaylistContinuous(a)
}
}
;
};
},
searchLibrarySongs() {
let self = this
@ -1906,8 +1880,7 @@ const app = new Vue({
return
}
try {
this.listennow = (await this.mk.api.v3.music(`v1/me/recommendations?timezone=${encodeURIComponent(this.formatTimezoneOffset())}`,
{
this.listennow = (await this.mk.api.v3.music(`v1/me/recommendations?timezone=${encodeURIComponent(this.formatTimezoneOffset())}`, {
name: "listen-now",
with: "friendsMix,library,social",
"art[social-profiles:url]": "c",
@ -1929,8 +1902,7 @@ const app = new Vue({
"meta[stations]": "inflectionPoints",
types: "artists,albums,editorial-items,library-albums,library-playlists,music-movies,music-videos,playlists,stations,uploaded-audios,uploaded-videos,activities,apple-curators,curators,tv-shows,social-upsells",
platform: "web"
},
{
}, {
includeResponseMeta: !0,
reload: !0
})).data;
@ -1968,8 +1940,7 @@ const app = new Vue({
return
}
try {
this.radio.personal = (await app.mk.api.v3.music(`/v1/me/recent/radio-stations`,
{
this.radio.personal = (await app.mk.api.v3.music(`/v1/me/recent/radio-stations`, {
"platform": "web",
"art[url]": "f"
})).data.data;
@ -1993,9 +1964,7 @@ const app = new Vue({
newPlaylistFolder(name = "New Folder") {
let self = this
this.mk.api.v3.music(
"/v1/me/library/playlist-folders/",
{},
{
"/v1/me/library/playlist-folders/", {}, {
fetchOptions: {
method: "POST",
body: JSON.stringify({
@ -2058,11 +2027,11 @@ const app = new Vue({
removeFromLibrary(kind, id) {
let self = this
let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
app.mk.api.v3.music(`v1/me/library/${truekind}/${id.toString()}`,{},
{
app.mk.api.v3.music(`v1/me/library/${truekind}/${id.toString()}`, {}, {
fetchOptions: {
method: "DELETE"
}}).then((data) => {
}
}).then((data) => {
self.getLibrarySongsFull(true)
})
},
@ -2212,8 +2181,7 @@ const app = new Vue({
lrcrich = jsonResponse["message"]["body"]["macro_calls"]["track.richsync.get"]["message"]["body"]["richsync"]["richsync_body"];
richsync = JSON.parse(lrcrich);
app.richlyrics = richsync;
} catch (_) {
}
} catch (_) {}
}
if (lrcfile == "") {
@ -2442,7 +2410,8 @@ const app = new Vue({
MusicKit.getInstance().play()
});
} else {
this.mk.setQueue({[truekind]: [id]}).then(function (queue) {
this.mk.setQueue({
[truekind]: [id] }).then(function(queue) {
MusicKit.getInstance().play()
})
}
@ -2487,7 +2456,8 @@ const app = new Vue({
if (childIndex != -1) {
app.mk.changeToMediaAtIndex(childIndex)
} else if (item) {
app.mk.playNext({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
app.mk.playNext({
[item.attributes.playParams.kind ? ? item.type]: item.attributes.playParams.id ? ? item.id }).then(function() {
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ? ? 1)
app.mk.play()
})
@ -2499,7 +2469,8 @@ const app = new Vue({
} else {
app.mk.stop().then(() => {
if (truekind == "playlists" && (id.startsWith("p.") || id.startsWith("pl.u"))) {
app.mk.setQueue({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
app.mk.setQueue({
[item.attributes.playParams.kind ? ? item.type]: item.attributes.playParams.id ? ? item.id }).then(function() {
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ? ? 1).then(function() {
if ((app.showingPlaylist && app.showingPlaylist.id == id)) {
let query = app.showingPlaylist.relationships.tracks.data.map(item => new MusicKit.MediaItem(item));
@ -2522,14 +2493,16 @@ const app = new Vue({
})
} else {
this.mk.setQueue({[truekind]: [id]}).then(function (queue) {
this.mk.setQueue({
[truekind]: [id] }).then(function(queue) {
if (item && ((queue._itemIDs[childIndex] != item.id))) {
childIndex = queue._itemIDs.indexOf(item.id)
}
if (childIndex != -1) {
app.mk.changeToMediaAtIndex(childIndex)
} else if (item) {
app.mk.playNext({[item.attributes.playParams.kind ?? item.type]: item.attributes.playParams.id ?? item.id}).then(function () {
app.mk.playNext({
[item.attributes.playParams.kind ? ? item.type]: item.attributes.playParams.id ? ? item.id }).then(function() {
app.mk.changeToMediaAtIndex(app.mk.queue._itemIDs.indexOf(item.id) ? ? 1)
app.mk.play()
})
@ -2544,8 +2517,7 @@ const app = new Vue({
console.log(err)
try {
app.mk.stop()
} catch (e) {
}
} catch (e) {}
this.playMediaItemById(item.attributes.playParams.id ? ? item.id, item.attributes.playParams.kind ? ? item.type, item.attributes.playParams.isLibrary ? ? false, item.attributes.url)
}
@ -2603,8 +2575,7 @@ const app = new Vue({
return
}
//this.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${this.search.term}`
this.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${this.search.term}`,
{
this.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/search?term=${this.search.term}`, {
types: "activities,albums,apple-curators,artists,curators,editorial-items,music-movies,music-videos,playlists,songs,stations,tv-episodes,uploaded-videos,record-labels",
"relate[editorial-items]": "contents",
"include[editorial-items]": "contents",
@ -2656,18 +2627,20 @@ const app = new Vue({
types[index].id.push(id)
}
}
types2 = types.map(function(item){return {[`ids[${item.type}]`]: [item.id]}})
types2 = types.map(function(item) { return {
[`ids[${item.type}]`]: [item.id] } })
types2 = types2.reduce(function(result, item) {
var key = Object.keys(item)[0]; //first property: a, b, c
result[key] = item[key];
return result;
}, {});
return (await
this.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}`, {...{
return (await this.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}`, {... {
"omit[resource]": "autos",
relate: "library",
fields: "inLibrary"
},...types2})).data.data
},
...types2
})).data.data
},
isInLibrary(playParams) {
let self = this
@ -2759,24 +2732,21 @@ const app = new Vue({
try {
clearInterval(bginterval);
} catch (err) {
}
} catch (err) {}
} else {
this.setLibraryArtBG()
}
} else if (this.mk.nowPlayingItem["id"] == this.currentTrackID) {
try {
clearInterval(bginterval);
} catch (err) {
}
} catch (err) {}
}
} catch (e) {
if (this.mk.nowPlayingItem && this.mk.nowPlayingItem["id"] && document.querySelector('.bg-artwork')) {
this.setLibraryArtBG()
try {
clearInterval(bginterval);
} catch (err) {
}
} catch (err) {}
}
}
}, 200)
@ -2829,8 +2799,7 @@ const app = new Vue({
this.currentArtUrl = (this.mk["nowPlayingItem"]["attributes"]["artwork"]["url"] ? ? '').replace('{w}', 50).replace('{h}', 50);
try {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`);
} catch (e) {
}
} catch (e) {}
} else {
let data = await this.mk.api.v3.music(`/v1/me/library/songs/${this.mk.nowPlayingItem.id}`);
data = data.data.data[0];
@ -2838,14 +2807,12 @@ const app = new Vue({
this.currentArtUrl = (data["attributes"]["artwork"]["url"] ? ? '').replace('{w}', 50).replace('{h}', 50);
try {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`);
} catch (e) {
}
} catch (e) {}
} else {
this.currentArtUrl = '';
try {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${this.currentArtUrl}")`);
} catch (e) {
}
} catch (e) {}
}
}
} catch (e) {
@ -2863,8 +2830,7 @@ const app = new Vue({
} else {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("")`);
}
} catch (e) {
}
} catch (e) {}
},
async setLibraryArtBG() {
if (typeof this.mk.nowPlayingItem === "undefined") return;
@ -2880,8 +2846,7 @@ const app = new Vue({
self.$store.commit("setLCDArtwork", img)
})
}
} catch (e) {
}
} catch (e) {}
},
quickPlay(query) {
@ -2922,17 +2887,14 @@ const app = new Vue({
id = item.id
}
this.mk.api.v3.music(`/v1/me/ratings/${type}/${id}`, {}, {
fetchOptions:
{
fetchOptions: {
method: "PUT",
body: JSON.stringify(
{
body: JSON.stringify({
"type": "rating",
"attributes": {
"value": 1
}
}
)
})
}
})
},
@ -2946,17 +2908,14 @@ const app = new Vue({
id = item.id
}
this.mk.api.v3.music(`/v1/me/ratings/${type}/${id}`, {}, {
fetchOptions:
{
fetchOptions: {
method: "PUT",
body: JSON.stringify(
{
body: JSON.stringify({
"type": "rating",
"attributes": {
"value": -1
}
}
)
})
}
})
},
@ -2970,8 +2929,7 @@ const app = new Vue({
id = item.id
}
this.mk.api.v3.music(`/v1/me/ratings/${type}/${id}`, {}, {
fetchOptions:
{
fetchOptions: {
method: "DELETE",
}
})
@ -3062,8 +3020,7 @@ const app = new Vue({
items: []
},
normal: {
headerItems: [
{
headerItems: [{
"icon": "./assets/feather/heart.svg",
"id": "love",
"name": "Love",
@ -3104,8 +3061,7 @@ const app = new Vue({
}
},
],
items: [
{
items: [{
"icon": "./assets/feather/list.svg",
"name": "Add to Playlist...",
"hidden": true,
@ -3241,9 +3197,9 @@ const app = new Vue({
return n
}
const s = e.getTimezoneOffset()
, n = Math.floor(Math.abs(s) / 60)
, d = Math.round(Math.abs(s) % 60);
const s = e.getTimezoneOffset(),
n = Math.floor(Math.abs(s) / 60),
d = Math.round(Math.abs(s) % 60);
let h = "+";
return 0 !== s && (h = s > 0 ? "-" : "+"),
`${h}${leadingZeros(n, 2)}:${leadingZeros(d, 2)}`
@ -3495,8 +3451,7 @@ var checkIfScrollIsStatic = setInterval(() => {
// do something
}
position = document.getElementsByClassName('lyric-body')[0].scrollTop
} catch (e) {
}
} catch (e) {}
}, 50);
@ -3514,5 +3469,3 @@ webGPU().then()
let screenWidth = screen.width;
let screenHeight = screen.height;