Chrunos commited on
Commit
2bae5b1
·
verified ·
1 Parent(s): 59df0e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
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
- # Get quality from request, default to 1080p if not specified
191
- quality = data.get('quality', '1080') # Can be '480', '720', '1080', '1440', '2160' (4K)
 
 
 
 
 
 
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
- if max_height > 1080:
208
- format_str = f'bestvideo[height<={max_height}]+bestaudio/best'
209
- else:
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()