Switched to FastApi

This commit is contained in:
UrloMythus
2024-08-26 11:53:22 +02:00 Unverified
parent 7684818f52
commit 311d1baa59
5 changed files with 24 additions and 20 deletions
+2 -2
View File
@@ -31,10 +31,10 @@
} }
}, },
"General":{ "General":{
"load_env": "0", "load_env": "1",
"HOST": "0.0.0.0", "HOST": "0.0.0.0",
"PORT": "8080", "PORT": "8080",
"HF": "1" "HF": "0"
} }
} }
+3 -1
View File
@@ -2,5 +2,7 @@ bs4
tmdbv3api tmdbv3api
dateparser dateparser
python-dotenv python-dotenv
flask fastapi
uvicorn
tzdata
lxml lxml
+17 -15
View File
@@ -1,3 +1,5 @@
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
from flask import Flask, jsonify, abort from flask import Flask, jsonify, abort
from filmpertutti import filmpertutti from filmpertutti import filmpertutti
from streamingcommunity import streaming_community from streamingcommunity import streaming_community
@@ -10,6 +12,7 @@ import logging
from okru import okru_get_url from okru import okru_get_url
from animeworld import animeworld from animeworld import animeworld
from dictionaries import okru,STREAM from dictionaries import okru,STREAM
import httpx
# Configure logging # Configure logging
FILMPERTUTTI = config.FILMPERTUTTI FILMPERTUTTI = config.FILMPERTUTTI
STREAMINGCOMMUNITY = config.STREAMINGCOMMUNITY STREAMINGCOMMUNITY = config.STREAMINGCOMMUNITY
@@ -30,8 +33,7 @@ else:
if MYSTERIUS == "1": if MYSTERIUS == "1":
from cool import cool from cool import cool
app = Flask(__name__) app = FastAPI()
MANIFEST = { MANIFEST = {
"id": "org.stremio.mammamia", "id": "org.stremio.mammamia",
"version": "1.0.5", "version": "1.0.5",
@@ -48,23 +50,23 @@ MANIFEST = {
def respond_with(data): def respond_with(data):
resp = jsonify(data) resp = JSONResponse(data)
resp.headers['Access-Control-Allow-Origin'] = '*' resp.headers['Access-Control-Allow-Origin'] = '*'
resp.headers['Access-Control-Allow-Headers'] = '*' resp.headers['Access-Control-Allow-Headers'] = '*'
return resp return resp
@app.route('/manifest.json') @app.get('/manifest.json')
def addon_manifest(): def addon_manifest():
return respond_with(MANIFEST) return respond_with(MANIFEST)
@app.route('/') @app.get('/')
def root(): def root():
return "Hello, this is a Stremio Addon providing HTTPS Stream for Italian Movies/Series, to install it add /manifest.json to the url and then add it into the Stremio search bar" return "Hello, this is a Stremio Addon providing HTTPS Stream for Italian Movies/Series, to install it add /manifest.json to the url and then add it into the Stremio search bar"
@app.route('/catalog/<type>/<id>.json') @app.get('/catalog/<type>/<id>.json')
def addon_catalog(type, id): def addon_catalog(type, id):
if type != "tv": if type != "tv":
abort(404) raise HTTPException(status_code=404)
catalogs = {"metas": []} catalogs = {"metas": []}
for channel in STREAM["channels"]: for channel in STREAM["channels"]:
@@ -78,10 +80,10 @@ def addon_catalog(type, id):
return respond_with(catalogs) return respond_with(catalogs)
@app.route('/meta/<type>/<id>.json') @app.get('/meta/<type>/<id>.json')
def addon_meta(type, id): def addon_meta(type, id):
if type != "tv": if type != "tv":
abort(404) raise HTTPException(status_code=404)
for channel in STREAM["channels"]: for channel in STREAM["channels"]:
if channel["id"] == id: if channel["id"] == id:
@@ -106,10 +108,10 @@ def addon_meta(type, id):
abort(404) abort(404)
@app.route('/stream/<type>/<id>.json') @app.get('/stream/{type}/{id}.json')
def addon_stream(type, id): def addon_stream(type, id):
if type not in MANIFEST['types']: if type not in MANIFEST['types']:
abort(404) raise HTTPException(status_code=404)
streams = {'streams': []} streams = {'streams': []}
if type == "tv": if type == "tv":
for channel in STREAM["channels"]: for channel in STREAM["channels"]:
@@ -125,7 +127,7 @@ def addon_stream(type, id):
'url': channel_url 'url': channel_url
}) })
if not streams['streams']: if not streams['streams']:
abort(404) raise HTTPException(status_code=404)
return respond_with(streams) return respond_with(streams)
else: else:
logging.debug(f"Handling movie or series: {id}") logging.debug(f"Handling movie or series: {id}")
@@ -178,11 +180,11 @@ def addon_stream(type, id):
if url_streamingwatch: if url_streamingwatch:
streams['streams'].append({'title': f'{HF}StreamingWatch 720p', 'url': url_streamingwatch}) streams['streams'].append({'title': f'{HF}StreamingWatch 720p', 'url': url_streamingwatch})
if not streams['streams']: if not streams['streams']:
abort(404) raise HTTPException(status_code=404)
return respond_with(streams) return respond_with(streams)
return respond_with({"meta": meta})
if __name__ == '__main__': if __name__ == '__main__':
app.run(host=HOST, port=PORT) import uvicorn
uvicorn.run("run:app", host=HOST, port=PORT, log_level="info")