From 311d1baa596b09f03638653ff0fcdebd480de25b Mon Sep 17 00:00:00 2001 From: UrloMythus Date: Mon, 26 Aug 2024 11:53:22 +0200 Subject: [PATCH] Switched to FastApi --- config.json | 4 ++-- convert.py | 2 +- requirements.txt | 4 +++- run.py | 32 +++++++++++++++++--------------- streamingcommunity.py | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/config.json b/config.json index ebe979d..832aceb 100644 --- a/config.json +++ b/config.json @@ -31,10 +31,10 @@ } }, "General":{ - "load_env": "0", + "load_env": "1", "HOST": "0.0.0.0", "PORT": "8080", - "HF": "1" + "HF": "0" } } diff --git a/convert.py b/convert.py index c60169b..cb213b9 100644 --- a/convert.py +++ b/convert.py @@ -5,7 +5,7 @@ import config env_vars = load_env() TMDB_KEY = env_vars.get('TMDB_KEY') -def get_TMDb_id_from_IMDb_id(imdb_id): +def get_TMDb_id_from_IMDb_id(imdb_id): response = requests.get(f'https://api.themoviedb.org/3/find/{imdb_id}', params={'external_source': 'imdb_id', 'api_key': f'{TMDB_KEY}'}) tmbda = response.json() diff --git a/requirements.txt b/requirements.txt index b58dc59..201c5da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,7 @@ bs4 tmdbv3api dateparser python-dotenv -flask +fastapi +uvicorn +tzdata lxml \ No newline at end of file diff --git a/run.py b/run.py index 21afe60..02b7e7f 100644 --- a/run.py +++ b/run.py @@ -1,3 +1,5 @@ +from fastapi import FastAPI, HTTPException +from fastapi.responses import JSONResponse from flask import Flask, jsonify, abort from filmpertutti import filmpertutti from streamingcommunity import streaming_community @@ -10,6 +12,7 @@ import logging from okru import okru_get_url from animeworld import animeworld from dictionaries import okru,STREAM +import httpx # Configure logging FILMPERTUTTI = config.FILMPERTUTTI STREAMINGCOMMUNITY = config.STREAMINGCOMMUNITY @@ -30,8 +33,7 @@ else: if MYSTERIUS == "1": from cool import cool -app = Flask(__name__) - +app = FastAPI() MANIFEST = { "id": "org.stremio.mammamia", "version": "1.0.5", @@ -48,23 +50,23 @@ MANIFEST = { def respond_with(data): - resp = jsonify(data) + resp = JSONResponse(data) resp.headers['Access-Control-Allow-Origin'] = '*' resp.headers['Access-Control-Allow-Headers'] = '*' return resp -@app.route('/manifest.json') +@app.get('/manifest.json') def addon_manifest(): return respond_with(MANIFEST) -@app.route('/') +@app.get('/') 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" -@app.route('/catalog//.json') +@app.get('/catalog//.json') def addon_catalog(type, id): if type != "tv": - abort(404) + raise HTTPException(status_code=404) catalogs = {"metas": []} for channel in STREAM["channels"]: @@ -78,10 +80,10 @@ def addon_catalog(type, id): return respond_with(catalogs) -@app.route('/meta//.json') +@app.get('/meta//.json') def addon_meta(type, id): if type != "tv": - abort(404) + raise HTTPException(status_code=404) for channel in STREAM["channels"]: if channel["id"] == id: @@ -106,10 +108,10 @@ def addon_meta(type, id): abort(404) -@app.route('/stream//.json') +@app.get('/stream/{type}/{id}.json') def addon_stream(type, id): if type not in MANIFEST['types']: - abort(404) + raise HTTPException(status_code=404) streams = {'streams': []} if type == "tv": for channel in STREAM["channels"]: @@ -125,7 +127,7 @@ def addon_stream(type, id): 'url': channel_url }) if not streams['streams']: - abort(404) + raise HTTPException(status_code=404) return respond_with(streams) else: logging.debug(f"Handling movie or series: {id}") @@ -178,11 +180,11 @@ def addon_stream(type, id): if url_streamingwatch: streams['streams'].append({'title': f'{HF}StreamingWatch 720p', 'url': url_streamingwatch}) if not streams['streams']: - abort(404) + raise HTTPException(status_code=404) return respond_with(streams) - return respond_with({"meta": meta}) if __name__ == '__main__': - app.run(host=HOST, port=PORT) \ No newline at end of file + import uvicorn + uvicorn.run("run:app", host=HOST, port=PORT, log_level="info") \ No newline at end of file diff --git a/streamingcommunity.py b/streamingcommunity.py index e89b45c..e65d6e8 100644 --- a/streamingcommunity.py +++ b/streamingcommunity.py @@ -187,7 +187,7 @@ def streaming_community(imdb): showname = get_info_tmdb(tmdba,ismovie,type) elif SC_FAST_SEARCH == "0": tmdba = get_TMDb_id_from_IMDb_id(imdb_id) - showname,date = get_info_tmdb(tmdba,ismovie,type) + showname,date = get_info_tmdb(tmdba,ismovie,type) #HERE THE CASE IF IT IS A MOVIE else: if "tt" in imdb: