From a91c8539c31b33b164ac09c28ff71c907826cf7d Mon Sep 17 00:00:00 2001 From: vapormusic Date: Sat, 22 Jan 2022 21:10:52 +0700 Subject: [PATCH 1/4] playlist / library search in remote --- src/main/base/wsapi.ts | 4 +- src/renderer/js/WSAPI_Interop.js | 14 +- src/web-remote/index.html | 997 ++++++++++++++++--------------- src/web-remote/index.js | 28 +- 4 files changed, 564 insertions(+), 479 deletions(-) diff --git a/src/main/base/wsapi.ts b/src/main/base/wsapi.ts index 8b114428..26d8c268 100644 --- a/src/main/base/wsapi.ts +++ b/src/main/base/wsapi.ts @@ -186,7 +186,7 @@ export class wsapi { response.message = "Previous"; break; case "musickit-api": - this._win.webContents.executeJavaScript(`wsapi.musickitApi(\`${data.method}\`, \`${data.id}\`, ${JSON.stringify(data.params)})`); + this._win.webContents.executeJavaScript(`wsapi.musickitApi(\`${data.method}\`, \`${data.id}\`, ${JSON.stringify(data.params)} , ${data.library})`); break; case "musickit-library-api": break; @@ -218,7 +218,7 @@ export class wsapi { this._win.hide() break; case "play-mediaitem": - this._win.webContents.executeJavaScript(`wsapi.playTrackById(${data.id}, \`${data.kind}\`)`); + this._win.webContents.executeJavaScript(`wsapi.playTrackById("${data.id}", \`${data.kind}\`)`); response.message = "Playing track"; break; case "get-status": diff --git a/src/renderer/js/WSAPI_Interop.js b/src/renderer/js/WSAPI_Interop.js index 7cc0db9f..5e1589bf 100644 --- a/src/renderer/js/WSAPI_Interop.js +++ b/src/renderer/js/WSAPI_Interop.js @@ -2,12 +2,12 @@ const wsapi = { cache: {playParams: {id: 0}, status: null, remainingTime: 0}, playbackCache: {status: null, time: Date.now()}, search(term, limit) { - MusicKit.getInstance().api.search(term, {limit: limit, types: 'songs,artists,albums'}).then((results)=>{ + MusicKit.getInstance().api.search(term, {limit: limit, types: 'songs,artists,albums,playlists'}).then((results)=>{ ipcRenderer.send('wsapi-returnSearch', JSON.stringify(results)) }) }, searchLibrary(term, limit) { - MusicKit.getInstance().api.library.search(term, {limit: limit, types: 'library-songs,library-artists,library-albums'}).then((results)=>{ + MusicKit.getInstance().api.library.search(term, {limit: limit, types: 'library-songs,library-artists,library-albums,library-playlists'}).then((results)=>{ ipcRenderer.send('wsapi-returnSearchLibrary', JSON.stringify(results)) }) }, @@ -47,10 +47,16 @@ const wsapi = { returnDynamic(data, type) { ipcRenderer.send('wsapi-returnDynamic', JSON.stringify(data), type) }, - musickitApi(method, id, params) { - MusicKit.getInstance().api[method](id, params).then((results)=>{ + musickitApi(method, id, params, library = false) { + if (library) { + MusicKit.getInstance().api.library[method](id, params).then((results)=>{ ipcRenderer.send('wsapi-returnMusicKitApi', JSON.stringify(results), method) }) + } else { + MusicKit.getInstance().api[method](id, params).then((results)=>{ + ipcRenderer.send('wsapi-returnMusicKitApi', JSON.stringify(results), method) + }) + } }, getPlaybackState () { ipcRenderer.send('wsapi-updatePlaybackState', MusicKitInterop.getAttributes()); diff --git a/src/web-remote/index.html b/src/web-remote/index.html index 1b93e454..f9f31652 100644 --- a/src/web-remote/index.html +++ b/src/web-remote/index.html @@ -218,6 +218,9 @@ +
@@ -306,505 +309,565 @@
+ + + - - - - - - - - - - -
-
- -
-
- - - - -
- -
-
- - -
-
- -
-
- - - - -
- -
-
- - -
-
-
-
- -
-
- {{ artistPage.data.attributes["name"] }} -
-
-
-
-
-
-
-

{{ artistPage.data.attributes["name"] }}

-
-
-

Songs

-
- -
-

Albums

-
- -
-

Playlists

-
- -
-
-
- -
-
- - -
-
-
-
-
-
-
-
-
-
- {{ player.currentMediaItem.name }} -
-
- {{ player.currentMediaItem.artistName }} -
-
-
-
-
-
- - -
-
- Empty -
-
- - +
- - - -
- - -
-
- {{ albumPage.data.attributes["name"] }} -
-
-
- -
-
- - - -
-
- -
-
-
- Loading... + + + +
+
+
+
+
+
+
+
+
+
+ {{ player.currentMediaItem.name }} +
+
+ {{ player.currentMediaItem.artistName }} +
+
+
+
+
+
+ + +
+
-
-

Connection Interrupted

- - + + + +
+
+
+
+ +
+
+
+
+
+
+
+
+ {{ albumPage.data.attributes["name"] }} +
+ + +
+
+ +
+
+ +
+
+
+
+
+ +
+
+
+
Tracks
+
+
+
+
+
+
+
+
+ {{ song.attributes.name }} +
+
+ {{ song.attributes.artistName }} +
+
+
+
+ +
+
+ +
+
+ + +
+
+ {{ albumPage.data.attributes["name"] }} +
+
+
+ +
+
+ + + +
+
+ +
+
+
+ Loading... +
+
+

Connection Interrupted

+ + +
+
+
- -
+
+ + \ No newline at end of file diff --git a/src/web-remote/views/components/mediaitem-artwork.ejs b/src/web-remote/views/components/mediaitem-artwork.ejs new file mode 100644 index 00000000..55617ebb --- /dev/null +++ b/src/web-remote/views/components/mediaitem-artwork.ejs @@ -0,0 +1,101 @@ + + + \ No newline at end of file diff --git a/src/web-remote/views/components/mediaitem-square.ejs b/src/web-remote/views/components/mediaitem-square.ejs new file mode 100644 index 00000000..67fae157 --- /dev/null +++ b/src/web-remote/views/components/mediaitem-square.ejs @@ -0,0 +1,469 @@ + + + \ No newline at end of file diff --git a/src/web-remote/views/index.ejs b/src/web-remote/views/index.ejs index ae53de44..d6815ae1 100644 --- a/src/web-remote/views/index.ejs +++ b/src/web-remote/views/index.ejs @@ -589,17 +589,28 @@

Albums

- +
+ +
+ {{ album.attributes["name"] }} +
+
+ {{ album.attributes["artistName"] }} +
+

Playlists

- +
+ +
+ {{ playlist.attributes["name"] }} +
+
@@ -896,5 +907,9 @@ + + +<%- include('components/mediaitem-artwork') +%> \ No newline at end of file