- commit
- 9f69338ba936fe65a4c31774f1f626fcf3329d82
- parent
- b0b8bbf386afc67b1776f0e2b97bcdbbc12d7e9b
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-03-05 19:52
only cache videos for a 5 minutes they expire quickly
Diffstat
M | dropin.py | 8 | +++++--- |
1 files changed, 5 insertions, 3 deletions
diff --git a/dropin.py b/dropin.py
@@ -176,7 +176,7 @@ unauth = Auth() 176 176 177 177 def async_cache(func): 178 178 cache = {}179 -1 async def wrapper(*args, **kwargs):-1 179 async def wrapper(*args, duration=CACHE_DURATION, **kwargs): 180 180 nonlocal cache 181 181 cache = {k: v for k, v in cache.items() if v[0] < time.time()} 182 182 @@ -185,7 +185,7 @@ def async_cache(func): 185 185 return await cache[key][1] 186 186 187 187 future = asyncio.Future()188 -1 cache[key] = (time.time() + CACHE_DURATION, future)-1 188 cache[key] = (time.time() + duration, future) 189 189 try: 190 190 future.set_result(await func(*args, **kwargs)) 191 191 except Exception as e: @@ -354,7 +354,9 @@ async def file_view(request): 354 354 id = request.match_info['id'] 355 355 quality = request.match_info['quality'] 356 356 format = request.match_info['format']357 -1 files = await fetch(f'https://api.vhx.tv/videos/{id}/files', need_auth=True)-1 357 files = await fetch( -1 358 f'https://api.vhx.tv/videos/{id}/files', need_auth=True, duration=300 -1 359 ) 358 360 filtered = [file for file in files if file['format'] == format] 359 361 if not filtered: 360 362 raise web.HTTPNotFound