Skip to content

Commit 4ae79e8

Browse files
authored
Init Commit With Spotify Len
1 parent cdfe736 commit 4ae79e8

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

AverageLenSpotify.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+

0 commit comments

Comments
 (0)