tecuts commited on
Commit
3652f49
·
verified ·
1 Parent(s): d6c33a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -550,6 +550,30 @@ def get_youtube_download_url_from_apis(video_url: str) -> str:
550
  logger.info("Both APIs failed to retrieve a download URL.")
551
  return None
552
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
553
  @app.post("/multi")
554
  async def multi_download(request: Request):
555
  user_ip = get_user_ip(request)
@@ -593,9 +617,11 @@ async def multi_download(request: Request):
593
  error_message = "Quality above 720p is for Premium Members Only. Please check the URL for more information."
594
  help_url = "https://chrunos.com/premium-shortcuts/" # Replace with your actual URL
595
  return {"error": error_message, "url": help_url}
596
-
597
 
598
  is_youtube_url = re.search(r'(youtube\.com|youtu\.be)', video_url) is not None
 
 
599
 
600
  if is_youtube_url:
601
  dl_url = get_youtube_download_url_from_apis(video_url)
 
550
  logger.info("Both APIs failed to retrieve a download URL.")
551
  return None
552
 
553
+ reads_api = "https://chrunos-reads.hf.space"
554
+ def call_extract_endpoint(post_url: str) -> Dict[str, Any]:
555
+
556
+ try:
557
+ response = requests.get(f"{reads_api}/extract", params={"url": post_url})
558
+ response.raise_for_status()
559
+ return response.json()
560
+ except requests.RequestException as e:
561
+ raise requests.RequestException(f"Failed to call extract endpoint: {str(e)}")
562
+ except ValueError as e:
563
+ raise ValueError(f"Invalid response format: {str(e)}")
564
+
565
+
566
+ def is_threads_url(url: str) -> bool:
567
+ """Check if URL is a Threads URL"""
568
+ try:
569
+ parsed = urlparse(url)
570
+ return (
571
+ parsed.netloc in ['threads.net', 'www.threads.net', 'threads.com', 'www.threads.com'] and
572
+ (('/post/' in parsed.path) or ('/t/' in parsed.path))
573
+ )
574
+ except:
575
+ return False
576
+
577
  @app.post("/multi")
578
  async def multi_download(request: Request):
579
  user_ip = get_user_ip(request)
 
617
  error_message = "Quality above 720p is for Premium Members Only. Please check the URL for more information."
618
  help_url = "https://chrunos.com/premium-shortcuts/" # Replace with your actual URL
619
  return {"error": error_message, "url": help_url}
620
+ if video_url
621
 
622
  is_youtube_url = re.search(r'(youtube\.com|youtu\.be)', video_url) is not None
623
+ if is_threads_url(video_url):
624
+ return call_extract_endpoint(video_url)
625
 
626
  if is_youtube_url:
627
  dl_url = get_youtube_download_url_from_apis(video_url)