Spaces:
Running
Running
Improves the yt download reliablity
Browse files- app.py +9 -3
- download_youtube.py +53 -0
- shared/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- shared/utils/__pycache__/audio.cpython-39.pyc +0 -0
- shared/utils/__pycache__/av.cpython-39.pyc +0 -0
- shared/utils/__pycache__/image.cpython-39.pyc +0 -0
- shared/utils/__pycache__/io.cpython-39.pyc +0 -0
- shared/utils/__pycache__/keypoint_matching.cpython-39.pyc +0 -0
- shared/utils/__pycache__/log.cpython-39.pyc +0 -0
- shared/utils/__pycache__/metrics.cpython-39.pyc +0 -0
- shared/utils/__pycache__/misc.cpython-39.pyc +0 -0
- shared/utils/__pycache__/pandas_utils.cpython-39.pyc +0 -0
- shared/utils/__pycache__/paths.cpython-39.pyc +0 -0
- shared/utils/__pycache__/physics.cpython-39.pyc +0 -0
- shared/utils/__pycache__/visualize.cpython-39.pyc +0 -0
- sound_of_water/audio_pitch/__pycache__/model.cpython-39.pyc +0 -0
- sound_of_water/data/__pycache__/audio_loader.cpython-39.pyc +0 -0
- sound_of_water/data/__pycache__/audio_transforms.cpython-39.pyc +0 -0
- sound_of_water/data/__pycache__/csv_loader.cpython-39.pyc +0 -0
app.py
CHANGED
@@ -127,7 +127,7 @@ Tips to get better results:
|
|
127 |
</div>
|
128 |
</div>
|
129 |
"""
|
130 |
-
|
131 |
|
132 |
def download_from_youtube(
|
133 |
video_id,
|
@@ -188,6 +188,11 @@ def configure_input():
|
|
188 |
)
|
189 |
video_input = gr.Video(label="Upload Video", height=520)
|
190 |
youtube_link = gr.Textbox(label="YouTube Link", value=None)
|
|
|
|
|
|
|
|
|
|
|
191 |
return [video_input, youtube_link]
|
192 |
|
193 |
|
@@ -267,8 +272,9 @@ def process_input(video, youtube_link):
|
|
267 |
"YouTube Link cannot be empty if no video is provided."
|
268 |
|
269 |
video_id = get_video_id_from_url(youtube_link)
|
270 |
-
|
271 |
-
|
|
|
272 |
)
|
273 |
|
274 |
# Get predictions
|
|
|
127 |
</div>
|
128 |
</div>
|
129 |
"""
|
130 |
+
from download_youtube import download_youtube_video_ytdlp
|
131 |
|
132 |
def download_from_youtube(
|
133 |
video_id,
|
|
|
188 |
)
|
189 |
video_input = gr.Video(label="Upload Video", height=520)
|
190 |
youtube_link = gr.Textbox(label="YouTube Link", value=None)
|
191 |
+
gr.Markdown(
|
192 |
+
"Note: Often, YouTube download can fail because the video may not be public or YouTube asks for Sign in."\
|
193 |
+
"We recommend downloading the video in other ways on your machine and uploading it here."\
|
194 |
+
" Alternatively, you can clone the repository and run the demo locally which can allow for Sign-in.",
|
195 |
+
)
|
196 |
return [video_input, youtube_link]
|
197 |
|
198 |
|
|
|
272 |
"YouTube Link cannot be empty if no video is provided."
|
273 |
|
274 |
video_id = get_video_id_from_url(youtube_link)
|
275 |
+
print("Video ID:", video_id)
|
276 |
+
video_path = download_youtube_video_ytdlp(
|
277 |
+
video_id, save_dir="/tmp/",
|
278 |
)
|
279 |
|
280 |
# Get predictions
|
download_youtube.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Util functions to download videos from youtube."""
|
2 |
+
from pytube import YouTube
|
3 |
+
import yt_dlp
|
4 |
+
from glob import glob
|
5 |
+
import os
|
6 |
+
|
7 |
+
|
8 |
+
def download_youtube_video_pytube(video_id, save_path="."):
|
9 |
+
url = f"https://www.youtube.com/watch?v={video_id}"
|
10 |
+
try:
|
11 |
+
# Create a YouTube object
|
12 |
+
yt = YouTube(url)
|
13 |
+
|
14 |
+
# Select the highest resolution stream
|
15 |
+
stream = yt.streams.get_highest_resolution()
|
16 |
+
|
17 |
+
# Download the video
|
18 |
+
stream.download(output_path=save_path)
|
19 |
+
print(f"Downloaded: {yt.title}")
|
20 |
+
except Exception as e:
|
21 |
+
print(f"An error occurred: {e}")
|
22 |
+
|
23 |
+
|
24 |
+
def download_youtube_video_ytdlp(video_id, save_dir="/tmp/"):
|
25 |
+
try:
|
26 |
+
# Construct the URL using the video ID
|
27 |
+
url = f"https://www.youtube.com/watch?v={video_id}"
|
28 |
+
|
29 |
+
# yt-dlp options
|
30 |
+
ydl_opts = {
|
31 |
+
'format': 'best', # Download the best video quality
|
32 |
+
'outtmpl': f'{save_dir}/{video_id}.%(ext)s', # Save using video ID as the filename
|
33 |
+
'noprogress': True, # Suppress progress bar
|
34 |
+
}
|
35 |
+
|
36 |
+
# Download the video
|
37 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
38 |
+
ydl.download([url])
|
39 |
+
|
40 |
+
print(f"Downloaded video with ID: {video_id} to {save_dir}")
|
41 |
+
saved_path = glob(f"{save_dir}/{video_id}.*")[0]
|
42 |
+
assert os.path.exists(saved_path), f"File not found: {saved_path}"
|
43 |
+
return saved_path
|
44 |
+
except Exception as e:
|
45 |
+
print(f"An error occurred for video ID {video_id}: {e}")
|
46 |
+
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
# Example usage
|
50 |
+
# video_id = "FwZfVEuCnI4"
|
51 |
+
video_id = "PCHIWN-Wi3M"
|
52 |
+
# download_youtube_video(video_id)
|
53 |
+
download_youtube_video_ytdlp(video_id)
|
shared/utils/__pycache__/__init__.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/__init__.cpython-39.pyc and b/shared/utils/__pycache__/__init__.cpython-39.pyc differ
|
|
shared/utils/__pycache__/audio.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/audio.cpython-39.pyc and b/shared/utils/__pycache__/audio.cpython-39.pyc differ
|
|
shared/utils/__pycache__/av.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/av.cpython-39.pyc and b/shared/utils/__pycache__/av.cpython-39.pyc differ
|
|
shared/utils/__pycache__/image.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/image.cpython-39.pyc and b/shared/utils/__pycache__/image.cpython-39.pyc differ
|
|
shared/utils/__pycache__/io.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/io.cpython-39.pyc and b/shared/utils/__pycache__/io.cpython-39.pyc differ
|
|
shared/utils/__pycache__/keypoint_matching.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/keypoint_matching.cpython-39.pyc and b/shared/utils/__pycache__/keypoint_matching.cpython-39.pyc differ
|
|
shared/utils/__pycache__/log.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/log.cpython-39.pyc and b/shared/utils/__pycache__/log.cpython-39.pyc differ
|
|
shared/utils/__pycache__/metrics.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/metrics.cpython-39.pyc and b/shared/utils/__pycache__/metrics.cpython-39.pyc differ
|
|
shared/utils/__pycache__/misc.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/misc.cpython-39.pyc and b/shared/utils/__pycache__/misc.cpython-39.pyc differ
|
|
shared/utils/__pycache__/pandas_utils.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/pandas_utils.cpython-39.pyc and b/shared/utils/__pycache__/pandas_utils.cpython-39.pyc differ
|
|
shared/utils/__pycache__/paths.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/paths.cpython-39.pyc and b/shared/utils/__pycache__/paths.cpython-39.pyc differ
|
|
shared/utils/__pycache__/physics.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/physics.cpython-39.pyc and b/shared/utils/__pycache__/physics.cpython-39.pyc differ
|
|
shared/utils/__pycache__/visualize.cpython-39.pyc
CHANGED
Binary files a/shared/utils/__pycache__/visualize.cpython-39.pyc and b/shared/utils/__pycache__/visualize.cpython-39.pyc differ
|
|
sound_of_water/audio_pitch/__pycache__/model.cpython-39.pyc
CHANGED
Binary files a/sound_of_water/audio_pitch/__pycache__/model.cpython-39.pyc and b/sound_of_water/audio_pitch/__pycache__/model.cpython-39.pyc differ
|
|
sound_of_water/data/__pycache__/audio_loader.cpython-39.pyc
CHANGED
Binary files a/sound_of_water/data/__pycache__/audio_loader.cpython-39.pyc and b/sound_of_water/data/__pycache__/audio_loader.cpython-39.pyc differ
|
|
sound_of_water/data/__pycache__/audio_transforms.cpython-39.pyc
CHANGED
Binary files a/sound_of_water/data/__pycache__/audio_transforms.cpython-39.pyc and b/sound_of_water/data/__pycache__/audio_transforms.cpython-39.pyc differ
|
|
sound_of_water/data/__pycache__/csv_loader.cpython-39.pyc
CHANGED
Binary files a/sound_of_water/data/__pycache__/csv_loader.cpython-39.pyc and b/sound_of_water/data/__pycache__/csv_loader.cpython-39.pyc differ
|
|