Update app.py
Browse files
app.py
CHANGED
|
@@ -187,8 +187,14 @@ async def download_high_quality_video(request: Request):
|
|
| 187 |
async def download_high_quality_video(request: Request):
|
| 188 |
data = await request.json()
|
| 189 |
video_url = data.get('url')
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
cookiefile = "firefox-cookies.txt"
|
| 193 |
env_to_cookies_from_env("firefox-cookies.txt")
|
| 194 |
|
|
@@ -199,15 +205,12 @@ async def download_high_quality_video(request: Request):
|
|
| 199 |
height_map = {
|
| 200 |
'480': 480,
|
| 201 |
'720': 720,
|
| 202 |
-
'1080': 1080
|
| 203 |
-
'1440': 1440,
|
| 204 |
-
'2160': 2160
|
| 205 |
}
|
| 206 |
-
max_height = height_map.get(quality, 1080)
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
format_str = f'bestvideo[height<={max_height}][vcodec^=avc]+bestaudio/best'
|
| 211 |
|
| 212 |
ydl_opts = {
|
| 213 |
'format': format_str,
|
|
@@ -230,6 +233,7 @@ async def download_high_quality_video(request: Request):
|
|
| 230 |
download_url = f"{BASE_URL}/file/{encoded_filename}"
|
| 231 |
return {"url": download_url}
|
| 232 |
|
|
|
|
| 233 |
@app.post("/audio")
|
| 234 |
async def download_audio(request: Request):
|
| 235 |
data = await request.json()
|
|
|
|
| 187 |
async def download_high_quality_video(request: Request):
|
| 188 |
data = await request.json()
|
| 189 |
video_url = data.get('url')
|
| 190 |
+
quality = data.get('quality', '1080') # Default to 1080p if not specified
|
| 191 |
+
|
| 192 |
+
# Check if the requested quality is above 1080p
|
| 193 |
+
if int(quality) > 1080:
|
| 194 |
+
error_message = "Quality above 1080p is for premium users. Please check the URL for more information."
|
| 195 |
+
help_url = "https://chrunos.com/premium-shortcuts/" # Replace with your actual URL
|
| 196 |
+
return {"error": error_message, "url": help_url}
|
| 197 |
+
|
| 198 |
cookiefile = "firefox-cookies.txt"
|
| 199 |
env_to_cookies_from_env("firefox-cookies.txt")
|
| 200 |
|
|
|
|
| 205 |
height_map = {
|
| 206 |
'480': 480,
|
| 207 |
'720': 720,
|
| 208 |
+
'1080': 1080
|
|
|
|
|
|
|
| 209 |
}
|
| 210 |
+
max_height = height_map.get(quality, 1080) # Use the quality variable correctly
|
| 211 |
+
|
| 212 |
+
# Determine format string based on quality
|
| 213 |
+
format_str = f'bestvideo[height<={max_height}][vcodec^=avc]+bestaudio/best'
|
|
|
|
| 214 |
|
| 215 |
ydl_opts = {
|
| 216 |
'format': format_str,
|
|
|
|
| 233 |
download_url = f"{BASE_URL}/file/{encoded_filename}"
|
| 234 |
return {"url": download_url}
|
| 235 |
|
| 236 |
+
|
| 237 |
@app.post("/audio")
|
| 238 |
async def download_audio(request: Request):
|
| 239 |
data = await request.json()
|