8 lines
470 B
Python
8 lines
470 B
Python
import youtube_dl
|
|
import urllib.parse
|
|
|
|
def getytvideo(songstring, index=0):
|
|
ydl_opts = {'default_search': 'ytsearch{count}'.format(count=index+1), 'quiet': 'true', 'forceurl': 'true'}
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
video_info = ydl.extract_info(songstring, download=False)['entries'][index]
|
|
return {"url": "https://youtu.be/{video_id}".format(video_id=urllib.parse.quote(video_info['id'], safe='')), "duration_s": video_info['duration']} |