-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuno_Time_Summation.py
72 lines (61 loc) · 2.24 KB
/
Suno_Time_Summation.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Suno Time Adder
# Adds up all the durations of music in a Suno playlist
albums = ["2cf0cd7b-e48e-492d-ad6c-20e1f2182923", "aa8b969d-9d94-45bf-8c61-0d140af88fac"] # Bible 1 and 2
# ALBUM = "c4a5f43a-bad3-4bde-ab14-42992d26f8d0" # Klein
# ALBUM = "4d1bdb98-a96f-4d4a-909c-453034fcea23" # Tradwife
DEBUG = True
from urllib.request import urlopen, Request
import webbrowser
from HTML_Cleaner import *
def get_webpage_data(site=SITE):
print("fetching", site)
try:
req = Request(site, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'})
with urlopen(req) as wbpg:
html = wbpg.read()
except:
print('fetch failed')
raise
return None
h = html.decode("utf-8")
if DEBUG: print("raw html ", len(h), "chars")
c = extract_contents(h, 'div class="react-aria-GridList"')[0]
if DEBUG: print("page content", len(c), "chars")
tstmps = extract_contents(c, 'span class="flex absolute bottom-[2px] items-center right-[2px] text-[11px]')
print("got", len(tstmps), "timestamps")
return tstmps
def find_seconds(timestamp_label):
total_secs = 0
digits = timestamp_label.split(':')
i = 0
while len(digits) > 0:
total_secs += (60**i) * int(digits.pop())
i += 1
return total_secs
def generate_timestamp(seconds):
days = seconds // 86400
hours = (seconds % 86400) // 3600
minutes = (seconds % 3600) // 60
seconds = seconds % 60
if days > 0:
timestamp_label = f"{days}d {hours}:{minutes:02}:{seconds:02}"
elif hours > 0:
timestamp_label = f"{hours}:{minutes:02}:{seconds:02}"
else:
timestamp_label = f"{minutes:02}:{seconds:02}"
return timestamp_label
def sum_timestamps(tstmps):
total = 0
for tst in tstmps:
total += find_seconds(tst)
return total
if __name__ == '__main__':
total_seconds = 0
for ALBUM in albums:
SITE = f"https://suno.com/playlist/{ALBUM}"
tstmps = get_webpage_data(SITE)
if tstmps:
total_seconds += sum_timestamps(tstmps)
formatted_total = generate_timestamp(total_seconds)
print("Total duration:", formatted_total)
input("enter to exit")