Update app.py
Browse files
app.py
CHANGED
@@ -251,39 +251,34 @@ async def get_track_download_url(video_url: str) -> str:
|
|
251 |
|
252 |
|
253 |
|
|
|
254 |
async def process_url(video_url: str) -> str:
|
255 |
try:
|
256 |
-
# Step 1: Download the URL
|
257 |
api_url = "https://www.saveporn.net/convert/"
|
258 |
-
session = cloudscraper.create_scraper()
|
259 |
form_data = {"url": video_url}
|
260 |
-
response = session.post(video_url, data=form_data)
|
261 |
-
response_text = response.text
|
262 |
-
logger.info(response_text)
|
263 |
-
|
264 |
-
# Step 2: Get HTML from rich text (in this simple case, just use the response text)
|
265 |
-
html_text = response_text
|
266 |
-
|
267 |
-
# Step 3: Match text for <tr> tags
|
268 |
-
tr_matches = re.findall(r'<tr>(.*?)</tr>', html_text)
|
269 |
-
|
270 |
-
repeat_results = []
|
271 |
-
for tr_match in tr_matches:
|
272 |
-
# Step 4: Match text for <td> tags with 3 - 4 digit numbers
|
273 |
-
td_matches = re.findall(r'<td>(\d{3,4})</td>', tr_match)
|
274 |
-
quality = td_matches[0] if td_matches else None
|
275 |
-
|
276 |
-
|
277 |
-
# Step 7: Count the repeat results
|
278 |
-
result_count = len(repeat_results)
|
279 |
-
|
280 |
|
281 |
-
|
282 |
-
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
except Exception as e:
|
285 |
-
|
286 |
-
return []
|
287 |
|
288 |
|
289 |
|
|
|
251 |
|
252 |
|
253 |
|
254 |
+
|
255 |
async def process_url(video_url: str) -> str:
|
256 |
try:
|
|
|
257 |
api_url = "https://www.saveporn.net/convert/"
|
|
|
258 |
form_data = {"url": video_url}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
+
async with httpx.AsyncClient() as client:
|
261 |
+
response = await client.post(
|
262 |
+
api_url,
|
263 |
+
data=form_data,
|
264 |
+
timeout=30.0 # 30 seconds timeout
|
265 |
+
)
|
266 |
+
|
267 |
+
response.raise_for_status()
|
268 |
+
|
269 |
+
# Optional: Validate response format
|
270 |
+
result = response.text
|
271 |
+
if not result:
|
272 |
+
raise ValueError("Empty response received")
|
273 |
+
|
274 |
+
return result
|
275 |
+
|
276 |
+
except httpx.TimeoutException:
|
277 |
+
raise Exception("Request timed out")
|
278 |
+
except httpx.HTTPStatusError as e:
|
279 |
+
raise Exception(f"HTTP error occurred: {e.response.status_code}")
|
280 |
except Exception as e:
|
281 |
+
raise Exception(f"An unexpected error occurred: {str(e)}")
|
|
|
282 |
|
283 |
|
284 |
|