Spaces:
Runtime error
Runtime error
ernestchu
commited on
Commit
·
a6d9cb2
1
Parent(s):
ee03285
switch-to-yt-dlp
Browse files- app.py +4 -4
- requirements.txt +1 -1
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 wget
|
6 |
import os
|
@@ -21,7 +21,7 @@ model, preprocess = clip.load("ViT-B/32")
|
|
21 |
def select_video_format(url, ydl_opts={}, format_note='240p', ext='mp4', max_size = 500000000):
|
22 |
defaults = ['480p', '360p','240p','144p']
|
23 |
ydl_opts = ydl_opts
|
24 |
-
ydl =
|
25 |
info_dict = ydl.extract_info(url, download=False)
|
26 |
formats = info_dict.get('formats', None)
|
27 |
# filter out formats we can't process
|
@@ -62,7 +62,7 @@ def download_video(url):
|
|
62 |
'format':format_id,
|
63 |
'outtmpl': "videos/%(id)s.%(ext)s"}
|
64 |
|
65 |
-
with
|
66 |
try:
|
67 |
ydl.cache.remove()
|
68 |
meta = ydl.extract_info(url)
|
@@ -71,7 +71,7 @@ def download_video(url):
|
|
71 |
thumb_location = f"videos/{meta['id']}.{thumb_url.split('.')[-1]}"
|
72 |
wget.download(thumb_url, out=thumb_location)
|
73 |
save_location = 'videos/' + meta['id'] + '.' + meta['ext']
|
74 |
-
except
|
75 |
print(f'error with download_video function: {error}')
|
76 |
save_location = None
|
77 |
thumb_location = None
|
|
|
1 |
import torch
|
2 |
import clip
|
3 |
+
import cv2, yt_dlp
|
4 |
from PIL import Image,ImageDraw, ImageFont
|
5 |
import wget
|
6 |
import os
|
|
|
21 |
def select_video_format(url, ydl_opts={}, format_note='240p', ext='mp4', max_size = 500000000):
|
22 |
defaults = ['480p', '360p','240p','144p']
|
23 |
ydl_opts = ydl_opts
|
24 |
+
ydl = yt_dlp.YoutubeDL(ydl_opts)
|
25 |
info_dict = ydl.extract_info(url, download=False)
|
26 |
formats = info_dict.get('formats', None)
|
27 |
# filter out formats we can't process
|
|
|
62 |
'format':format_id,
|
63 |
'outtmpl': "videos/%(id)s.%(ext)s"}
|
64 |
|
65 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
66 |
try:
|
67 |
ydl.cache.remove()
|
68 |
meta = ydl.extract_info(url)
|
|
|
71 |
thumb_location = f"videos/{meta['id']}.{thumb_url.split('.')[-1]}"
|
72 |
wget.download(thumb_url, out=thumb_location)
|
73 |
save_location = 'videos/' + meta['id'] + '.' + meta['ext']
|
74 |
+
except yt_dlp.DownloadError as error:
|
75 |
print(f'error with download_video function: {error}')
|
76 |
save_location = None
|
77 |
thumb_location = None
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
git+https://github.com/openai/CLIP.git
|
2 |
torch
|
3 |
-
|
4 |
opencv-python-headless
|
5 |
wget
|
|
|
1 |
git+https://github.com/openai/CLIP.git
|
2 |
torch
|
3 |
+
yt-dlp
|
4 |
opencv-python-headless
|
5 |
wget
|