-
Notifications
You must be signed in to change notification settings - Fork 0
/
YTSource.py
26 lines (21 loc) · 1.01 KB
/
YTSource.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
import yt_dlp
YDL_OPTIONS = {'extract_flat': 'in_playlist', 'format':"bestaudio", 'playlistend':'-1', 'default_search': 'ytsearch1:'}
# Downloads the song data and returns it
def getSongSource(link: str) -> dict:
YDL_OPTIONS['extract_flat'] = 'false'
with yt_dlp.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(link, download=False)
if '_type' in info:
info = info['entries'][0]
source = {'extracted':True, 'source': info['url'], 'id':info['id'], 'thumbnail': info['thumbnail'], 'title':info['title']}
return source
# Gets the playlist data, exactly, the title and url of every song.
def getPlaylistSource(link: str) -> list:
YDL_OPTIONS['extract_flat'] = 'in_playlist'
sources = []
with yt_dlp.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(link, download=False)
for song in info['entries']:
source = {'extracted':False, 'title': song['title'], 'search': song['url']}
sources.append(source)
return sources