Update app.py
Browse files
app.py
CHANGED
|
@@ -385,81 +385,58 @@ async def jio_download(request: JioDownloadRequest):
|
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
# Step 1: Download the URL
|
| 391 |
-
api_url = f"https://www.saveporn.net/download/{title}/"
|
| 392 |
-
session = cloudscraper.create_scraper()
|
| 393 |
-
|
| 394 |
-
# Use the correct API endpoint
|
| 395 |
-
response = session.get(api_url)
|
| 396 |
-
logger.info(response)
|
| 397 |
-
|
| 398 |
-
# Check if the request was successful
|
| 399 |
-
response.raise_for_status()
|
| 400 |
-
soup = BeautifulSoup(response.text, 'html.parser')
|
| 401 |
-
table = soup.find('table')
|
| 402 |
-
data = []
|
| 403 |
-
if table:
|
| 404 |
-
rows = table.find_all('tr')
|
| 405 |
-
for row in rows:
|
| 406 |
-
cols = row.find_all('td')
|
| 407 |
-
row_data = {
|
| 408 |
-
"format_id": cols[0].get_text() if len(cols) > 0 else "",
|
| 409 |
-
"format": cols[1].get_text() if len(cols) > 1 else "",
|
| 410 |
-
"url": cols[2].find('a')['href'] if len(cols) > 2 and cols[2].find('a') else ""
|
| 411 |
-
}
|
| 412 |
-
data.append(row_data)
|
| 413 |
-
return data
|
| 414 |
-
except requests.exceptions.RequestException as e:
|
| 415 |
-
# Handle network-related errors
|
| 416 |
-
raise Exception(f"Failed to process URL: {str(e)}")
|
| 417 |
-
except Exception as e:
|
| 418 |
-
# Handle any other unexpected errors
|
| 419 |
-
raise Exception(f"An unexpected error occurred: {str(e)}")
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
EXTRACT_API = os.getenv("EXTRACT_API")
|
|
|
|
|
|
|
| 425 |
|
| 426 |
def extract_video_info(video_url: str) -> str:
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
else:
|
| 454 |
-
|
| 455 |
-
return new_result
|
| 456 |
else:
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
logger.error(f"An error occurred: {e}")
|
| 462 |
-
return {"error": str(e)}
|
| 463 |
|
| 464 |
|
| 465 |
@app.post("/test")
|
|
|
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
+
|
| 389 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
EXTRACT_API = os.getenv("EXTRACT_API")
|
| 395 |
+
ALT_API = os.getenv("ALT_API")
|
| 396 |
+
|
| 397 |
|
| 398 |
def extract_video_info(video_url: str) -> str:
|
| 399 |
+
api_urls = [f'{EXTRACT_API}?url={video_url}', f'{ALT_API}?url={video_url}']
|
| 400 |
+
for api_url in api_urls:
|
| 401 |
+
logger.info(api_url)
|
| 402 |
+
session = cloudscraper.create_scraper()
|
| 403 |
+
try:
|
| 404 |
+
response = session.get(api_url, timeout=20)
|
| 405 |
+
|
| 406 |
+
if response.status_code == 200:
|
| 407 |
+
json_response = response.json()
|
| 408 |
+
result = []
|
| 409 |
+
if 'formats' in json_response:
|
| 410 |
+
for format_item in json_response['formats']:
|
| 411 |
+
format_url = format_item.get('url')
|
| 412 |
+
format_id = format_item.get('format_id')
|
| 413 |
+
p_cookies = format_item.get('cookies')
|
| 414 |
+
if format_id and format_url:
|
| 415 |
+
result.append({
|
| 416 |
+
"url": format_url,
|
| 417 |
+
"format_id": format_id,
|
| 418 |
+
"cookies": p_cookies
|
| 419 |
+
})
|
| 420 |
+
title = json_response.get('title')
|
| 421 |
+
logger.info(title)
|
| 422 |
+
if "pornhub.com" in video_url:
|
| 423 |
+
p_result = [item for item in result if 'hls' in item['format_id']]
|
| 424 |
+
return p_result
|
| 425 |
+
else:
|
| 426 |
+
if len(result) == 1:
|
| 427 |
+
new_item = {
|
| 428 |
+
"format_id": "This is Fake, Don't Choose This One",
|
| 429 |
+
"url": "none"
|
| 430 |
+
}
|
| 431 |
+
result.append(new_item)
|
| 432 |
+
return result
|
| 433 |
else:
|
| 434 |
+
return {"error": "No formats available"}
|
|
|
|
| 435 |
else:
|
| 436 |
+
logger.warning(f"Request failed with status code {response.status_code}, API: {api_url}")
|
| 437 |
+
except Exception as e:
|
| 438 |
+
logger.error(f"An error occurred: {e}")
|
| 439 |
+
return {"error": "Both APIs failed to provide valid results."}
|
|
|
|
|
|
|
| 440 |
|
| 441 |
|
| 442 |
@app.post("/test")
|