26 lines
795 B
Python
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)
|