forked from sultansq/kiu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundcloud.py
40 lines (34 loc) · 1.02 KB
/
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
import re
from os import path
from yt_dlp import YoutubeDL
from AnonX.utils.formatters import seconds_to_min
class SoundAPI:
def __init__(self):
self.opts = {
"outtmpl": "downloads/%(id)s.%(ext)s",
"format": "best",
"retries": 3,
"nooverwrites": False,
"continuedl": True,
}
async def valid(self, link: str):
if "soundcloud" in link:
return True
else:
return False
async def download(self, url):
d = YoutubeDL(self.opts)
try:
info = d.extract_info(url)
except:
return False
xyz = path.join("downloads", f"{info['id']}.{info['ext']}")
duration_min = seconds_to_min(info["duration"])
track_details = {
"title": info["title"],
"duration_sec": info["duration"],
"duration_min": duration_min,
"uploader": info["uploader"],
"filepath": xyz,
}
return track_details, xyz