Skip to content

Commit

Permalink
Merge pull request #14 from SageTendo/dev
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
SageTendo committed Feb 12, 2024
2 parents 343e963 + 3722346 commit fb8b661
Show file tree
Hide file tree
Showing 7 changed files with 1,167 additions and 476 deletions.
69 changes: 69 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
"backports.entry-points-selectable" = "*"
cachecontrol = "*"
cachy = "*"
certifi = "*"
cffi = "*"
charset-normalizer = "*"
cleo = "*"
click = "*"
clikit = "*"
crashtest = "*"
cryptography = "*"
distlib = "*"
dnspython = "*"
filelock = "*"
flask = {extras = ["async"], version = "*"}
greenlet = "*"
html5lib = "*"
idna = "*"
importlib-metadata = "*"
itsdangerous = "*"
jeepney = "*"
jinja2 = "*"
keyring = "*"
livereload = "*"
lockfile = "*"
lxml = "*"
markupsafe = "*"
msgpack = "*"
packaging = "*"
pastel = "*"
pexpect = "*"
pipenv = "*"
pkginfo = "*"
platformdirs = "*"
poetry = "*"
poetry-core = "*"
ptyprocess = "*"
pycparser = "*"
pylev = "*"
pyparsing = "*"
python-dotenv = "*"
requests-toolbelt = "*"
secretstorage = "*"
shellingham = "*"
six = "*"
tomlkit = "*"
tornado = "*"
urllib3 = "*"
virtualenv = "*"
virtualenv-clone = "*"
webencodings = "*"
werkzeug = "*"
zipp = "*"
pymongo = {extras = ["srv"], version = "*"}
waitress = "*"
flask-session = "*"
flask-compress = "*"

[dev-packages]
uvicorn = "*"

[requires]
python_version = "3.9"
1,486 changes: 1,021 additions & 465 deletions Pipfile.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion app/routes/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def mal_to_meta(anime_item: dict):
start_date += '-'

if end_date := anime_item.get('end_date', None):
start_date += end_date
start_date += end_date[:4]

# Check for background key in anime_item
background = None
Expand All @@ -143,6 +143,9 @@ def mal_to_meta(anime_item: dict):
media_type = None

return {
'cacheMaxAge': 43200,
'staleRevalidate': 3600,
'staleError': 3600,
'id': formatted_content_id,
'name': title,
'type': media_type,
Expand Down
20 changes: 11 additions & 9 deletions app/routes/manifest.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
from flask import Blueprint, abort

from . import MAL_ID_PREFIX, IMDB_ID_PREFIX
from . import MAL_ID_PREFIX
from .utils import respond_with
from ..db.db import UID_map_collection

manifest_blueprint = Blueprint('manifest', __name__)

MANIFEST = {
'id': 'com.sagetendo.mal-stremio-addon',
'version': '1.1.1',
'version': '1.2.0',
'name': 'MAL-Stremio Addon',
'logo': 'https://i.imgur.com/zVYdffr.png',
'description': 'Provides users with watchlist content from MyAnimeList within Stremio. '
'This addon only provides catalogs, with the help of AnimeKitsu',
'types': ['anime', 'series', 'movie'],

'catalogs': [
{'type': 'anime', 'id': 'plan_to_watch', 'name': 'MAL: Plan To Watch'},
{'type': 'anime', 'id': 'watching', 'name': 'MAL: Watching'},
{'type': 'anime', 'id': 'completed', 'name': 'MAL: Completed'},
{'type': 'anime', 'id': 'on_hold', 'name': 'MAL: On Hold'},
{'type': 'anime', 'id': 'dropped', 'name': 'MAL: Dropped'},
{'type': 'anime', 'id': 'plan_to_watch', 'name': 'MAL: Plan To Watch', 'extra': [{'name': 'skip'}]},
{'type': 'anime', 'id': 'watching', 'name': 'MAL: Watching', 'extra': [{'name': 'skip'}]},
{'type': 'anime', 'id': 'completed', 'name': 'MAL: Completed', 'extra': [{'name': 'skip'}]},
{'type': 'anime', 'id': 'on_hold', 'name': 'MAL: On Hold', 'extra': [{'name': 'skip'}]},
{'type': 'anime', 'id': 'dropped', 'name': 'MAL: Dropped', 'extra': [{'name': 'skip'}]},
{
'type': 'anime',
'id': 'search_list',
'name': 'Search Results',
'extra': [
{'name': 'search', 'isRequired': True}
{'name': 'search', 'isRequired': True},
{'name': 'skip'}
]
}
],

'resources': ['catalog', 'meta'],
'idPrefixes': [MAL_ID_PREFIX, IMDB_ID_PREFIX]
'idPrefixes': [MAL_ID_PREFIX]
}


Expand Down
55 changes: 54 additions & 1 deletion app/routes/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from flask import Blueprint, abort

from . import IMDB_ID_PREFIX
from .manifest import MANIFEST
from .utils import respond_with

Expand All @@ -20,6 +21,10 @@ def addon_meta(user_id: str, meta_type: str, meta_id: str):
:param meta_id: The ID of the content
:return: JSON response
"""
# ignore imdb ids for older versions of mal-stremio
if IMDB_ID_PREFIX in meta_id:
return respond_with({})

# Check if meta type exists in manifest
if meta_type not in MANIFEST['types']:
abort(404)
Expand All @@ -29,4 +34,52 @@ def addon_meta(user_id: str, meta_type: str, meta_id: str):
logging.error(resp.status_code, resp.reason)
abort(404, f"{resp.status_code}: {resp.reason}")

return respond_with(resp.json()) # Return with CORS to client
meta = kitsu_to_meta(resp.json())
meta['id'] = meta_id
meta['type'] = meta_type
return respond_with({'meta': meta}) # Return with CORS to client


def kitsu_to_meta(kitsu_meta: dict):
"""
Convert kitsu item to a valid Stremio meta format
:param kitsu_meta: The kitsu item to convert
:return: Stremio meta format
"""
meta = kitsu_meta.get('meta', {})

name = meta.get('name', '')
genres = meta.get('genres', [])
logo = meta.get('logo', None)
poster = meta.get('poster', None)
background = meta.get('background', None)
description = meta.get('description', None)
releaseInfo = meta.get('releaseInfo', None)
year = meta.get('year', None)
imdbRating = meta.get('imdbRating', None)
trailers = meta.get('trailers', [])
links = meta.get('links', [])
cacheMaxAge = meta.get('cacheMaxAge', None)
runtime = meta.get('runtime', None)
videos = meta.get('videos', [])
imdb_id = meta.get('imdb_id', None)

return {
'cacheMaxAge': cacheMaxAge,
'staleRevalidate': 43200,
'staleError': 3600,
'name': name,
'genres': genres,
'logo': logo,
'poster': poster,
'background': background,
'description': description,
'releaseInfo': releaseInfo,
'year': year,
'imdbRating': imdbRating,
'trailers': trailers,
'links': links,
'runtime': runtime,
'videos': videos,
'imdb_id': imdb_id
}
8 changes: 8 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from flask import Flask, render_template, session
from flask_compress import Compress
from flask_session import Session

from app.db.db import db
Expand All @@ -19,6 +20,8 @@

app.config['SESSION_MONGODB'] = db
Session(app)
Compress(app)

logging.basicConfig(format='%(asctime)s %(message)s')


Expand All @@ -36,6 +39,11 @@ def index():
return render_template('index.html')


@app.route('/favicon.ico')
def favicon():
return app.send_static_file('favicon.ico')


if __name__ == '__main__':
from waitress import serve

Expand Down
Binary file added static/favicon.ico
Binary file not shown.

0 comments on commit fb8b661

Please sign in to comment.