dj-embe/framework/youtube.py
2023-04-28 01:19:18 +02:00

26 lines
795 B
Python

from yt_dlp import YoutubeDL
from youtubesearchpython.__future__ import VideosSearch
from asyncio import AbstractEventLoop
from config import YoutubeConfig
class Youtube:
def __init__(self, loop: AbstractEventLoop, config: YoutubeConfig) -> None:
self.params = {}
self.client = YoutubeDL(self.params)
self.loop = loop
self.config = config
async def searchVideo(self, query: str):
videosSearch = VideosSearch(
query, limit=1, language=self.config.language, region=self.config.region
)
return await videosSearch.next()
async def get_data(self, url: str) -> str:
data = await self.loop.run_in_executor(
None, lambda: self.client.extract_info(url, download=False)
)
print(data)