Skip to content

Commit

Permalink
- increased TTLs
Browse files Browse the repository at this point in the history
  • Loading branch information
SageTendo committed Feb 1, 2025
1 parent 18c7313 commit b5fe660
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/routes/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def addon_meta(user_id: str, meta_type: str, meta_id: str):
"""
# ignore imdb ids for older versions of mal-stremio
if IMDB_ID_PREFIX in meta_id:
return respond_with({'meta': {}, 'message': 'Content not supported'}, ttl=120)
return respond_with({'meta': {}, 'message': 'Content not supported'}, ttl=config.META_CACHE_EXPIRE)

if meta_type not in MANIFEST['types']:
abort(404)
Expand All @@ -54,7 +54,7 @@ def addon_meta(user_id: str, meta_type: str, meta_id: str):
meta = kitsu_to_meta(resp.json())
meta['id'] = meta_id
meta['type'] = meta_type
return respond_with({'meta': meta}, ttl=43200)
return respond_with({'meta': meta}, ttl=config.META_CACHE_EXPIRE)


@functools.lru_cache(maxsize=config.META_CACHE_SIZE)
Expand Down
10 changes: 5 additions & 5 deletions app/routes/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ def addon_stream(user_id: str, content_type: str, content_id: str):

content_id = urllib.parse.unquote(content_id)
if content_type not in MANIFEST['types']:
return respond_with({'streams': [], 'message': 'Content not supported'}, ttl=60)
return respond_with({'streams': [], 'message': 'Content not supported'}, ttl=config.STREAM_CACHE_EXPIRE)

get_token(user_id)
if content_id.startswith(MAL_ID_PREFIX):
exists, kitsu_id = get_kitsu_id_from_mal_id(content_id)
elif content_id.startswith('kitsu:'):
exists, kitsu_id = True, content_id.replace('kitsu:', '')
else:
return respond_with({'streams': [], 'message': 'Invalid content ID'}, ttl=60)
return respond_with({'streams': [], 'message': 'Invalid content ID'}, ttl=360)

if not exists:
return respond_with({'streams': [], 'message': 'No Kitsu ID in mapping database'}, ttl=60)
return respond_with({'streams': [], 'message': 'No Kitsu ID in mapping database'}, ttl=360)

url = f"{torrentio_api}/stream/{content_type}/kitsu:{kitsu_id}.json"
resp = fetch_streams(url)
if resp.is_error:
return respond_with({'streams': [], 'message': 'No streams found'}, ttl=60)
return respond_with(resp.json(), ttl=360)
return respond_with({'streams': [], 'message': 'No streams found'}, ttl=180)
return respond_with(resp.json(), ttl=config.STREAM_CACHE_EXPIRE)


@functools.lru_cache(maxsize=config.STREAM_CACHE_SIZE)
Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ class Config:
META_CACHE_SIZE = 25000
ID_CACHE_SIZE = 50000
STREAM_CACHE_SIZE = 20000
META_CACHE_EXPIRE = 3 * 24 * 60 * 60
STREAM_CACHE_EXPIRE = 3 * 60 * 60

0 comments on commit b5fe660

Please sign in to comment.