Files
Video-Archive-Discord-Bot/downloader.py
Matthew Adams b7d47701bf Initial commit
2021-03-02 18:24:24 +10:00

27 lines
551 B
Python

import youtube_dl
def download(videoUrl):
ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s.mp4'})
ydl_opts = {}
with ydl:
result = ydl.extract_info(
videoUrl,
download=True
)
if 'entries' in result:
# Can be a playlist or a list of videos
video = result['entries'][0]
return "Error: More than 1 result found"
else:
# Just a video
video = result
print(video)
video_url = video['title']
videoId = video['id']
return videoId + ".mp4"