adjusted routeview for routes

This commit is contained in:
booploops 2021-12-21 00:47:59 -08:00
parent f8491848fd
commit 05f97ad4a1

View file

@ -25,15 +25,15 @@ var CiderContextMenu = {
menu.style.zIndex = "99909"; menu.style.zIndex = "99909";
menu.addEventListener("animationend", function () { menu.addEventListener("animationend", function () {
menu.classList.remove("context-menu-open"); menu.classList.remove("context-menu-open");
}, {once: true}); }, { once: true });
function close () { function close() {
menuBackground.style.pointerEvents = "none"; menuBackground.style.pointerEvents = "none";
menu.classList.add("context-menu-close"); menu.classList.add("context-menu-close");
menu.addEventListener("animationend", function () { menu.addEventListener("animationend", function () {
menuBackground.remove(); menuBackground.remove();
menu.remove(); menu.remove();
}, {once: true}); }, { once: true });
} }
// when menubackground is clicked, remove it // when menubackground is clicked, remove it
@ -164,7 +164,7 @@ const app = new Vue({
sorting: "name", sorting: "name",
sortOrder: "asc", sortOrder: "asc",
listing: [], listing: [],
meta: {total: 0, progress: 0}, meta: { total: 0, progress: 0 },
search: "", search: "",
displayListing: [], displayListing: [],
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library
@ -180,7 +180,7 @@ const app = new Vue({
sorting: ["dateAdded", "name"], // [0] = recentlyadded page, [1] = albums page sorting: ["dateAdded", "name"], // [0] = recentlyadded page, [1] = albums page
sortOrder: ["desc", "asc"], // [0] = recentlyadded page, [1] = albums page sortOrder: ["desc", "asc"], // [0] = recentlyadded page, [1] = albums page
listing: [], listing: [],
meta: {total: 0, progress: 0}, meta: { total: 0, progress: 0 },
search: "", search: "",
displayListing: [], displayListing: [],
downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library downloadState: 0 // 0 = not started, 1 = in progress, 2 = complete, 3 = empty library
@ -215,7 +215,7 @@ const app = new Vue({
"attributes": { "attributes": {
"name": "Cider User", "name": "Cider User",
"handle": "CiderUser", "handle": "CiderUser",
"artwork": {"url": "http://localhost:9000/assets/logocut.png"} "artwork": { "url": "http://localhost:9000/assets/logocut.png" }
} }
}, },
menuOpened: false, menuOpened: false,
@ -271,7 +271,7 @@ const app = new Vue({
"attributes": { "attributes": {
"name": "Cider User", "name": "Cider User",
"handle": "CiderUser", "handle": "CiderUser",
"artwork": {"url": "http://localhost:9000/assets/logocut.png"} "artwork": { "url": "http://localhost:9000/assets/logocut.png" }
} }
} }
} }
@ -292,11 +292,11 @@ const app = new Vue({
} }
MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player") MusicKit.getInstance().videoContainerElement = document.getElementById("apple-music-video-player")
this.mk.addEventListener(MusicKit.Events.playbackTimeDidChange, (a) => { this.mk.addEventListener(MusicKit.Events.playbackTimeDidChange, (a) => {
if (self.mk.nowPlayingItem && self.mk.nowPlayingItem.playParams.kind.includes('ideo')){ if (self.mk.nowPlayingItem && self.mk.nowPlayingItem.playParams.kind.includes('ideo')) {
self.lyriccurrenttime = (self.mk.currentPlaybackTime) self.lyriccurrenttime = (self.mk.currentPlaybackTime)
} }
this.currentSongInfo = a this.currentSongInfo = a
@ -313,7 +313,7 @@ const app = new Vue({
}) })
this.mk.addEventListener(MusicKit.Events.nowPlayingItemDidChange, (a) => { this.mk.addEventListener(MusicKit.Events.nowPlayingItemDidChange, (a) => {
if(self.$refs.queue) { if (self.$refs.queue) {
self.$refs.queue.updateQueue(); self.$refs.queue.updateQueue();
} }
this.currentSongInfo = a this.currentSongInfo = a
@ -360,21 +360,21 @@ const app = new Vue({
self.playlists.listing = res.data self.playlists.listing = res.data
}) })
document.body.removeAttribute("loading") document.body.removeAttribute("loading")
if(window.location.hash != "") { if (window.location.hash != "") {
this.appRoute(window.location.hash) this.appRoute(window.location.hash)
} }
}, },
invokeDrawer(panel) { invokeDrawer(panel) {
if(this.drawer.panel == panel && this.drawer.open) { if (this.drawer.panel == panel && this.drawer.open) {
if(panel == "lyrics") { if (panel == "lyrics") {
this.lyricon = false this.lyricon = false
} }
this.drawer.panel = "" this.drawer.panel = ""
this.drawer.open = false this.drawer.open = false
}else{ } else {
if(panel == "lyrics") { if (panel == "lyrics") {
this.lyricon = true this.lyricon = true
}else{ } else {
this.lyricon = false this.lyricon = false
} }
this.drawer.open = true this.drawer.open = true
@ -388,14 +388,14 @@ const app = new Vue({
}, },
select_hasMediaItem(id) { select_hasMediaItem(id) {
let found = this.selectedMediaItems.find(item => item.guid == id) let found = this.selectedMediaItems.find(item => item.guid == id)
if(found) { if (found) {
return true return true
}else{ } else {
return false return false
} }
}, },
select_selectMediaItem(id, kind, index, guid) { select_selectMediaItem(id, kind, index, guid) {
if(!this.select_hasMediaItem(guid)) { if (!this.select_hasMediaItem(guid)) {
this.selectedMediaItems.push({ this.selectedMediaItems.push({
id: id, id: id,
kind: kind, kind: kind,
@ -412,11 +412,11 @@ const app = new Vue({
app.appRoute("collection-list") app.appRoute("collection-list")
}, },
async showArtistView(artist, title, view) { async showArtistView(artist, title, view) {
let response = await this.mk.api.artistView(artist, view, {}, {view: view, includeResponseMeta: !0}) let response = await this.mk.api.artistView(artist, view, {}, { view: view, includeResponseMeta: !0 })
await this.showCollection(response, title, "artists") await this.showCollection(response, title, "artists")
}, },
async showRecordLabelView(label, title, view) { async showRecordLabelView(label, title, view) {
let response = await this.mk.api.recordLabelView(label, view, {}, {view: view, includeResponseMeta: !0}) let response = await this.mk.api.recordLabelView(label, view, {}, { view: view, includeResponseMeta: !0 })
await this.showCollection(response, title, "record-labels") await this.showCollection(response, title, "record-labels")
}, },
async showSearchView(term, group, title) { async showSearchView(term, group, title) {
@ -445,7 +445,7 @@ const app = new Vue({
omit: { omit: {
resource: ["autos"] resource: ["autos"]
} }
}, {groups: group, includeResponseMeta: !0}) }, { groups: group, includeResponseMeta: !0 })
console.log(response) console.log(response)
let responseFormat = { let responseFormat = {
data: response[group].data.data, data: response[group].data.data,
@ -485,7 +485,7 @@ const app = new Vue({
"fields[albums]": "artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount", "fields[albums]": "artistName,artistUrl,artwork,contentRating,editorialArtwork,editorialVideo,name,playParams,releaseDate,url,trackCount",
"limit[artists:top-songs]": 20, "limit[artists:top-songs]": 20,
"art[url]": "f" "art[url]": "f"
}, {includeResponseMeta: !0}) }, { includeResponseMeta: !0 })
console.log(artistData) console.log(artistData)
this.artistPage.data = artistData.data[0] this.artistPage.data = artistData.data[0]
this.page = "artist-page" this.page = "artist-page"
@ -549,7 +549,7 @@ const app = new Vue({
return hash; return hash;
}, },
appRoute(route) { appRoute(route) {
if(route == "" || route == "#" || route == "/") { if (route == "" || route == "#" || route == "/") {
return; return;
} }
route = route.replace(/#/g, "") route = route.replace(/#/g, "")
@ -567,7 +567,7 @@ const app = new Vue({
kind: page, kind: page,
id: id, id: id,
attributes: { attributes: {
playParams: {kind: page, id: id} playParams: { kind: page, id: id }
} }
}) })
}, },
@ -580,10 +580,12 @@ const app = new Vue({
; ;
let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false; let isLibrary = item.attributes.playParams ? (item.attributes.playParams.isLibrary ?? false) : false;
console.log(kind, id, isLibrary) console.log(kind, id, isLibrary)
if (true) { if (true) {
app.showingPlaylist = []; if (kind == "playlist") {
if (kind.toString().includes("apple-curator")){ app.showingPlaylist = [];
}
if (kind.toString().includes("apple-curator")) {
kind = "appleCurator" kind = "appleCurator"
app.getTypeFromID("appleCurator", (id), false, { app.getTypeFromID("appleCurator", (id), false, {
platform: "web", platform: "web",
@ -591,9 +593,13 @@ const app = new Vue({
extend: "editorialArtwork", extend: "editorialArtwork",
"art[url]": "f" "art[url]": "f"
}); });
window.location.hash = `${kind}/${id}`
document.querySelector("#app-content").scrollTop = 0
} }
else if (kind.toString().includes("artist")) { else if (kind.toString().includes("artist")) {
app.getArtistInfo(id, isLibrary) app.getArtistInfo(id, isLibrary)
window.location.hash = `${kind}/${id}`
document.querySelector("#app-content").scrollTop = 0
} else if (kind.toString().includes("record-label") || kind.toString().includes("curator")) { } else if (kind.toString().includes("record-label") || kind.toString().includes("curator")) {
if (kind.toString().includes("record-label")) { if (kind.toString().includes("record-label")) {
kind = "recordLabel" kind = "recordLabel"
@ -606,18 +612,22 @@ const app = new Vue({
include: 'grouping,playlists', include: 'grouping,playlists',
views: 'top-releases,latest-releases,top-artists' views: 'top-releases,latest-releases,top-artists'
}); });
window.location.hash = `${kind}/${id}`
document.querySelector("#app-content").scrollTop = 0
} else if (!kind.toString().includes("radioStation") && !kind.toString().includes("song") && !kind.toString().includes("musicVideo") && !kind.toString().includes("uploadedVideo")) { } else if (!kind.toString().includes("radioStation") && !kind.toString().includes("song") && !kind.toString().includes("musicVideo") && !kind.toString().includes("uploadedVideo")) {
app.page = (kind) + "_" + (id); app.page = (kind) + "_" + (id);
app.getTypeFromID((kind), (id), (isLibrary), {extend: "editorialVideo"}); app.getTypeFromID((kind), (id), (isLibrary), { extend: "editorialVideo" });
window.location.hash = `${kind}/${id}`
document.querySelector("#app-content").scrollTop = 0
} else { } else {
app.playMediaItemById((id), (kind), (isLibrary), item.attributes.url ?? '') app.playMediaItemById((id), (kind), (isLibrary), item.attributes.url ?? '')
} }
document.querySelector("#app-content").scrollTop = 0
} }
window.location.hash = `${kind}/${id}`
}, },
async getNowPlayingItemDetailed(target) { async getNowPlayingItemDetailed(target) {
let u = await app.mkapi(app.mk.nowPlayingItem.playParams.kind, (app.mk.nowPlayingItem.songId == -1), (app.mk.nowPlayingItem.songId != -1) ? app.mk.nowPlayingItem.songId : app.mk.nowPlayingItem["id"], {"include[songs]": "albums,artists"}); let u = await app.mkapi(app.mk.nowPlayingItem.playParams.kind, (app.mk.nowPlayingItem.songId == -1), (app.mk.nowPlayingItem.songId != -1) ? app.mk.nowPlayingItem.songId : app.mk.nowPlayingItem["id"], { "include[songs]": "albums,artists" });
app.searchAndNavigate(u, target) app.searchAndNavigate(u, target)
}, },
async searchAndNavigate(item, target) { async searchAndNavigate(item, target) {
@ -708,7 +718,7 @@ const app = new Vue({
} }
if (labelId != "") { if (labelId != "") {
app.showingPlaylist = [] app.showingPlaylist = []
await app.getTypeFromID("recordLabel", labelId, false, {views: 'top-releases,latest-releases,top-artists'}); await app.getTypeFromID("recordLabel", labelId, false, { views: 'top-releases,latest-releases,top-artists' });
app.page = "recordLabel_" + labelId; app.page = "recordLabel_" + labelId;
} }
@ -978,11 +988,11 @@ const app = new Vue({
} }
self.library.songs.downloadState = 1 self.library.songs.downloadState = 1
if (downloaded == null) { if (downloaded == null) {
app.mk.api.library.songs("", params, {includeResponseMeta: !0}).then((response) => { app.mk.api.library.songs("", params, { includeResponseMeta: !0 }).then((response) => {
processChunk(response) processChunk(response)
}) })
} else { } else {
downloaded.next("", params, {includeResponseMeta: !0}).then((response) => { downloaded.next("", params, { includeResponseMeta: !0 }).then((response) => {
processChunk(response) processChunk(response)
}) })
} }
@ -1045,11 +1055,11 @@ const app = new Vue({
function downloadChunk() { function downloadChunk() {
self.library.albums.downloadState = 1 self.library.albums.downloadState = 1
if (downloaded == null) { if (downloaded == null) {
app.mk.api.library.albums("", {limit: 100}, {includeResponseMeta: !0}).then((response) => { app.mk.api.library.albums("", { limit: 100 }, { includeResponseMeta: !0 }).then((response) => {
processChunk(response) processChunk(response)
}) })
} else { } else {
downloaded.next("", {limit: 100}, {includeResponseMeta: !0}).then((response) => { downloaded.next("", { limit: 100 }, { includeResponseMeta: !0 }).then((response) => {
processChunk(response) processChunk(response)
}) })
} }
@ -1076,7 +1086,7 @@ const app = new Vue({
} }
if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") { if (downloaded.meta.total > library.length || typeof downloaded.meta.next != "undefined") {
console.log(`downloading next chunk - ${library.length console.log(`downloading next chunk - ${library.length
} albums so far`) } albums so far`)
downloadChunk() downloadChunk()
} else { } else {
self.library.albums.listing = library self.library.albums.listing = library
@ -1093,7 +1103,7 @@ const app = new Vue({
getTotalTime() { getTotalTime() {
try { try {
if (app.showingPlaylist.relationships.tracks.data.length > 0) { if (app.showingPlaylist.relationships.tracks.data.length > 0) {
time = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, {attributes: {durationInMillis}}) => a + durationInMillis, 0) / 60000); time = Math.round([].concat(...app.showingPlaylist.relationships.tracks.data).reduce((a, { attributes: { durationInMillis } }) => a + durationInMillis, 0) / 60000);
return app.showingPlaylist.relationships.tracks.data.length + " tracks, " + time + " mins."; return app.showingPlaylist.relationships.tracks.data.length + " tracks, " + time + " mins.";
} else return "" } else return ""
} catch (err) { } catch (err) {
@ -1101,12 +1111,12 @@ const app = new Vue({
} }
}, },
async getLibrarySongs() { async getLibrarySongs() {
var response = await this.mkapi("songs", true, "", {limit: 100}, {includeResponseMeta: !0}) var response = await this.mkapi("songs", true, "", { limit: 100 }, { includeResponseMeta: !0 })
this.library.songs.listing = response.data this.library.songs.listing = response.data
this.library.songs.meta = response.meta this.library.songs.meta = response.meta
}, },
async getLibraryAlbums() { async getLibraryAlbums() {
var response = await this.mkapi("albums", true, "", {limit: 100}, {includeResponseMeta: !0}) var response = await this.mkapi("albums", true, "", { limit: 100 }, { includeResponseMeta: !0 })
this.library.albums.listing = response.data this.library.albums.listing = response.data
this.library.albums.meta = response.meta this.library.albums.meta = response.meta
}, },
@ -1301,18 +1311,18 @@ const app = new Vue({
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 {
lrcrich = jsonResponse["message"]["body"]["macro_calls"]["track.richsync.get"]["message"]["body"]["richsync"]["richsync_body"]; 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 == "") {
app.loadAMLyrics() app.loadAMLyrics()
} else { } else {
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
@ -1337,17 +1347,21 @@ const app = new Vue({
}); });
app.lyrics = preLrc.reverse(); app.lyrics = preLrc.reverse();
} else { } else {
preLrc = richsync.map(function (item){ return { startTime: item.ts, preLrc = richsync.map(function (item) {
endTime: item.te, return {
line: item.x, startTime: item.ts,
translation: ''}}) endTime: item.te,
line: item.x,
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 != '') {
@ -1447,15 +1461,15 @@ const app = new Vue({
line: "lrcInstrumental" line: "lrcInstrumental"
}); });
} }
preLrc.push({startTime: start, endTime: end, line: element.textContent}); preLrc.push({ startTime: start, endTime: end, line: element.textContent });
endTimes.push(end); endTimes.push(end);
} }
// first line dot // first line dot
if (preLrc.length > 0) if (preLrc.length > 0)
preLrc.unshift({startTime: 0, endTime: preLrc[0].startTime, line: "lrcInstrumental"}); preLrc.unshift({ startTime: 0, endTime: preLrc[0].startTime, line: "lrcInstrumental" });
} else { } else {
for (element of lyricsLines) { for (element of lyricsLines) {
preLrc.push({startTime: 9999999, endTime: 9999999, line: element.textContent}); preLrc.push({ startTime: 9999999, endTime: 9999999, line: element.textContent });
} }
} }
this.lyrics = preLrc; this.lyrics = preLrc;
@ -1522,17 +1536,17 @@ const app = new Vue({
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
console.log(id, truekind, isLibrary) console.log(id, truekind, isLibrary)
try { try {
if (truekind.includes("artist")){ if (truekind.includes("artist")) {
app.mk.setStationQueue({ artist: 'a-' + id }).then(() => { app.mk.setStationQueue({ artist: 'a-' + id }).then(() => {
app.mk.play() app.mk.play()
}) })
} }
else if (truekind == "radioStations") { else if (truekind == "radioStations") {
this.mk.setStationQueue({url: raurl}).then(function (queue) { this.mk.setStationQueue({ url: raurl }).then(function (queue) {
MusicKit.getInstance().play() MusicKit.getInstance().play()
}); });
} else { } else {
this.mk.setQueue({[truekind]: [id]}).then(function (queue) { this.mk.setQueue({ [truekind]: [id] }).then(function (queue) {
MusicKit.getInstance().play() MusicKit.getInstance().play()
}) })
} }
@ -1541,37 +1555,37 @@ const app = new Vue({
this.playMediaItemById(id, kind, isLibrary, raurl) this.playMediaItemById(id, kind, isLibrary, raurl)
} }
}, },
queueParentandplayChild(parent,childIndex,item){ queueParentandplayChild(parent, childIndex, item) {
var kind = parent.substring(0,parent.indexOf(":")) var kind = parent.substring(0, parent.indexOf(":"))
var id = parent.substring(parent.indexOf(":")+1 , parent.length) var id = parent.substring(parent.indexOf(":") + 1, parent.length)
var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; var truekind = (!kind.endsWith("s")) ? (kind + "s") : kind;
console.log(truekind,id) console.log(truekind, id)
try { try {
if (app.library.songs.listing.length > childIndex && parent == "librarysongs"){ if (app.library.songs.listing.length > childIndex && parent == "librarysongs") {
console.log(item) console.log(item)
if (item && ((app.library.songs.listing[childIndex].id != item.id))){ if (item && ((app.library.songs.listing[childIndex].id != item.id))) {
childIndex = app.library.songs.listing.indexOf(item) childIndex = app.library.songs.listing.indexOf(item)
} }
let query = app.library.songs.listing.map(item => new MusicKit.MediaItem(item)); let query = app.library.songs.listing.map(item => new MusicKit.MediaItem(item));
try{app.mk.stop()}catch(e){} try { app.mk.stop() } catch (e) { }
this.mk.clearQueue().then(function (_) { this.mk.clearQueue().then(function (_) {
app.mk.queue.append(query) app.mk.queue.append(query)
app.mk.changeToMediaAtIndex(childIndex) app.mk.changeToMediaAtIndex(childIndex)
}) })
} else { } else {
try{app.mk.stop()}catch(e){} try { app.mk.stop() } catch (e) { }
this.mk.setQueue({[truekind]: [id]}).then(function (queue) { this.mk.setQueue({ [truekind]: [id] }).then(function (queue) {
app.mk.changeToMediaAtIndex(childIndex) app.mk.changeToMediaAtIndex(childIndex)
}) })
} }
} catch (err) { } catch (err) {
console.log(err) console.log(err)
try{app.mk.stop()}catch(e){} try { app.mk.stop() } catch (e) { }
this.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url) this.playMediaItemById(item.attributes.playParams.id ?? item.id, item.attributes.playParams.kind ?? item.type, item.attributes.playParams.isLibrary ?? false, item.attributes.url)
} }
}, },
friendlyTypes(type) { friendlyTypes(type) {
// use switch statement to return friendly name for media types "songs,artists,albums,playlists,music-videos,stations,apple-curators,curators" // use switch statement to return friendly name for media types "songs,artists,albums,playlists,music-videos,stations,apple-curators,curators"
@ -1643,8 +1657,8 @@ const app = new Vue({
"platform": "web", "platform": "web",
limit: 25 limit: 25
}).then(function (results) { }).then(function (results) {
self.search.results = results self.search.results = results
}) })
}, },
isInLibrary(playParams) { isInLibrary(playParams) {
let self = this let self = this
@ -1685,7 +1699,7 @@ const app = new Vue({
return newurl return newurl
}, },
getNowPlayingArtworkBG(size = 600) { getNowPlayingArtworkBG(size = 600) {
if(typeof this.mk.nowPlayingItem === "undefined") return; if (typeof this.mk.nowPlayingItem === "undefined") return;
let bginterval = setInterval(() => { let bginterval = setInterval(() => {
if (!this.mkReady()) { if (!this.mkReady()) {
return "" return ""
@ -1704,19 +1718,19 @@ const app = new Vue({
} else { } else {
this.setLibraryArtBG() this.setLibraryArtBG()
} }
} else if (this.mk.nowPlayingItem["id"] == this.currentTrackID){ } else if (this.mk.nowPlayingItem["id"] == this.currentTrackID) {
try { clearInterval(bginterval); } catch (err) { } try { clearInterval(bginterval); } catch (err) { }
} }
} catch (e) { } catch (e) {
if (this.mk.nowPlayingItem && this.mk.nowPlayingItem["id"] && document.querySelector('.bg-artwork')){ if (this.mk.nowPlayingItem && this.mk.nowPlayingItem["id"] && document.querySelector('.bg-artwork')) {
this.setLibraryArtBG() this.setLibraryArtBG()
try { clearInterval(bginterval); } catch (err) { } try { clearInterval(bginterval); } catch (err) { }
} }
} }
}, 200) }, 200)
}, },
getNowPlayingArtwork(size = 600) { getNowPlayingArtwork(size = 600) {
if(typeof this.mk.nowPlayingItem === "undefined") return; if (typeof this.mk.nowPlayingItem === "undefined") return;
let interval = setInterval(() => { let interval = setInterval(() => {
try { try {
@ -1728,19 +1742,19 @@ const app = new Vue({
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', ''); document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', '');
if (this.mk["nowPlayingItem"]["attributes"]["artwork"]["url"]) { if (this.mk["nowPlayingItem"]["attributes"]["artwork"]["url"]) {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${decodeURI((this.mk["nowPlayingItem"]["attributes"]["artwork"]["url"])).replace('{w}', size).replace('{h}', size)}")`); document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', `url("${decodeURI((this.mk["nowPlayingItem"]["attributes"]["artwork"]["url"])).replace('{w}', size).replace('{h}', size)}")`);
try { clearInterval(interval); } catch (err) {} try { clearInterval(interval); } catch (err) { }
} else { } else {
this.setLibraryArt() this.setLibraryArt()
} }
} else if (this.mk.nowPlayingItem["id"] == this.currentTrackID){ } else if (this.mk.nowPlayingItem["id"] == this.currentTrackID) {
try { clearInterval(interval); } catch (err) { } try { clearInterval(interval); } catch (err) { }
} }
} catch (e) { } catch (e) {
if (this.mk.nowPlayingItem && this.mk.nowPlayingItem["id"] && document.querySelector('.app-playback-controls .artwork')){ if (this.mk.nowPlayingItem && this.mk.nowPlayingItem["id"] && document.querySelector('.app-playback-controls .artwork')) {
this.setLibraryArt() this.setLibraryArt()
try { clearInterval(interval); } catch (err) { } try { clearInterval(interval); } catch (err) { }
} }
} }
}, 200) }, 200)
@ -1748,11 +1762,11 @@ const app = new Vue({
}, },
async setLibraryArt() { async setLibraryArt() {
if(typeof this.mk.nowPlayingItem === "undefined") return; if (typeof this.mk.nowPlayingItem === "undefined") return;
const data = await this.mk.api.library.song(this.mk.nowPlayingItem["id"]) const data = await this.mk.api.library.song(this.mk.nowPlayingItem["id"])
try { try {
const data = await this.mk.api.library.song(this.mk.nowPlayingItem.id) const data = await this.mk.api.library.song(this.mk.nowPlayingItem.id)
if (data != null && data !== "") { if (data != null && data !== "") {
document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', 'url("' + (data["attributes"]["artwork"]["url"]).toString() + '")'); document.querySelector('.app-playback-controls .artwork').style.setProperty('--artwork', 'url("' + (data["attributes"]["artwork"]["url"]).toString() + '")');
} else { } else {
@ -1762,11 +1776,11 @@ const app = new Vue({
} }
}, },
async setLibraryArtBG() { async setLibraryArtBG() {
if(typeof this.mk.nowPlayingItem === "undefined") return; if (typeof this.mk.nowPlayingItem === "undefined") return;
const data = await this.mk.api.library.song(this.mk.nowPlayingItem["id"]) const data = await this.mk.api.library.song(this.mk.nowPlayingItem["id"])
try { try {
const data = await this.mk.api.library.song(this.mk.nowPlayingItem.id) const data = await this.mk.api.library.song(this.mk.nowPlayingItem.id)
if (data != null && data !== "") { if (data != null && data !== "") {
document.querySelector('.bg-artwork').src = (data["attributes"]["artwork"]["url"]).toString(); document.querySelector('.bg-artwork').src = (data["attributes"]["artwork"]["url"]).toString();
} }
@ -1776,8 +1790,8 @@ const app = new Vue({
}, },
quickPlay(query) { quickPlay(query) {
let self = this let self = this
MusicKit.getInstance().api.search(query, {limit: 2, types: 'songs'}).then(function (data) { MusicKit.getInstance().api.search(query, { limit: 2, types: 'songs' }).then(function (data) {
MusicKit.getInstance().setQueue({song: data["songs"]['data'][0]["id"]}).then(function (queue) { MusicKit.getInstance().setQueue({ song: data["songs"]['data'][0]["id"] }).then(function (queue) {
MusicKit.getInstance().play() MusicKit.getInstance().play()
setTimeout(() => { setTimeout(() => {
self.$forceUpdate() self.$forceUpdate()
@ -1840,8 +1854,8 @@ document.addEventListener('keydown', function (e) {
}); });
// Hang Timer // Hang Timer
app.hangtimer = setTimeout(()=>{ app.hangtimer = setTimeout(() => {
if(confirm("Cider is not responding. Reload the app?")) { if (confirm("Cider is not responding. Reload the app?")) {
window.location.reload() window.location.reload()
} }
}, 10000) }, 10000)
@ -1884,7 +1898,7 @@ document.addEventListener('musickitloaded', function () {
// } // }
function uuidv4() { function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
); );
} }
@ -1954,7 +1968,7 @@ var checkIfScrollIsStatic = setInterval(() => {
// WebGPU Console Notification // WebGPU Console Notification
async function webGPU() { async function webGPU() {
const currentGPU = await navigator.gpu.requestAdapter() const currentGPU = await navigator.gpu.requestAdapter()
console.log("WebGPU enabled on", currentGPU.name,"with feature ID", currentGPU.features.size) console.log("WebGPU enabled on", currentGPU.name, "with feature ID", currentGPU.features.size)
} }
webGPU().then() webGPU().then()