twblue/src/audio_services/youtube_utils.py

14 lines
417 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-06-06 11:52:23 -05:00
from __future__ import unicode_literals
import youtube_dl
def get_video_url(url):
ydl = youtube_dl.YoutubeDL({'quiet': True, 'format': 'bestaudio/best', 'outtmpl': u'%(id)s%(ext)s'})
with ydl:
result = ydl.extract_info(url, download=False)
if 'entries' in result:
video = result['entries'][0]
else:
video = result
return video["formats"][0]["url"]