Spaces:
Runtime error
Runtime error
switch-to-yt-dlp-for-faster-dl (#3)
Browse files- switch-to-yt-dlp-for-faster-dl (f6e845c6efb89ae69c9360404c976107fa7b3ed4)
Co-authored-by: Ernie Chu <[email protected]>
- app.py +4 -4
- requirements.txt +2 -2
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import torch
|
2 |
import clip
|
3 |
-
import cv2,
|
4 |
from PIL import Image,ImageDraw, ImageFont
|
5 |
import os
|
6 |
from functools import partial
|
@@ -20,7 +20,7 @@ model, preprocess = clip.load("ViT-B/32")
|
|
20 |
def select_video_format(url, ydl_opts={}, format_note='240p', ext='mp4', max_size = 500000000):
|
21 |
defaults = ['480p', '360p','240p','144p']
|
22 |
ydl_opts = ydl_opts
|
23 |
-
ydl =
|
24 |
info_dict = ydl.extract_info(url, download=False)
|
25 |
formats = info_dict.get('formats', None)
|
26 |
# filter out formats we can't process
|
@@ -61,12 +61,12 @@ def download_video(url):
|
|
61 |
'format':format_id,
|
62 |
'outtmpl': "videos/%(id)s.%(ext)s"}
|
63 |
|
64 |
-
with
|
65 |
try:
|
66 |
ydl.cache.remove()
|
67 |
meta = ydl.extract_info(url)
|
68 |
save_location = 'videos/' + meta['id'] + '.' + meta['ext']
|
69 |
-
except
|
70 |
print(f'error with download_video function: {error}')
|
71 |
save_location = None
|
72 |
except IndexError as err:
|
|
|
1 |
import torch
|
2 |
import clip
|
3 |
+
import cv2, yt_dlp
|
4 |
from PIL import Image,ImageDraw, ImageFont
|
5 |
import os
|
6 |
from functools import partial
|
|
|
20 |
def select_video_format(url, ydl_opts={}, format_note='240p', ext='mp4', max_size = 500000000):
|
21 |
defaults = ['480p', '360p','240p','144p']
|
22 |
ydl_opts = ydl_opts
|
23 |
+
ydl = yt_dlp.YoutubeDL(ydl_opts)
|
24 |
info_dict = ydl.extract_info(url, download=False)
|
25 |
formats = info_dict.get('formats', None)
|
26 |
# filter out formats we can't process
|
|
|
61 |
'format':format_id,
|
62 |
'outtmpl': "videos/%(id)s.%(ext)s"}
|
63 |
|
64 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
65 |
try:
|
66 |
ydl.cache.remove()
|
67 |
meta = ydl.extract_info(url)
|
68 |
save_location = 'videos/' + meta['id'] + '.' + meta['ext']
|
69 |
+
except yt_dlp.DownloadError as error:
|
70 |
print(f'error with download_video function: {error}')
|
71 |
save_location = None
|
72 |
except IndexError as err:
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
git+https://github.com/openai/CLIP.git
|
2 |
torch
|
3 |
-
|
4 |
-
opencv-python-headless
|
|
|
1 |
git+https://github.com/openai/CLIP.git
|
2 |
torch
|
3 |
+
yt_dlp
|
4 |
+
opencv-python-headless
|