mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
* 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>
29 lines
898 B
Python
29 lines
898 B
Python
"""
|
|
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() |