Update app.py
Browse files
app.py
CHANGED
@@ -248,6 +248,56 @@ async def get_track_download_url(video_url: str) -> str:
|
|
248 |
return {"error": "Download URL not found"}
|
249 |
|
250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
async def extract_video_info(video_url: str) -> str:
|
252 |
api_url = f'https://yt-dl-web.vercel.app/api/info?url={video_url}'
|
253 |
session = cloudscraper.create_scraper()
|
@@ -282,7 +332,7 @@ async def extract_video_info(video_url: str) -> str:
|
|
282 |
async def test_download(request: Request):
|
283 |
data = await request.json()
|
284 |
video_url = data.get('url')
|
285 |
-
response = await
|
286 |
return response
|
287 |
|
288 |
|
|
|
248 |
return {"error": "Download URL not found"}
|
249 |
|
250 |
|
251 |
+
|
252 |
+
import requests
|
253 |
+
import re
|
254 |
+
|
255 |
+
|
256 |
+
def process_url(video_url: str) -> str:
|
257 |
+
try:
|
258 |
+
# Step 1: Download the URL
|
259 |
+
api_url = "https://www.saveporn.net/convert/"
|
260 |
+
session = cloudscraper.create_scraper()
|
261 |
+
form_data = {"url": video_url}
|
262 |
+
response = session.post(video_url, data=form_data)
|
263 |
+
response_text = response.text
|
264 |
+
|
265 |
+
# Step 2: Get HTML from rich text (in this simple case, just use the response text)
|
266 |
+
html_text = response_text
|
267 |
+
|
268 |
+
# Step 3: Match text for <tr> tags
|
269 |
+
tr_matches = re.findall(r'<tr>(.*?)</tr>', html_text)
|
270 |
+
|
271 |
+
repeat_results = []
|
272 |
+
for tr_match in tr_matches:
|
273 |
+
# Step 4: Match text for <td> tags with 3 - 4 digit numbers
|
274 |
+
td_matches = re.findall(r'<td>(\d{3,4})</td>', tr_match)
|
275 |
+
quality = td_matches[0] if td_matches else None
|
276 |
+
if quality:
|
277 |
+
# Step 5: Get URLs from the current <tr> match
|
278 |
+
urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
|
279 |
+
tr_match)
|
280 |
+
# Step 6: Set name for the URLs
|
281 |
+
named_urls = [(url, f"{quality}P - MP4") for url in urls]
|
282 |
+
repeat_results.extend(named_urls)
|
283 |
+
|
284 |
+
# Step 7: Count the repeat results
|
285 |
+
result_count = len(repeat_results)
|
286 |
+
|
287 |
+
if result_count < 1:
|
288 |
+
print("Error: No results found.")
|
289 |
+
return
|
290 |
+
|
291 |
+
return repeat_results
|
292 |
+
|
293 |
+
except Exception as e:
|
294 |
+
print(f"An error occurred: {e}")
|
295 |
+
return []
|
296 |
+
|
297 |
+
|
298 |
+
|
299 |
+
|
300 |
+
|
301 |
async def extract_video_info(video_url: str) -> str:
|
302 |
api_url = f'https://yt-dl-web.vercel.app/api/info?url={video_url}'
|
303 |
session = cloudscraper.create_scraper()
|
|
|
332 |
async def test_download(request: Request):
|
333 |
data = await request.json()
|
334 |
video_url = data.get('url')
|
335 |
+
response = await process_url(video_url)
|
336 |
return response
|
337 |
|
338 |
|