-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathver.txt
69 lines (61 loc) · 2.79 KB
/
ver.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from fastapi import FastAPI, Request, HTTPException
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
import requests
from bs4 import BeautifulSoup
import time
import random
app = FastAPI()
# CORS middleware configuration remains same
# Define headers that make the request look more like a regular browser
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
}
def fetch_movie_details(url, base_url):
try:
# Add a small random delay
time.sleep(random.uniform(1, 3))
response = requests.get(base_url + url, headers=headers, timeout=10)
response.raise_for_status()
soup = BeautifulSoup(response.content, 'html.parser')
download_links_container = soup.find("div", class_="dlbtn")
if download_links_container:
download_link_element = download_links_container.find("a", class_="dl")
if download_link_element:
download_link = download_link_element["href"]
return {"download_link": download_link}
except requests.exceptions.RequestException as e:
print(f"Error fetching page: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
return None
@app.get("/search_movie")
async def search_movie(query: str):
url = f"https://filmyfly.capetown/site-1.html?to-search={query}"
try:
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
soup = BeautifulSoup(response.content, "html.parser")
movie_containers = soup.find_all("div", class_="A2")
for container in movie_containers:
try:
link_element = container.find("a")
link = link_element["href"]
download_link = fetch_movie_details(link, "https://filmyfly.capetown/")
if download_link:
return JSONResponse(content=download_link)
except AttributeError as e:
print(f"Error parsing movie container: {e}")
continue
return JSONResponse(content={"message": "No results found."}, status_code=404)
except requests.exceptions.RequestException as e:
return JSONResponse(content={"error": f"Request failed: {e}"}, status_code=500)
except Exception as e:
return JSONResponse(content={"error": f"An unexpected error occurred: {e}"}, status_code=500)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)