Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
-
from fastapi import FastAPI, Request, Response
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
-
from fastapi
|
|
|
|
|
|
|
| 5 |
import requests
|
| 6 |
import canais
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
templates = Jinja2Templates(directory="templates")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
MANIFEST = {
|
| 13 |
"id": "com.skyflix",
|
| 14 |
"version": "1.0.0",
|
|
@@ -26,37 +39,169 @@ MANIFEST = {
|
|
| 26 |
{
|
| 27 |
"name": "genre",
|
| 28 |
"options": [
|
| 29 |
-
"Canais Abertos",
|
| 30 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
],
|
| 32 |
"isRequired": False
|
| 33 |
}
|
| 34 |
]
|
| 35 |
},
|
| 36 |
-
{
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
],
|
| 39 |
"idPrefixes": ["skyflix", "tt"]
|
| 40 |
}
|
| 41 |
|
| 42 |
-
|
|
|
|
| 43 |
async def home(request: Request):
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
async def manifest():
|
| 48 |
return JSONResponse(content=MANIFEST)
|
| 49 |
|
| 50 |
-
@
|
| 51 |
-
async def
|
| 52 |
host = request.client.host
|
| 53 |
-
server = f'https://{host}/logo?url=' if 'localhost'
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
if type == 'tv':
|
| 56 |
canais_ = []
|
| 57 |
list_canais = canais.canais_list(server)
|
| 58 |
for canal in list_canais:
|
| 59 |
-
canal.pop('streams'
|
| 60 |
canais_.append(canal)
|
| 61 |
-
return JSONResponse(content={"metas": canais_})
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
|
|
|
| 2 |
from fastapi.responses import JSONResponse
|
| 3 |
+
from fastapi import Request, Response
|
| 4 |
+
from fastapi.templating import Jinja2Templates # Added for rendering HTML templates
|
| 5 |
+
import json
|
| 6 |
import requests
|
| 7 |
import canais
|
| 8 |
+
import os
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
|
| 11 |
+
load_dotenv()
|
| 12 |
|
| 13 |
+
app_ = FastAPI()
|
| 14 |
+
|
| 15 |
+
# Initialize Jinja2Templates for HTML rendering
|
| 16 |
templates = Jinja2Templates(directory="templates")
|
| 17 |
|
| 18 |
+
# Function to add CORS headers
|
| 19 |
+
def add_cors_headers(response: Response):
|
| 20 |
+
response.headers['Access-Control-Allow-Origin'] = '*' # Allow all domains
|
| 21 |
+
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS' # Allowed methods
|
| 22 |
+
response.headers['Access-Control-Allow-Headers'] = 'Content-Type' # Allowed headers
|
| 23 |
+
return response
|
| 24 |
+
|
| 25 |
MANIFEST = {
|
| 26 |
"id": "com.skyflix",
|
| 27 |
"version": "1.0.0",
|
|
|
|
| 39 |
{
|
| 40 |
"name": "genre",
|
| 41 |
"options": [
|
| 42 |
+
"Canais Abertos",
|
| 43 |
+
"Variedades",
|
| 44 |
+
"Filmes e Series",
|
| 45 |
+
"Documentarios",
|
| 46 |
+
"Esportes",
|
| 47 |
+
"Infantil",
|
| 48 |
+
"Noticias",
|
| 49 |
+
"PLUTO TV",
|
| 50 |
+
"CANAL 24H"
|
| 51 |
],
|
| 52 |
"isRequired": False
|
| 53 |
}
|
| 54 |
]
|
| 55 |
},
|
| 56 |
+
{
|
| 57 |
+
"type": "movie",
|
| 58 |
+
"id": "skyflix",
|
| 59 |
+
"name": "SKYFLIX",
|
| 60 |
+
"extraSupported": ["search"]
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"type": "series",
|
| 64 |
+
"id": "skyflix",
|
| 65 |
+
"name": "SKYFLIX",
|
| 66 |
+
"extraSupported": ["search"]
|
| 67 |
+
}
|
| 68 |
],
|
| 69 |
"idPrefixes": ["skyflix", "tt"]
|
| 70 |
}
|
| 71 |
|
| 72 |
+
|
| 73 |
+
@app_.get("/")
|
| 74 |
async def home(request: Request):
|
| 75 |
+
name = MANIFEST['name']
|
| 76 |
+
types = MANIFEST['types']
|
| 77 |
+
logo = MANIFEST['logo']
|
| 78 |
+
description = MANIFEST['description']
|
| 79 |
+
version = MANIFEST['version']
|
| 80 |
+
return templates.TemplateResponse('index.html', {"request": request, "name": name, "types": types, "logo": logo, "description": description, "version": version})
|
| 81 |
+
|
| 82 |
+
@app_.get("/logo")
|
| 83 |
+
async def proxy_logo(request: Request):
|
| 84 |
+
image_url = request.query_params.get('url')
|
| 85 |
|
| 86 |
+
if not image_url:
|
| 87 |
+
return JSONResponse(content={"error": "Nenhuma URL fornecida"}, status_code=400)
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
response = requests.get(image_url, stream=True)
|
| 91 |
+
|
| 92 |
+
if response.status_code != 200:
|
| 93 |
+
return JSONResponse(content={"error": f"Erro ao buscar a imagem: {response.status_code}"}, status_code=400)
|
| 94 |
+
|
| 95 |
+
content_type = response.headers.get('Content-Type', 'image/jpeg')
|
| 96 |
+
|
| 97 |
+
resp = Response(content=response.content, media_type=content_type)
|
| 98 |
+
resp.headers['Access-Control-Allow-Origin'] = '*' # Allow any origin
|
| 99 |
+
resp.headers['Access-Control-Allow-Methods'] = 'GET, OPTIONS' # Allowed methods
|
| 100 |
+
resp.headers['Access-Control-Allow-Headers'] = 'Content-Type' # Allowed headers
|
| 101 |
+
|
| 102 |
+
return resp
|
| 103 |
+
|
| 104 |
+
except requests.exceptions.RequestException as e:
|
| 105 |
+
return JSONResponse(content={"error": f"Erro ao buscar a imagem: {str(e)}"}, status_code=500)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@app_.get("/manifest.json")
|
| 109 |
async def manifest():
|
| 110 |
return JSONResponse(content=MANIFEST)
|
| 111 |
|
| 112 |
+
@app_.get("/catalog/tv/skyflix/genre={id}.json")
|
| 113 |
+
async def genres(id: str):
|
| 114 |
host = request.client.host
|
| 115 |
+
server = f'https://{host}/logo?url=' if not ('localhost' in host or '127.0.0.1' in host) else f'http://{host}/logo?url='
|
| 116 |
+
canais_ = []
|
| 117 |
+
|
| 118 |
+
if 'skip' not in id:
|
| 119 |
+
list_canais = canais.canais_list(server)
|
| 120 |
+
for canal in list_canais:
|
| 121 |
+
canal.pop('streams')
|
| 122 |
+
if id in canal['genres']:
|
| 123 |
+
canais_.append(canal)
|
| 124 |
+
|
| 125 |
+
return JSONResponse(content={"metas": canais_})
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
@app_.get("/catalog/{type}/{id}.json")
|
| 129 |
+
async def catalog_route(type: str, id: str):
|
| 130 |
+
host = request.client.host
|
| 131 |
+
server = f'https://{host}/logo?url=' if not ('localhost' in host or '127.0.0.1' in host) else f'http://{host}/logo?url='
|
| 132 |
+
|
| 133 |
if type == 'tv':
|
| 134 |
canais_ = []
|
| 135 |
list_canais = canais.canais_list(server)
|
| 136 |
for canal in list_canais:
|
| 137 |
+
canal.pop('streams')
|
| 138 |
canais_.append(canal)
|
| 139 |
+
return JSONResponse(content={"metas": canais_})
|
| 140 |
+
else:
|
| 141 |
+
return JSONResponse(content={"metas": []})
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
@app_.get("/catalog/{type}/skyflix/search={query}.json")
|
| 145 |
+
async def search(type: str, query: str):
|
| 146 |
+
catalog = catalog_search(query)
|
| 147 |
+
results = [item for item in catalog if item.get('type', '') == type] if catalog else []
|
| 148 |
+
return JSONResponse(content={"metas": results})
|
| 149 |
+
|
| 150 |
+
@app_.get("/meta/{type}/{id}.json")
|
| 151 |
+
async def meta(type: str, id: str):
|
| 152 |
+
host = request.client.host
|
| 153 |
+
server = f'https://{host}/logo?url=' if not ('localhost' in host or '127.0.0.1' in host) else f'http://{host}/logo?url='
|
| 154 |
+
|
| 155 |
+
if type == 'tv':
|
| 156 |
+
meta = {}
|
| 157 |
+
list_canais = canais.canais_list(server)
|
| 158 |
+
for canal in list_canais:
|
| 159 |
+
if canal['id'] == id:
|
| 160 |
+
canal.pop('streams')
|
| 161 |
+
meta['meta'] = canal
|
| 162 |
+
break
|
| 163 |
+
return JSONResponse(content=meta)
|
| 164 |
+
|
| 165 |
+
return JSONResponse(content={"meta": {}})
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
@app_.get("/stream/{type}/{id}.json")
|
| 169 |
+
async def stream(type: str, id: str):
|
| 170 |
+
host = request.client.host
|
| 171 |
+
server = f'https://{host}/logo?url=' if not ('localhost' in host or '127.0.0.1' in host) else f'http://{host}/logo?url='
|
| 172 |
+
|
| 173 |
+
if type == 'tv':
|
| 174 |
+
scrape_ = []
|
| 175 |
+
list_canais = canais.canais_list(server)
|
| 176 |
+
for canal in list_canais:
|
| 177 |
+
if canal['id'] == id:
|
| 178 |
+
scrape_ = canal.get('streams', [])
|
| 179 |
+
break
|
| 180 |
+
elif type in ['movie', 'series']:
|
| 181 |
+
try:
|
| 182 |
+
stream_, headers = search_link(id)
|
| 183 |
+
scrape_ = [{
|
| 184 |
+
"url": stream_,
|
| 185 |
+
"name": "SKYFLIX",
|
| 186 |
+
"description": "Netcine",
|
| 187 |
+
"behaviorHints": {
|
| 188 |
+
"notWebReady": True,
|
| 189 |
+
"proxyHeaders": {
|
| 190 |
+
"request": {
|
| 191 |
+
"User-Agent": headers['User-Agent'],
|
| 192 |
+
"Referer": headers['Referer'],
|
| 193 |
+
"Cookie": headers['Cookie']
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
}]
|
| 198 |
+
except:
|
| 199 |
+
scrape_ = []
|
| 200 |
+
|
| 201 |
+
return JSONResponse(content={"streams": scrape_})
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
@app_.options("/{path:path}")
|
| 205 |
+
async def options_handler(path: str):
|
| 206 |
+
response = Response()
|
| 207 |
+
return add_cors_headers(response)
|