-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_audio.py
27 lines (26 loc) · 1019 Bytes
/
video_audio.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
import yt_dlp
def download_video(url, download_type):
if download_type == 'video':
ydl_opts = {
'outtmpl': '%(title)s.%(ext)s',
'format': 'bestvideo+bestaudio/best',
}
elif download_type == 'audio':
ydl_opts = {
'outtmpl': '%(title)s.%(ext)s',
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
else:
print("Type de téléchargement non valide. Veuillez choisir 'video' ou 'audio'.")
return
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
if __name__ == '__main__':
video_url = input("Veuillez entrer l'URL de la vidéo: ")
download_type = input("Voulez-vous télécharger la vidéo ou l'audio? (video/audio): ").strip().lower()
download_video(video_url, download_type)