forked from alonitac/TelegramAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
24 lines (20 loc) · 800 Bytes
/
utils.py
File metadata and controls
24 lines (20 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import time
from yt_dlp import YoutubeDL
def search_download_youtube_video(video_name, num_results=1):
"""
This function downloads the first num_results search results from Youtube
:param video_name: string of the video name
:param num_results: integer representing how many videos to download
:return: list of paths to your downloaded video files
"""
results = []
with YoutubeDL() as ydl:
videos = ydl.extract_info(f"ytsearch{num_results}:{video_name}", download=True)['entries']
for video in videos:
results.append({
'filename': ydl.prepare_filename(video),
'video_id': video['id'],
'title': video['title'],
'url': video['webpage_url']
})
return results