Skip to content

Commit

Permalink
Get userId for playlist since need userId on spotify APIs to get a pl…
Browse files Browse the repository at this point in the history
…aylist
  • Loading branch information
xuezhma committed Dec 1, 2017
1 parent bceed4f commit 4d9a46a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { didYouMean, aggressiveDidYouMeanSpotify } = require('did-you-mean-bing')
didYouMean('play fireworks by katy perry')
// 'play firework by katy perry'
```
`aggressiveDidYouMeanSpotify` , aggressively finds a track/album/artist/playlist on spotify. Returns the item with its spotify `id`, and `type`.
`aggressiveDidYouMeanSpotify` , aggressively finds a track/album/artist/playlist on spotify. Returns the item with its spotify `id`, and `type`. If it's a playlist, `userId` will also be returned.
```
aggressiveDidYouMeanSpotify('play fireworks by katy perry')
// {type: 'track', id: '1mXuMM6zjPgjL4asbBsgnt'}
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function aggressiveDidYouMeanSpotify(wrongQuery) {
.then(html => {
const typeAndId = html.split('https://open.spotify.com/')[1].split('"')[0].split("/")
const length = typeAndId.length
if (typeAndId[length - 2] === 'playlist') return {type: typeAndId[length - 2], id: typeAndId[length - 1], userId: typeAndId[length - 3]}
return {type: typeAndId[length - 2], id: typeAndId[length - 1]}
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/aggressiveSpotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe('Get playable from Spotify aggressively with wrong name, track/album/ar
runAggressiveDidYouMeanSpotify('play firefly from owl city', {type: 'track', id: '1mr3616BzLdhXfJmLmRsO8'})
runAggressiveDidYouMeanSpotify('play sunny day from armin van buuren', {type: 'album', id: '0SottnyJaBApBrZZT6Y3kb'})
runAggressiveDidYouMeanSpotify('play Selina Gomez', {type: 'artist', id: '0C8ZW7ezQVs4URX5aX7Kqx'})
runAggressiveDidYouMeanSpotify('play new music fridays', {type: 'playlist', id: '1yHZ5C3penaxRdWR7LRIOb'})
runAggressiveDidYouMeanSpotify('play new music fridays', {type: 'playlist', id: '1yHZ5C3penaxRdWR7LRIOb', userId: 'spotify'})
})

describe('Get playable from Spotify aggressively with correct name', function vevoTest() {
Expand All @@ -14,5 +14,5 @@ describe('Get playable from Spotify aggressively with correct name', function ve
runAggressiveDidYouMeanSpotify('play fireflies from owl city', {type: 'track', id: '1mr3616BzLdhXfJmLmRsO8'})
runAggressiveDidYouMeanSpotify('play sunny days from armin van buuren', {type: 'album', id: '2Pnc34J8XGKOfnBBnfJisu'})
runAggressiveDidYouMeanSpotify('play Selena Gomez', {type: 'artist', id: '0C8ZW7ezQVs4URX5aX7Kqx'})
runAggressiveDidYouMeanSpotify('play new music friday', {type: 'playlist', id: '1yHZ5C3penaxRdWR7LRIOb'})
runAggressiveDidYouMeanSpotify('play new music friday', {type: 'playlist', id: '1yHZ5C3penaxRdWR7LRIOb', userId: 'spotify'})
})

0 comments on commit 4d9a46a

Please sign in to comment.