Spaces:
Runtime error
Runtime error
FB API
Browse files- Dockerfile +11 -0
- main.py +82 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from characterai import PyCAI as AnotherAPI
|
3 |
+
import requests
|
4 |
+
import re
|
5 |
+
import json
|
6 |
+
import logging
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
class VideoLinkExtractor:
|
11 |
+
"""Class for extracting video links from HTML content."""
|
12 |
+
|
13 |
+
def __init__(self, html_content):
|
14 |
+
self.html_content = html_content
|
15 |
+
|
16 |
+
def clean_str(self, s):
|
17 |
+
"""Cleans and returns a JSON-encoded string."""
|
18 |
+
try:
|
19 |
+
return json.loads(f'{{"text": "{s}"}}')['text']
|
20 |
+
except json.JSONDecodeError as e:
|
21 |
+
logging.error(f"Error decoding JSON: {e}")
|
22 |
+
return None
|
23 |
+
|
24 |
+
def get_link(self, regex):
|
25 |
+
"""Extracts and returns link based on the provided regex."""
|
26 |
+
match = re.search(regex, self.html_content)
|
27 |
+
return self.clean_str(match.group(1)) if match else None
|
28 |
+
|
29 |
+
def get_title(self):
|
30 |
+
"""Extracts and returns the title from HTML content."""
|
31 |
+
return self.get_link(r'<title>(.*?)<\/title>')
|
32 |
+
|
33 |
+
@app.get("/AnotherAPI/{api_key}/FB_Downloader/")
|
34 |
+
async def get_video_links(url: str, api_key: str,):
|
35 |
+
API = AnotherAPI(api_key)
|
36 |
+
API.chat.new_chat('csTC3hw0Fnj1Whnl0uV1Nb3_oYIillMQtdBH5NEl0Gs')
|
37 |
+
if not url:
|
38 |
+
return {"success": False, "message": "Please provide the URL"}
|
39 |
+
|
40 |
+
headers = {
|
41 |
+
'sec-fetch-user': '?1',
|
42 |
+
'sec-ch-ua-mobile': '?0',
|
43 |
+
'sec-fetch-site': 'none',
|
44 |
+
'sec-fetch-dest': 'document',
|
45 |
+
'sec-fetch-mode': 'navigate',
|
46 |
+
'cache-control': 'max-age=0',
|
47 |
+
'authority': 'www.facebook.com',
|
48 |
+
'upgrade-insecure-requests': '1',
|
49 |
+
'accept-language': 'en-GB,en;q=0.9,tr-TR;q=0.8,tr;q=0.7,en-US;q=0.6',
|
50 |
+
'sec-ch-ua': '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',
|
51 |
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36',
|
52 |
+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
|
53 |
+
}
|
54 |
+
|
55 |
+
try:
|
56 |
+
r = requests.get(url, headers=headers)
|
57 |
+
r.raise_for_status()
|
58 |
+
extractor = VideoLinkExtractor(r.text)
|
59 |
+
|
60 |
+
data = {
|
61 |
+
"success": True,
|
62 |
+
"title": extractor.get_title(),
|
63 |
+
"links": {}
|
64 |
+
}
|
65 |
+
|
66 |
+
sd_link = extractor.get_link(r'browser_native_sd_url":"([^"]+)"')
|
67 |
+
if sd_link:
|
68 |
+
data["links"]["Download Low Quality"] = sd_link + "&dl=1"
|
69 |
+
|
70 |
+
hd_link = extractor.get_link(r'browser_native_hd_url":"([^"]+)"')
|
71 |
+
if hd_link:
|
72 |
+
data["links"]["Download High Quality"] = hd_link + "&dl=1"
|
73 |
+
|
74 |
+
return data
|
75 |
+
|
76 |
+
except requests.RequestException as e:
|
77 |
+
logging.error(f"Request failed: {e}")
|
78 |
+
return {"success": False, "message": str(e)}
|
79 |
+
|
80 |
+
if __name__ == "__main__":
|
81 |
+
import uvicorn
|
82 |
+
uvicorn.run(app, host="127.0.0.1", port=8100)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
characterai
|
4 |
+
g4f
|