Maximo Fernandez
commited on
Commit
路
23816e9
1
Parent(s):
73839c5
Download from youtube with pytube
Browse files- download.py +22 -6
download.py
CHANGED
@@ -66,14 +66,30 @@ def download_twitch(url, type):
|
|
66 |
os.system(f'rm {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format}')
|
67 |
|
68 |
def download_youtube_video(url):
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
def download_youtube_audio(url):
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
def download_youtube(url, type):
|
79 |
if type == DOWNLOAD_VIDEO:
|
|
|
66 |
os.system(f'rm {AUDIO_FOLDER}/{DOWNLOAD_AUDIO_NAME}.{args.format}')
|
67 |
|
68 |
def download_youtube_video(url):
|
69 |
+
try:
|
70 |
+
yt = YouTube(url)
|
71 |
+
# Get stream with best resolution
|
72 |
+
video = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
|
73 |
+
if video:
|
74 |
+
# Download video
|
75 |
+
video.download(output_path=VIDEO_FOLDER, filename=f'{DOWNLOAD_VIDEO_NAME}.{DOWNLOAD_VIDEO_FORMAT}')
|
76 |
+
else:
|
77 |
+
print('No se encontr贸 un stream de video compatible')
|
78 |
+
except Exception as e:
|
79 |
+
print(f'Error descargando el video: {str(e)}')
|
80 |
|
81 |
def download_youtube_audio(url):
|
82 |
+
try:
|
83 |
+
yt = YouTube(url)
|
84 |
+
# Get stream with best quality
|
85 |
+
audio = yt.streams.filter(only_audio=True).order_by('abr').desc().first()
|
86 |
+
if audio:
|
87 |
+
# Download audio
|
88 |
+
audio.download(output_path=AUDIO_FOLDER, filename=f'{DOWNLOAD_AUDIO_NAME}.{DOWNLOAD_AUDIO_FORMAT}')
|
89 |
+
else:
|
90 |
+
print('No se encontr贸 un stream de audio compatible')
|
91 |
+
except Exception as e:
|
92 |
+
print(f'Error descargando el audio: {str(e)}')
|
93 |
|
94 |
def download_youtube(url, type):
|
95 |
if type == DOWNLOAD_VIDEO:
|