-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/JeanBaptiste-dlb/Skiptify …
…into develop
- Loading branch information
Showing
4 changed files
with
295 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.idea/ | ||
.cache* | ||
settings.json | ||
*my_token.py | ||
|
||
data/tmp | ||
# Byte-compiled / optimized / DLL files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 42, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import spotipy\n", | ||
"from spotipy.oauth2 import SpotifyClientCredentials\n", | ||
"import json\n", | ||
"\n", | ||
"from my_token import *\n", | ||
"\n", | ||
"os.environ[\"SPOTIPY_CLIENT_ID\"] = SPOTIPY_CLIENT_ID\n", | ||
"os.environ[\"SPOTIPY_CLIENT_SECRET\"] = SPOTIPY_CLIENT_SECRET\n", | ||
"os.environ[\"SPOTIPY_REDIRECT_URI\"] = SPOTIPY_REDIRECT_URI\n", | ||
"\n", | ||
"scope = 'user-read-currently-playing'\n", | ||
"# scope = 'user-modify-playback-state'\n", | ||
"# scope = 'user-read-recently-played'\n", | ||
"\n", | ||
"# To connect succesfully you need to provide your own Spotify Credentials\n", | ||
"# You can do this signing up in https://developer.spotify.com/ and creating a new app.\n", | ||
"token = spotipy.util.prompt_for_user_token(\n", | ||
" USERNAME, scope, client_id=SPOTIPY_CLIENT_ID, client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIRECT_URI)\n", | ||
"\n", | ||
"sp = spotipy.Spotify(auth=token)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Check song in playing and find the next song" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 53, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_next_song(sp, playlist_id):\n", | ||
" \"\"\"Get the next song in the currently playing playlist\n", | ||
"\n", | ||
" Args:\n", | ||
" sp (_type_): Spotipy authentication\n", | ||
" current_track_id (str): id of the currently playing track\n", | ||
" playlist_id (str): id of the currently playing playlist\n", | ||
"\n", | ||
" Returns:\n", | ||
" track_id of the next song\n", | ||
" track_name of the next song\n", | ||
" \"\"\"\n", | ||
" # 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", | ||
"\n", | ||
" json_results = json.dumps(results)\n", | ||
" data = json.loads(json_results)\n", | ||
"\n", | ||
" # Get id of all tracks\n", | ||
" all_track_id = []\n", | ||
" all_track_name = []\n", | ||
" for track in data['items']:\n", | ||
" track_id = track['track']['id']\n", | ||
" date_added = track['added_at']\n", | ||
" track_name = track['track']['name']\n", | ||
" all_track_id.append(track_id)\n", | ||
" all_track_name.append(track_name)\n", | ||
"\n", | ||
" # get currently playing song\n", | ||
" current_song = sp.currently_playing()\n", | ||
" current_song_id = current_song['item']['id']\n", | ||
"\n", | ||
" 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", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 55, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"('1AsQFm7ORbr4NEZ0dUltOY', 'Way It Goes')" | ||
] | ||
}, | ||
"execution_count": 55, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"get_next_song(sp, \"3B4pbKqnUer2d7DII1QC8Q\")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.9.13 ('base')", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "c6e4e9f98eb68ad3b7c296f83d20e6de614cb42e90992a65aa266555a3137d0d" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import spotipy\n", | ||
"from spotipy.oauth2 import SpotifyClientCredentials\n", | ||
"from my_token import *\n", | ||
"\n", | ||
"os.environ[\"SPOTIPY_CLIENT_ID\"] = SPOTIPY_CLIENT_ID\n", | ||
"os.environ[\"SPOTIPY_CLIENT_SECRET\"] = SPOTIPY_CLIENT_SECRET\n", | ||
"os.environ[\"SPOTIPY_REDIRECT_URI\"] = SPOTIPY_REDIRECT_URI\n", | ||
"\n", | ||
"auth_manager = SpotifyClientCredentials()\n", | ||
"sp = spotipy.Spotify(auth_manager=auth_manager)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
" 1 spotify:playlist:35Pg8gI6Rgw4ccqNd5skcv Best Chill Mix\n", | ||
" 2 spotify:playlist:3B4pbKqnUer2d7DII1QC8Q Good Vibes\n", | ||
" 3 spotify:playlist:5KV4fkw3FkdOpT3Wan2Jvf Emotional, Sad & Lovely\n", | ||
" 4 spotify:playlist:00Y1KcNQphDPzFb3KY2Y4t Dance & excitement\n", | ||
" 5 spotify:playlist:7zlU42UvIgfRqpHXVA6NrD Epic soundtrack\n", | ||
" 6 spotify:playlist:6Dvljqvm1SEsy4uP6O8Tfj Mixed Thai musics\n", | ||
" 7 spotify:playlist:6Xp2hKEGGREbZnzdCV6mzN Thai country songs\n", | ||
" 8 spotify:playlist:7rCQqQKoMCzjJsMrzlhrt8 Soundtrack\n", | ||
" 9 spotify:playlist:1Tz5apWYRM5gJfLm1VK4y2 Thai folk songs\n", | ||
" 10 spotify:playlist:26nJKkz1djwNDxnEFNPLtF Linkin Park!!\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"playlists = sp.user_playlists('nutty_chem')\n", | ||
"my_playlists = []\n", | ||
"while playlists:\n", | ||
" for i, playlist in enumerate(playlists['items']):\n", | ||
" print(\"%4d %s %s\" % (i + 1 + playlists['offset'], playlist['uri'], playlist['name']))\n", | ||
" # print(playlist.keys())\n", | ||
" my_playlists.append(playlist['id'])\n", | ||
" if playlists['next']:\n", | ||
" playlists = sp.next(playlists)\n", | ||
" else:\n", | ||
" playlists = None" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"['35Pg8gI6Rgw4ccqNd5skcv',\n", | ||
" '3B4pbKqnUer2d7DII1QC8Q',\n", | ||
" '5KV4fkw3FkdOpT3Wan2Jvf',\n", | ||
" '00Y1KcNQphDPzFb3KY2Y4t',\n", | ||
" '7zlU42UvIgfRqpHXVA6NrD',\n", | ||
" '6Dvljqvm1SEsy4uP6O8Tfj',\n", | ||
" '6Xp2hKEGGREbZnzdCV6mzN',\n", | ||
" '7rCQqQKoMCzjJsMrzlhrt8',\n", | ||
" '1Tz5apWYRM5gJfLm1VK4y2',\n", | ||
" '26nJKkz1djwNDxnEFNPLtF']" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"my_playlists" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.9.13 ('base')", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "c6e4e9f98eb68ad3b7c296f83d20e6de614cb42e90992a65aa266555a3137d0d" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |