Skip to content

Commit

Permalink
highlight tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
teticio committed Oct 3, 2021
1 parent bf40465 commit 8fccbb8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
20 changes: 13 additions & 7 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async def make_playlist_widget(playlist_widget: schemas.PlaylistWidget):
"""Make a new Spotify playlist widget.
Args:
playlist_widget (schemas.PlaylistWidget): List of track IDs.
playlist_widget (schemas.PlaylistWidget): List of track IDs and waypoints.
Returns:
str: Base 64 encoded HTML which can be embedded in an iframe.
Expand Down Expand Up @@ -288,15 +288,21 @@ async def make_playlist_widget(playlist_widget: schemas.PlaylistWidget):
for track_id in playlist_widget.track_ids:
title = deejai.tracks[track_id]
track = {
'is_local': True,
'is_playable': True,
'name': title[title.find(' - ') + 3:],
'preview_url': deejai.urls.get(track_id, ''),
'is_local':
True,
'is_playable':
True,
'name': ('* ' if track_id in playlist_widget.waypoints else '') +
title[title.find(' - ') + 3:],
'preview_url':
deejai.urls.get(track_id, ''),
'artists': [{
'name': title[:title.find(' - ')]
}],
'duration_ms': '30000',
'uri': f'spotify:track{track_id}'
'duration_ms':
'30000',
'uri':
f'spotify:track{track_id}'
}
playlist['tracks']['items'].append({'track': track})
playlist['name'] = playlist['tracks']['items'][0]['track']['name']
Expand Down
1 change: 1 addition & 0 deletions backend/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ class PlaylistWidget(BaseModel): # pylint: disable=too-few-public-methods
"""Schema for generating a new playlist widget.
"""
track_ids: list
waypoints: list
3 changes: 2 additions & 1 deletion src/components/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default function Playlist({ track_ids = [], waypoints = [] }) {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'track_ids': track_ids
'track_ids': track_ids,
'waypoints': waypoints
})
})
.then(response => (response.status === 200) ? response.text() : '')
Expand Down

0 comments on commit 8fccbb8

Please sign in to comment.