Sekuro commited on
Commit
ca80603
·
verified ·
1 Parent(s): af6298d

Upload download_video.py

Browse files
Files changed (1) hide show
  1. download_video.py +32 -0
download_video.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import yt_dlp
3
+
4
+ def download(url):
5
+ output_path = 'tmp/input_video.mp4'
6
+
7
+ ydl_opts = {
8
+ 'format': 'bestvideo+bestaudio/best',
9
+ 'postprocessors': [{
10
+ 'key': 'FFmpegVideoConvertor',
11
+ 'preferedformat':'mp4'
12
+ }],
13
+ 'outtmpl': output_path,
14
+ 'postprocessor_args': [
15
+ '-movflags', 'faststart'
16
+ ],
17
+ 'merge_output_format':'mp4'
18
+ }
19
+
20
+ while True:
21
+ try:
22
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
23
+ ydl.download([url])
24
+ break
25
+ except yt_dlp.utils.DownloadError as e:
26
+ if "is not a valid URL" in str(e):
27
+ print("Erro: o link inserido não é válido.")
28
+ url = input("\nPor favor, insira um link válido: ")
29
+ else:
30
+ raise
31
+
32
+ return output_path