-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotify_dl.py
More file actions
31 lines (25 loc) · 754 Bytes
/
spotify_dl.py
File metadata and controls
31 lines (25 loc) · 754 Bytes
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
import os
from concurrent.futures import ThreadPoolExecutor
from nicegui import ui
pool = ThreadPoolExecutor(max_workers=5)
downids = []
downmap = {}
def spotify_download(track_id):
global downids
global downmap
if track_id in downids:
return
downids.append(track_id)
future = pool.submit(download_track, track_id)
downmap[track_id] = future
ui.notify('Downloading track '+track_id)
def download_track(track_id):
os.system(f'cd downloads && spotdl https://open.spotify.com/track/{track_id} --overwrite skip')
def get_pending():
global downmap
global downids
pending = []
for track_id in downids:
if not downmap[track_id].done():
pending.append(track_id)
return pending