-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed scripts in examples directory that didn't work, deleted any redundant examples. * Added examples for methods related to audiobooks, shows and episodes * Updated changelog --------- Co-authored-by: Stéphane Bruckert <[email protected]>
- Loading branch information
1 parent
645ed6d
commit ba01a6a
Showing
18 changed files
with
268 additions
and
57 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
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,28 @@ | ||
""" | ||
Add episodes to current user's library | ||
Usage: add_saved_episodes.py -e episode_id episode_id ... | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
scope = 'user-library-modify' | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Add episodes to library') | ||
# Default args set to This American Life episodes 814 and 815 | ||
parser.add_argument('-e', '--eids', nargs='+', | ||
default=['6rxg9Lpt2ywNHFea8LxEBO', '7q8or6oYYRFQFYlA0remoy'], | ||
help='Episode ids') | ||
return parser.parse_args() | ||
|
||
def main(): | ||
args = get_args() | ||
print('Adding following episode ids to library: ' + str(args.eids)) | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) | ||
sp.current_user_saved_episodes_add(episodes=args.eids) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,28 @@ | ||
""" | ||
Add shows to current user's library | ||
Usage: add_saved_shows.py -s show_id show_id ... | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
scope = 'user-library-modify' | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Add shows to library') | ||
# Default args set to Radiolab and 99% invisible | ||
parser.add_argument('-s', '--sids', nargs='+', | ||
default=['2hmkzUtix0qTqvtpPcMzEL', '2VRS1IJCTn2Nlkg33ZVfkM'], | ||
help='Show ids') | ||
return parser.parse_args() | ||
|
||
def main(): | ||
args = get_args() | ||
print('Adding following show ids to library: ' + str(args.sids)) | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) | ||
sp.current_user_saved_shows_add(shows=args.sids) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,31 @@ | ||
""" | ||
Check if shows are saved in user's library | ||
Usage: check_show_is_saved -s show_id show_id ... | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
scope = 'user-library-read' | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Check that a show is saved') | ||
# Default args set to Radiolab and 99% invisible | ||
parser.add_argument('-s', '--sids', nargs='+', | ||
default=['2hmkzUtix0qTqvtpPcMzEL', '2VRS1IJCTn2Nlkg33ZVfkM'], | ||
help='Show ids') | ||
return parser.parse_args() | ||
|
||
def main(): | ||
args = get_args() | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) | ||
results = sp.current_user_saved_episodes_contains(episodes=args.sids) | ||
show_names = sp.shows(shows=args.sids) | ||
# Print show names and if show is saved by current user | ||
for i, show in enumerate(show_names['shows']): | ||
print(show['name'] + ': ' + str(results[i])) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,28 @@ | ||
""" | ||
Delete episodes from current user's library | ||
Usage: delete_saved_episodes.py -e episode_id episode_id ... | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
scope = 'user-library-modify' | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Delete episodes from library') | ||
# Default args set to This American Life episodes 814 and 815 | ||
parser.add_argument('-e', '--eids', nargs='+', | ||
default=['6rxg9Lpt2ywNHFea8LxEBO', '7q8or6oYYRFQFYlA0remoy'], | ||
help='Episode ids') | ||
return parser.parse_args() | ||
|
||
def main(): | ||
args = get_args() | ||
print('Deleting following episode ids from library: ' + str(args.eids)) | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) | ||
sp.current_user_saved_episodes_delete(episodes=args.eids) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,27 +1,22 @@ | ||
import argparse | ||
# Follow a playlist | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
scope = 'playlist-modify-public' | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Follows a playlist based on playlist ID') | ||
parser.add_argument('-p', '--playlist', required=True, help='Playlist ID') | ||
|
||
# Default to Top 50 Global if no playlist is provided | ||
parser.add_argument('-p', '--playlist', help='Playlist ID', nargs='?', default='37i9dQZEVXbMDoHDwVN2tF') | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = get_args() | ||
|
||
if args.playlist is None: | ||
# Uses the Spotify Global Top 50 playlist | ||
spotipy.Spotify(auth_manager=SpotifyOAuth()).current_user_follow_playlist( | ||
'37i9dQZEVXbMDoHDwVN2tF') | ||
|
||
else: | ||
spotipy.Spotify(auth_manager=SpotifyOAuth()).current_user_follow_playlist(args.playlist) | ||
|
||
sp.current_user_follow_playlist(args.playlist) | ||
|
||
if __name__ == '__main__': | ||
main() | ||
main() |
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,29 @@ | ||
""" | ||
Print chapter titles and lengths for given audiobook | ||
Usage: get_audiobooks_chapters_info.py -a audiobook_id | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Get chapter info for an audiobook') | ||
# Default set to Dune | ||
parser.add_argument('-a', '--audiobook', default='2h01INWMBvfpzNMpGFzhdF', help='Audiobook id') | ||
return parser.parse_args() | ||
|
||
|
||
def main(): | ||
args = get_args() | ||
print('Getting chapter info for follow audiobook id: ' + str(args.audiobook)) | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth()) | ||
results = sp.get_audiobook_chapters(id=args.audiobook) | ||
# Print chapter name and length | ||
for item in results['items']: | ||
print('Name: ' + item['name'] + ', length: ' + str(round(item['duration_ms']/60000,1)) + ' minutes') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,29 @@ | ||
""" | ||
Print audiobook title and description for a list of audiobook ids | ||
Usage: get_audiobooks_info.py -a audiobook_id audiobook_id ... | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Get information for a list of audiobooks') | ||
# Defaults set to The Great Gatsby, The Chronicles of Narnia and Dune | ||
parser.add_argument('-a', '--aids', nargs='+', | ||
default=['6qjpt1CUHhKXiNoeNoU7nu', '1ezmXd68LbDtxebvygEQ2U', '2h01INWMBvfpzNMpGFzhdF'], | ||
help='Audiobook ids') | ||
return parser.parse_args() | ||
|
||
def main(): | ||
args = get_args() | ||
print('Getting info for follow audiobook ids: ' + str(args.aids) + '\n') | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth()) | ||
results = sp.get_audiobooks(ids=args.aids) | ||
# Print book title and description | ||
for book in results['audiobooks']: | ||
print('Title: ' + book['name'] + '\n' + book['description'] + '\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file was deleted.
Oops, something went wrong.
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
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
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
""" | ||
List current user's saved episodes | ||
Usage: user_saved_episodes -l <num> -o <num> | ||
""" | ||
|
||
import argparse | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth | ||
|
||
scope = 'user-library-read' | ||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser(description='Show user\'s saved episodes') | ||
parser.add_argument('-l', '--limit', default=20, help='Num of episodes to return') | ||
parser.add_argument('-o', '--offset', default=0, help='Index of first show to return') | ||
|
||
return parser.parse_args() | ||
|
||
def main(): | ||
args = get_args() | ||
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) | ||
results = sp.current_user_saved_episodes(limit=args.limit, offset=args.offset) | ||
# Print episode names | ||
for item in results['items']: | ||
print(item['episode']['name']) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.