-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
46 lines (37 loc) · 1.23 KB
/
Copy pathutils.py
File metadata and controls
46 lines (37 loc) · 1.23 KB
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
import os
import subprocess
import datetime
counter_file = "counter.txt"
def reset_counter_if_new_week():
today = datetime.datetime.now().isocalendar()[1]
if os.path.exists(counter_file):
with open(counter_file) as f:
saved_week, count = map(int, f.read().split(","))
if saved_week != today:
with open(counter_file, "w") as f:
f.write(f"{today},0")
else:
with open(counter_file, "w") as f:
f.write(f"{today},0")
def get_current_count():
reset_counter_if_new_week()
with open(counter_file) as f:
_, count = f.read().split(",")
return int(count)
def can_download_more():
return get_current_count() < 500
def increase_count(n=1):
week = datetime.datetime.now().isocalendar()[1]
count = get_current_count()
with open(counter_file, "w") as f:
f.write(f"{week},{count+n}")
def download_spotify(link, single=True):
folder = "downloads"
os.makedirs(folder, exist_ok=True)
os.chdir(folder)
cmd = ["spotdl", "download", link]
subprocess.call(cmd)
songs = [f for f in os.listdir() if f.endswith(".mp3")]
paths = [os.path.join(os.getcwd(), song) for song in songs]
os.chdir("..")
return paths