|
1 | 1 | import youtube_dl |
2 | | - |
| 2 | +from typing import List |
3 | 3 |
|
4 | 4 | class SoundCloud: |
5 | | - def __init__(self, url: str): |
| 5 | + def __init__(self, url: str) -> None: |
6 | 6 | self.url = url |
7 | 7 | self.info = self.extract_info() |
8 | 8 |
|
9 | | - def ydl_option(self): |
| 9 | + def ydl_option(self) -> None: |
10 | 10 | return {"dumpjson": True, "extract_flat": True} |
11 | 11 |
|
12 | | - def extract_info(self): |
13 | | - try: |
14 | | - with youtube_dl.YoutubeDL(self.ydl_option()) as ydl: |
15 | | - return ydl.extract_info(url=self.url, download=False) |
16 | | - except Exception as e: |
17 | | - return e |
18 | | - |
| 12 | + def extract_info(self) -> dict: |
| 13 | + with youtube_dl.YoutubeDL(self.ydl_option()) as ydl: |
| 14 | + return ydl.extract_info(url=self.url, download=False) |
| 15 | + |
19 | 16 | @property |
20 | | - def genre(self): |
| 17 | + def genre(self) -> str: |
21 | 18 | return self.info["genre"] |
22 | 19 |
|
23 | 20 | @property |
24 | | - def formats(self): |
| 21 | + def formats(self) -> List: |
25 | 22 | return self.info["formats"] |
26 | 23 |
|
27 | 24 | @property |
28 | | - def caption(self): |
| 25 | + def caption(self) -> str: |
29 | 26 | return self.info["description"] |
30 | 27 |
|
31 | 28 | @property |
32 | | - def thumbnails(self): |
| 29 | + def thumbnails(self) -> List: |
33 | 30 | return self.info["thumbnails"] |
34 | 31 |
|
35 | 32 | @property |
36 | | - def view_count(self): |
| 33 | + def view_count(self) -> int: |
37 | 34 | return self.info["view_count"] |
38 | 35 |
|
39 | 36 | @property |
40 | | - def comment_count(self): |
| 37 | + def comment_count(self) -> int: |
41 | 38 | return self.info["comment_count"] |
42 | 39 |
|
43 | 40 | @property |
44 | | - def repost_count(self): |
| 41 | + def repost_count(self) -> int: |
45 | 42 | return self.info["repost_count"] |
46 | 43 |
|
47 | 44 | @property |
48 | | - def like_count(self): |
| 45 | + def like_count(self) -> int: |
49 | 46 | return self.info["like_count"] |
50 | 47 |
|
51 | 48 | @property |
52 | | - def idd(self): |
| 49 | + def idd(self) -> str: |
53 | 50 | return self.info["id"] |
54 | 51 |
|
55 | 52 | @property |
56 | | - def uploader(self): |
| 53 | + def uploader(self) -> str: |
57 | 54 | return self.info["uploader"] |
58 | 55 |
|
59 | 56 | @property |
60 | | - def uploader_id(self): |
| 57 | + def uploader_id(self) -> str: |
61 | 58 | return self.info["uploader_id"] |
62 | 59 |
|
63 | 60 | @property |
64 | | - def uploader_url(self): |
| 61 | + def uploader_url(self) -> str: |
65 | 62 | return self.info["uploader_url"] |
66 | 63 |
|
67 | 64 | @property |
68 | | - def upload_date(self): |
| 65 | + def upload_date(self) -> int: |
69 | 66 | return self.info["timestamp"] |
70 | 67 |
|
71 | 68 | @property |
72 | | - def title(self): |
| 69 | + def title(self) -> str: |
73 | 70 | return self.info["title"] |
0 commit comments