forked from Kakarot-2000/Wall-E
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathYTDL.py
32 lines (25 loc) · 842 Bytes
/
YTDL.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
27
28
29
30
31
32
import asyncio
import discord
import youtube_dl
youtube_dl.utils.bug_reports_message = lambda: ''
ytdl_format_options = {
'format': 'bestaudio/best'
}
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)
self.data = data
self.title = data.get('title')
@classmethod
async def from_url(cls, url, *, loops=None, stream=True):
loop = None
if loops is None:
loop = asyncio.get_event_loop()
else:
loop = loops
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
if 'entries' in data:
data = data['entries']
# return url, fileName, time
return data