File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import os
2+ import sys
3+
4+ import spotipy
5+ from spotipy .oauth2 import SpotifyClientCredentials
6+
7+ cid = 'client_id'
8+ secret = 'client_secret'
9+
10+ auth_manager = SpotifyClientCredentials (client_id = cid , client_secret = secret )
11+ sp = spotipy .Spotify (client_credentials_manager = auth_manager )
12+
13+ print ("Please input the playlist id: " )
14+ id = input ()
15+ id = id .split ('/' )[- 1 ].split ('?' )[0 ]
16+ len = 0
17+ total_dur = 0
18+ alltracks = sp .playlist_tracks (id , None , 100 )
19+ while True :
20+ for track in alltracks ['items' ]:
21+ total_dur += track ['track' ]['duration_ms' ]
22+ len += 1
23+
24+ if alltracks ['next' ] == None :
25+ break
26+
27+ alltracks = sp .next (alltracks )
28+
29+ print ('The average length is - ' + str (total_dur / len / 1000 / 60 ) + ' minutes' )
30+
31+
32+
33+
34+
You can’t perform that action at this time.
0 commit comments