-
Notifications
You must be signed in to change notification settings - Fork 0
/
py_soundcloud.py
54 lines (48 loc) · 1.67 KB
/
py_soundcloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from sclib import SoundcloudAPI, Track, Playlist # pip install soundcloud-lib
api = SoundcloudAPI()
def get_playlist():
question = input("Enter playlist url or any number to exit: ")
try:
playlist = api.resolve(question)
assert type(playlist) is Playlist
for track in playlist.tracks:
filename = f'./{track.artist} - {track.title}.mp3'
try:
with open(filename, 'wb+') as file:
track.write_mp3_to(file)
except Exception as e:
print("Track error:", e)
return 0
except Exception as e:
print("Link error: ", e)
print("Exiting...")
return 0
def get_track():
question = input("Enter track url or any number to exit: ")
try:
track = api.resolve(question)
assert type(track) is Track
filename = f'./{track.artist} - {track.title}.mp3'
with open(filename, 'wb+') as file:
track.write_mp3_to(file)
except Exception as e:
print("Link error: ", e)
print("Exiting...")
return 0
question1 = input("1 for playlist link || 2 for track link || or any other number to exit: ")
while True:
if int(question1) == 1:
check = get_playlist()
if check == 0: #If 0 returned instead of link it closes
break
else: # Else run
continue
elif int(question1) == 2:
check = get_track()
if check == 0: #If 0 returned instead of link it closes
break
else: # Else run
continue
else: # If something else than 1 or 2 is entered its closed.
print("Exiting..")
break