Skip to content

Commit

Permalink
get next song function (original)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangsimanketkaew committed Oct 23, 2022
1 parent 80eecdf commit b966785
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions notebooks/skiptify_get_next_song.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
"def get_next_song(sp, playlist_id):\n",
"def get_next_song(sp):\n",
" \"\"\"Get the next song in the currently playing playlist\n",
"\n",
" Args:\n",
Expand All @@ -57,7 +57,8 @@
" # Get all tracks of the given playlist\n",
" # playlist_id = \"3B4pbKqnUer2d7DII1QC8Q\"\n",
" offset_n = 0\n",
" results = sp.user_playlist_tracks(sp.me()['id'], playlist_id, offset=offset_n)\n",
" results = sp.user_playlist_tracks(sp.me()['id'], sp.currently_playing()[\n",
" 'context']['uri'].split(':')[2], offset=offset_n)\n",
"\n",
" json_results = json.dumps(results)\n",
" data = json.loads(json_results)\n",
Expand All @@ -79,29 +80,35 @@
" idx_next_song = all_track_id.index(current_song_id) + 1\n",
"\n",
" # Check and return the id of the song next to the currently playing song\n",
" return all_track_id[idx_next_song], all_track_name[idx_next_song]\n",
" "
" return all_track_id[idx_next_song], all_track_name[idx_next_song]\n"
]
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('1AsQFm7ORbr4NEZ0dUltOY', 'Way It Goes')"
"('0VjIjW4GlUZAMYd2vXMi3b', 'Blinding Lights')"
]
},
"execution_count": 55,
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_next_song(sp, \"3B4pbKqnUer2d7DII1QC8Q\")"
"get_next_song(sp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit b966785

Please sign in to comment.