Chrunos commited on
Commit
cbd5822
·
verified ·
1 Parent(s): b860942

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -30,6 +30,7 @@ import re
30
  import asyncio
31
  import cloudscraper
32
  import httpx
 
33
 
34
  tmp_dir = tempfile.gettempdir()
35
  BASE_URL = "https://chrunos-zam.hf.space"
@@ -265,8 +266,20 @@ async def process_url(title: str) -> str:
265
 
266
  # Check if the request was successful
267
  response.raise_for_status()
268
-
269
- return response.text
 
 
 
 
 
 
 
 
 
 
 
 
270
  except requests.exceptions.RequestException as e:
271
  # Handle network-related errors
272
  raise Exception(f"Failed to process URL: {str(e)}")
 
30
  import asyncio
31
  import cloudscraper
32
  import httpx
33
+ from bs4 import BeautifulSoup
34
 
35
  tmp_dir = tempfile.gettempdir()
36
  BASE_URL = "https://chrunos-zam.hf.space"
 
266
 
267
  # Check if the request was successful
268
  response.raise_for_status()
269
+ soup = BeautifulSoup(response, 'html.parser')
270
+ table = soup.find('table')
271
+ data = []
272
+ if table:
273
+ rows = table.find_all('tr')
274
+ for row in rows:
275
+ cols = row.find_all('td')
276
+ row_data = {
277
+ "quality": cols[0].get_text() if len(cols) > 0 else "",
278
+ "format": cols[1].get_text() if len(cols) > 1 else "",
279
+ "download_link": cols[2].find('a')['href'] if len(cols) > 2 and cols[2].find('a') else ""
280
+ }
281
+ data.append(row_data)
282
+ return json.dumps(data)
283
  except requests.exceptions.RequestException as e:
284
  # Handle network-related errors
285
  raise Exception(f"Failed to process URL: {str(e)}")