You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
616 B
Python
28 lines
616 B
Python
11 months ago
|
import yt_dlp
|
||
|
from config import yt_dlp_opts
|
||
|
|
||
|
|
||
|
# Function to search YouTube
|
||
|
def search_youtube(query, opts = yt_dlp_opts):
|
||
|
with yt_dlp.YoutubeDL(opts) as ydl:
|
||
|
info = ydl.extract_info(query, download=False)
|
||
|
return info['entries']
|
||
|
|
||
|
|
||
|
def download_audio(url, base_path, opts = yt_dlp_opts):
|
||
|
|
||
|
opts['outtmpl'] = f'{base_path}/audios/%(title)s.%(ext)s'
|
||
|
if not isinstance(url, list):
|
||
|
url = [url]
|
||
|
|
||
|
success = False
|
||
|
|
||
|
try:
|
||
|
with yt_dlp.YoutubeDL(opts) as ydl:
|
||
|
ydl.download(url)
|
||
|
success = True
|
||
|
except:
|
||
|
success = False
|
||
|
return success
|
||
|
|
||
|
|