Spaces:
Build error
Build error
Delete youtube_video.py
Browse files- youtube_video.py +0 -34
youtube_video.py
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
import pytube
|
| 2 |
-
import os
|
| 3 |
-
from pytube import YouTube
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def download_youtube_video(youtube_url):
|
| 7 |
-
"""Downloads a YouTube video, renames it to the first three characters, and returns the downloaded file path."""
|
| 8 |
-
|
| 9 |
-
try:
|
| 10 |
-
# Create a YouTube object
|
| 11 |
-
yt = pytube.YouTube(youtube_url)
|
| 12 |
-
|
| 13 |
-
# Get the highest resolution progressive stream
|
| 14 |
-
video = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
|
| 15 |
-
|
| 16 |
-
# Download the video
|
| 17 |
-
print("Downloading...")
|
| 18 |
-
video.download()
|
| 19 |
-
|
| 20 |
-
# Get the original filename
|
| 21 |
-
original_filename = video.default_filename
|
| 22 |
-
|
| 23 |
-
# Extract the first three characters and keep the file extension
|
| 24 |
-
new_filename = original_filename[:12] + os.path.splitext(original_filename)[1]
|
| 25 |
-
|
| 26 |
-
# Rename the downloaded file
|
| 27 |
-
os.rename(original_filename, new_filename)
|
| 28 |
-
|
| 29 |
-
print("Download complete! Video saved to:", new_filename)
|
| 30 |
-
return new_filename
|
| 31 |
-
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print("An error occurred:", e)
|
| 34 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|