Skip to content

Commit b958d25

Browse files
committed
changed New Releases to My Liked Songs due to the first endpoint not existing anymore, updated wrapper calls to reflect latest Spotify API changes
1 parent b4927bc commit b958d25

5 files changed

Lines changed: 44 additions & 46 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ You are able to configure the behavior of some of them via their settings.
123123
- Push: Play
124124
- Touch: Play
125125
- Long Touch: Refresh
126-
- **New Releases**\
127-
Navigate and play through your personalized new releases.
126+
- **My Liked Songs**\
127+
Navigate and play through your liked songs.
128128

129129
- Rotate: Navigate
130130
- Push: Play

com.ntanis.essentials-for-spotify.sdPlugin/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@
502502
}
503503
},
504504
{
505-
"Name": "New Releases",
506-
"UUID": "com.ntanis.essentials-for-spotify.new-releases-dial",
505+
"Name": "My Liked Songs",
506+
"UUID": "com.ntanis.essentials-for-spotify.my-liked-songs-dial",
507507
"Icon": "images/actions/items",
508-
"Tooltip": "Navigate and play through your personalized new releases.",
508+
"Tooltip": "Navigate and play through your liked songs.",
509509
"Controllers": [
510510
"Encoder"
511511
],
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import ItemsDial from './items-dial.js'
66

77
import wrapper from './../library/wrapper.js'
88

9-
@action({ UUID: 'com.ntanis.essentials-for-spotify.new-releases-dial' })
10-
export default class NewReleasesDial extends ItemsDial {
9+
@action({ UUID: 'com.ntanis.essentials-for-spotify.my-liked-songs-dial' })
10+
export default class MyLikedSongs extends ItemsDial {
1111
constructor() {
1212
super('layouts/items-layout.json', 'images/icons/items.png')
1313
}
1414

1515
async fetchItems(page: number) {
16-
return await wrapper.getNewReleases(page)
16+
return await wrapper.getUserLikedSongs(page)
1717
}
1818
}

src/library/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import UserInformationButton from './../actions/user-information-button'
2424
import VolumeControlDial from './../actions/volume-control-dial'
2525
import PlaybackControlDial from './../actions/playback-control-dial'
2626
import MyPlaylistsDial from './../actions/my-playlists-dial'
27-
import NewReleasesDial from '../actions/new-releases-dial'
27+
import MyLikedSongsDial from '../actions/my-liked-songs-dial'
2828
import AddToPlaylistButton from './../actions/add-to-playlist-button'
2929

3030
export default {
@@ -54,7 +54,7 @@ export default {
5454
StreamDeck.actions.registerAction(new VolumeControlDial())
5555
StreamDeck.actions.registerAction(new PlaybackControlDial())
5656
StreamDeck.actions.registerAction(new MyPlaylistsDial())
57-
StreamDeck.actions.registerAction(new NewReleasesDial())
57+
StreamDeck.actions.registerAction(new MyLikedSongsDial())
5858
StreamDeck.actions.registerAction(new AddToPlaylistButton())
5959
}
6060
}

src/library/wrapper.js

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Wrapper extends EventEmitter {
188188

189189
this.#setSong(response?.item ? {
190190
item: response.item,
191-
liked: response.item.id ? (await connector.callSpotifyApi(`me/tracks/contains?ids=${response.item.id}`))[0] : false,
191+
liked: response.item.id ? (await connector.callSpotifyApi(`me/library/contains?uris=${encodeURIComponent(response.item.uri)}`))[0] : false,
192192
progress: response.progress_ms
193193
} : null)
194194

@@ -799,7 +799,7 @@ class Wrapper extends EventEmitter {
799799

800800
async likeSong(song) {
801801
return this.#wrapCall(async () => {
802-
await connector.callSpotifyApi(`me/tracks?ids=${song.item.id}`, {
802+
await connector.callSpotifyApi(`me/library?uris=${encodeURIComponent(song.item.uri)}`, {
803803
method: 'PUT'
804804
})
805805

@@ -840,7 +840,7 @@ class Wrapper extends EventEmitter {
840840

841841
async unlikeSong(song) {
842842
return this.#wrapCall(async () => {
843-
await connector.callSpotifyApi(`me/tracks?ids=${song.item.id}`, {
843+
await connector.callSpotifyApi(`me/library?uris=${encodeURIComponent(song.item.uri)}`, {
844844
method: 'DELETE'
845845
})
846846

@@ -865,13 +865,11 @@ class Wrapper extends EventEmitter {
865865

866866
async addSongToPlaylist(playlistId, trackUri) {
867867
return this.#wrapCall(async () => {
868-
if (playlistId === 'tracks') {
869-
const trackId = trackUri.split(':')[2]
870-
871-
await connector.callSpotifyApi(`me/tracks?ids=${trackId}`, {
868+
if (playlistId === 'tracks')
869+
await connector.callSpotifyApi(`me/library?uris=${encodeURIComponent(trackUri)}`, {
872870
method: 'PUT'
873871
})
874-
} else {
872+
else {
875873
await connector.callSpotifyApi(`playlists/${playlistId}/tracks`, {
876874
method: 'POST',
877875

@@ -916,7 +914,7 @@ class Wrapper extends EventEmitter {
916914

917915
async getPlaylists(page = 1) {
918916
return this.#wrapCall(async () => {
919-
const tracks = await connector.callSpotifyApi(`me/tracks?limit=1&offset=0`)
917+
const tracks = await connector.callSpotifyApi('me/tracks?limit=1&offset=0')
920918
const playlists = await connector.callSpotifyApi(`me/playlists?limit=${constants.WRAPPER_ITEMS_PER_PAGE}&offset=${(page - 1) * constants.WRAPPER_ITEMS_PER_PAGE}`)
921919

922920
return {
@@ -939,14 +937,14 @@ class Wrapper extends EventEmitter {
939937
images: playlist.images
940938
}))),
941939

942-
total: playlists.total
940+
total: playlists.total + (tracks.total > 0 ? 1 : 0)
943941
}
944942
}, true)
945943
}
946944

947945
async getUserPlaylists(page = 1) {
948946
return this.#wrapCall(async () => {
949-
const tracks = await connector.callSpotifyApi(`me/tracks?limit=1&offset=0`)
947+
const tracks = await connector.callSpotifyApi('me/tracks?limit=1&offset=0')
950948
const playlists = await connector.callSpotifyApi(`me/playlists?limit=${constants.WRAPPER_ITEMS_PER_PAGE}&offset=${(page - 1) * constants.WRAPPER_ITEMS_PER_PAGE}`)
951949

952950
return {
@@ -971,37 +969,22 @@ class Wrapper extends EventEmitter {
971969
collaborative: playlist.collaborative
972970
}))),
973971

974-
total: playlists.total
975-
}
976-
}, true)
977-
}
978-
979-
async getCurrentTrack() {
980-
return this.#wrapCall(async () => {
981-
const response = await connector.callSpotifyApi('me/player/currently-playing', undefined, [constants.API_EMPTY_RESPONSE])
982-
983-
if (response === constants.API_EMPTY_RESPONSE || !response?.item)
984-
return null
985-
986-
return {
987-
id: response.item.id,
988-
uri: response.item.uri,
989-
name: response.item.name
972+
total: playlists.total + (tracks.total > 0 ? 1 : 0)
990973
}
991974
}, true)
992975
}
993976

994-
async getNewReleases(page = 1) {
977+
async getUserLikedSongs(page = 1) {
995978
return this.#wrapCall(async () => {
996-
const response = await connector.callSpotifyApi(`browse/new-releases?limit=${constants.WRAPPER_ITEMS_PER_PAGE}&offset=${(page - 1) * constants.WRAPPER_ITEMS_PER_PAGE}`)
979+
const tracks = await connector.callSpotifyApi(`me/tracks?limit=${constants.WRAPPER_ITEMS_PER_PAGE}&offset=${(page - 1) * constants.WRAPPER_ITEMS_PER_PAGE}`)
997980

998981
return {
999982
status: constants.WRAPPER_RESPONSE_SUCCESS,
1000983

1001-
items: response.albums.items.map(item => {
984+
items: tracks.items.map(item => {
1002985
let extra = ''
1003986

1004-
switch (item.album_type) {
987+
switch (item.track.album.album_type) {
1005988
case 'album':
1006989
extra = '💿'
1007990
break
@@ -1020,15 +1003,30 @@ class Wrapper extends EventEmitter {
10201003
}
10211004

10221005
return {
1023-
id: item.id,
1024-
type: 'album',
1006+
id: item.track.id,
1007+
type: 'track',
10251008
extra,
1026-
name: `${item.name} - ${item.artists.map(artist => artist.name).join(', ')}`,
1027-
images: item.images
1009+
name: `${item.track.name} - ${item.track.artists.map(artist => artist.name).join(', ')}`,
1010+
images: item.track.album.images
10281011
}
10291012
}),
10301013

1031-
total: response.albums.total
1014+
total: tracks.total
1015+
}
1016+
}, true)
1017+
}
1018+
1019+
async getCurrentTrack() {
1020+
return this.#wrapCall(async () => {
1021+
const response = await connector.callSpotifyApi('me/player/currently-playing', undefined, [constants.API_EMPTY_RESPONSE])
1022+
1023+
if (response === constants.API_EMPTY_RESPONSE || !response?.item)
1024+
return null
1025+
1026+
return {
1027+
id: response.item.id,
1028+
uri: response.item.uri,
1029+
name: response.item.name
10321030
}
10331031
}, true)
10341032
}

0 commit comments

Comments
 (0)