Skip to content

Commit

Permalink
Add is_playable to base tracks data #108
Browse files Browse the repository at this point in the history
Uses market from user token
  • Loading branch information
watsonbox committed Aug 22, 2024
1 parent cf55b26 commit 9b0f396
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Track data is exported in [UTF-8](https://en.wikipedia.org/wiki/UTF-8) encoded [
- Explicit?
- Popularity
- ISRC ([International Standard Recording Code](https://isrc.ifpi.org/en/))
- Is Playable - whether the track is playable in the [user's market](https://developer.spotify.com/documentation/web-api/concepts/track-relinking)
- Added By
- Added At

Expand Down
30 changes: 15 additions & 15 deletions src/components/PlaylistTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ afterEach(() => {
server.resetHandlers()
})

const baseTrackHeaders = '"Track URI","Track Name","Artist URI(s)","Artist Name(s)","Album URI","Album Name","Album Artist URI(s)","Album Artist Name(s)","Album Release Date","Album Image URL","Disc Number","Track Number","Track Duration (ms)","Track Preview URL","Explicit","Popularity","ISRC","Added By","Added At"'
const baseTrackDataCrying = '"spotify:track:1GrLfs4TEvAZ86HVzXHchS","Crying","spotify:artist:4TXdHyuAOl3rAOFmZ6MeKz","Six by Seven","spotify:album:4iwv7b8gDPKztLkKCbWyhi","Best of Six By Seven","spotify:artist:4TXdHyuAOl3rAOFmZ6MeKz","Six by Seven","2017-02-17","https://i.scdn.co/image/ab67616d0000b273f485821b346237acbbca07ea","1","3","198093","https://p.scdn.co/mp3-preview/daf08df57a49c215c8c53dc5fe88dec5461f15c9?cid=9950ac751e34487dbbe027c4fd7f8e99","false","2","UK4UP1300002","","2020-07-19T09:24:39Z"'
const baseTrackHeaders = '"Track URI","Track Name","Artist URI(s)","Artist Name(s)","Album URI","Album Name","Album Artist URI(s)","Album Artist Name(s)","Album Release Date","Album Image URL","Disc Number","Track Number","Track Duration (ms)","Track Preview URL","Explicit","Popularity","ISRC","Is Playable","Added By","Added At"'
const baseTrackDataCrying = '"spotify:track:1GrLfs4TEvAZ86HVzXHchS","Crying","spotify:artist:4TXdHyuAOl3rAOFmZ6MeKz","Six by Seven","spotify:album:4iwv7b8gDPKztLkKCbWyhi","Best of Six By Seven","spotify:artist:4TXdHyuAOl3rAOFmZ6MeKz","Six by Seven","2017-02-17","https://i.scdn.co/image/ab67616d0000b273f485821b346237acbbca07ea","1","3","198093","https://p.scdn.co/mp3-preview/daf08df57a49c215c8c53dc5fe88dec5461f15c9?cid=9950ac751e34487dbbe027c4fd7f8e99","false","2","UK4UP1300002","true","","2020-07-19T09:24:39Z"'

// Use a snapshot test to ensure exact component rendering
test("playlist loading", async () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("single playlist exporting", () => {
['https://api.spotify.com/v1/me'],
['https://api.spotify.com/v1/users/watsonbox/playlists?offset=0&limit=20'],
['https://api.spotify.com/v1/users/watsonbox/tracks'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50']
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50&market=from_token']
])
})

Expand Down Expand Up @@ -163,7 +163,7 @@ describe("single playlist exporting", () => {
['https://api.spotify.com/v1/me'],
['https://api.spotify.com/v1/users/watsonbox/playlists?offset=0&limit=20'],
['https://api.spotify.com/v1/users/watsonbox/tracks'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50&market=from_token'],
['https://api.spotify.com/v1/artists?ids=4TXdHyuAOl3rAOFmZ6MeKz']
])
})
Expand Down Expand Up @@ -216,7 +216,7 @@ describe("single playlist exporting", () => {
['https://api.spotify.com/v1/me'],
['https://api.spotify.com/v1/users/watsonbox/playlists?offset=0&limit=20'],
['https://api.spotify.com/v1/users/watsonbox/tracks'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50&market=from_token'],
['https://api.spotify.com/v1/audio-features?ids=1GrLfs4TEvAZ86HVzXHchS']
])
})
Expand Down Expand Up @@ -269,7 +269,7 @@ describe("single playlist exporting", () => {
['https://api.spotify.com/v1/me'],
['https://api.spotify.com/v1/users/watsonbox/playlists?offset=0&limit=20'],
['https://api.spotify.com/v1/users/watsonbox/tracks'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50&market=from_token'],
['https://api.spotify.com/v1/albums?ids=4iwv7b8gDPKztLkKCbWyhi']
])
})
Expand Down Expand Up @@ -324,7 +324,7 @@ describe("single playlist exporting", () => {
['https://api.spotify.com/v1/me'],
['https://api.spotify.com/v1/users/watsonbox/playlists?offset=0&limit=20'],
['https://api.spotify.com/v1/users/watsonbox/tracks'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50'],
['https://api.spotify.com/v1/me/tracks?offset=0&limit=50&market=from_token'],
['https://api.spotify.com/v1/albums?ids=4iwv7b8gDPKztLkKCbWyhi']
])
})
Expand Down Expand Up @@ -402,8 +402,8 @@ describe("single playlist exporting", () => {
{
content: [
`${baseTrackHeaders}\n` +
'"spotify:local:The+Waymores:Heart+of+Stone:Heart+of+Stone:128","Heart of Stone","","The Waymores","","Heart of Stone","","","","","0","0","128000","","false","0","","spotify:user:u8ins5esg43wtxk4h66o5d1nb","2021-02-24T06:12:40Z"\n' +
'"spotify:local:Charlie+Marie:Heard+It+Through+The+Red+Wine:Heard+It+Through+The+Red+Wine:227","Heard It Through The Red Wine","","Charlie Marie","","Heard It Through The Red Wine","","","","","0","0","227000","","false","0","","spotify:user:u8ins5esg43wtxk4h66o5d1nb","2021-02-24T06:12:40Z"\n'
'"spotify:local:The+Waymores:Heart+of+Stone:Heart+of+Stone:128","Heart of Stone","","The Waymores","","Heart of Stone","","","","","0","0","128000","","false","0","","true","spotify:user:u8ins5esg43wtxk4h66o5d1nb","2021-02-24T06:12:40Z"\n' +
'"spotify:local:Charlie+Marie:Heard+It+Through+The+Red+Wine:Heard+It+Through+The+Red+Wine:227","Heard It Through The Red Wine","","Charlie Marie","","Heard It Through The Red Wine","","","","","0","0","227000","","false","0","","true","spotify:user:u8ins5esg43wtxk4h66o5d1nb","2021-02-24T06:12:40Z"\n'
],
options: { type: 'text/csv;charset=utf-8' }
},
Expand Down Expand Up @@ -436,8 +436,8 @@ describe("single playlist exporting", () => {
{
content: [
`${baseTrackHeaders}\n` +
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n' +
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","spotify:user:watsonbox","2020-11-20T15:19:04Z"\n'
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","true","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n' +
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","true","spotify:user:watsonbox","2020-11-20T15:19:04Z"\n'
],
options: { type: 'text/csv;charset=utf-8' }
},
Expand Down Expand Up @@ -519,8 +519,8 @@ test("exporting of all playlists", async () => {
expect(jsZipFileMock).toHaveBeenCalledWith(
"ghostpoet_–_peanut_butter_blues_and_melancholy_jam.csv",
`${baseTrackHeaders}\n` +
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n' +
'"spotify:track:0FNanBLvmFEDyD75Whjj52","Us Against Whatever Ever","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","2","269346","https://p.scdn.co/mp3-preview/e5e39be10697be8755532d02c52319ffa6d58688?cid=9950ac751e34487dbbe027c4fd7f8e99","false","36","GBMEF1000270","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n'
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","true","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n' +
'"spotify:track:0FNanBLvmFEDyD75Whjj52","Us Against Whatever Ever","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","2","269346","https://p.scdn.co/mp3-preview/e5e39be10697be8755532d02c52319ffa6d58688?cid=9950ac751e34487dbbe027c4fd7f8e99","false","36","GBMEF1000270","true","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n'
)

await waitFor(() => {
Expand Down Expand Up @@ -559,8 +559,8 @@ test("exporting of search results", async () => {
expect(jsZipFileMock).toHaveBeenCalledWith(
"ghostpoet_–_peanut_butter_blues_and_melancholy_jam.csv",
`${baseTrackHeaders}\n` +
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n' +
'"spotify:track:0FNanBLvmFEDyD75Whjj52","Us Against Whatever Ever","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","2","269346","https://p.scdn.co/mp3-preview/e5e39be10697be8755532d02c52319ffa6d58688?cid=9950ac751e34487dbbe027c4fd7f8e99","false","36","GBMEF1000270","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n'
'"spotify:track:7ATyvp3TmYBmGW7YuC8DJ3","One Twos / Run Run Run","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","1","241346","https://p.scdn.co/mp3-preview/137d431ad0cf987b147dccea6304aca756e923c1?cid=9950ac751e34487dbbe027c4fd7f8e99","false","22","GBMEF1100339","true","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n' +
'"spotify:track:0FNanBLvmFEDyD75Whjj52","Us Against Whatever Ever","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","spotify:album:6jiLkuSnhzDvzsHJlweoGh","Peanut Butter Blues and Melancholy Jam","spotify:artist:69lEbRQRe29JdyLrewNAvD","Ghostpoet","2011","https://i.scdn.co/image/ab67616d0000b273306e7640be17c5b3468e6e80","1","2","269346","https://p.scdn.co/mp3-preview/e5e39be10697be8755532d02c52319ffa6d58688?cid=9950ac751e34487dbbe027c4fd7f8e99","false","36","GBMEF1000270","true","spotify:user:watsonbox","2020-11-03T15:19:04Z"\n'
)

await waitFor(() => {
Expand Down
8 changes: 5 additions & 3 deletions src/components/data/TracksBaseData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class TracksBaseData extends TracksData {
"Track Preview URL",
"Explicit",
"Popularity",
"ISRC"
"ISRC",
"Is Playable"
]
}

Expand Down Expand Up @@ -60,7 +61,8 @@ class TracksBaseData extends TracksData {
item.track.preview_url == null ? '' : item.track.preview_url,
item.track.explicit,
item.track.popularity,
item.track.external_ids.isrc == null ? '' : item.track.external_ids.isrc
item.track.external_ids.isrc == null ? '' : item.track.external_ids.isrc,
item.track.is_playable
]
]
}))
Expand All @@ -77,7 +79,7 @@ class TracksBaseData extends TracksData {
var limit = this.playlist.tracks.limit ? 50 : 100

for (var offset = 0; offset < this.playlist.tracks.total; offset = offset + limit) {
requests.push(`${this.playlist.tracks.href.split('?')[0]}?offset=${offset}&limit=${limit}`)
requests.push(`${this.playlist.tracks.href.split('?')[0]}?offset=${offset}&limit=${limit}&market=from_token`)
}

const trackPromises = requests.map(request => { return apiCall(request, this.accessToken) })
Expand Down
Loading

0 comments on commit 9b0f396

Please sign in to comment.