Spaces:
Runtime error
Runtime error
Update server.py
Browse files
server.py
CHANGED
|
@@ -5,6 +5,29 @@ import json
|
|
| 5 |
import base64
|
| 6 |
import os
|
| 7 |
os.system("pip install yt-dlp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import re
|
| 9 |
import logging
|
| 10 |
from typing import Union
|
|
|
|
| 5 |
import base64
|
| 6 |
import os
|
| 7 |
os.system("pip install yt-dlp")
|
| 8 |
+
import yt_dlp
|
| 9 |
+
import os
|
| 10 |
+
|
| 11 |
+
def download_video_with_cookies(video_url, cookies_path):
|
| 12 |
+
# Define options for yt-dlp
|
| 13 |
+
ydl_opts = {
|
| 14 |
+
'cookies': cookies_path, # Path to the cookies file
|
| 15 |
+
'outtmpl': 'downloads/%(title)s.%(ext)s', # Define the output file template
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Using yt-dlp to download the video
|
| 19 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 20 |
+
ydl.download([video_url]) # Downloads the video
|
| 21 |
+
|
| 22 |
+
# Path to the cookies.txt file in your Hugging Face Space
|
| 23 |
+
cookies_file = '/mnt/data/cookies.txt' # You will need to upload the cookies.txt file here
|
| 24 |
+
|
| 25 |
+
# Example video URL
|
| 26 |
+
video_url = 'https://www.youtube.com/watch?v=kffacxfA7G4' # Replace with the desired YouTube video URL
|
| 27 |
+
|
| 28 |
+
# Call the download function
|
| 29 |
+
download_video_with_cookies(video_url, cookies_file)
|
| 30 |
+
|
| 31 |
import re
|
| 32 |
import logging
|
| 33 |
from typing import Union
|