spotipy/examples/check_show_is_saved.py
jonathan-huston ba01a6aee5
Examples directory updates (#1055)
* 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 <stephane.bruckert@gmail.com>
2025-01-12 14:47:10 +00:00

32 lines
981 B
Python

"""
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()