- commit
- ed0a7f2640a376decfac9c03ef7d2d9567688470
- parent
- e34d775c07d2f8cbf23305a1b0f1d878280f9cad
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-02-07 09:38
support adaptive formats in file view
Diffstat
M | dropin.py | 17 | +++++++++++------ |
1 files changed, 11 insertions, 6 deletions
diff --git a/dropin.py b/dropin.py
@@ -250,12 +250,16 @@ async def video_view(request): 250 250 async def file_view(request): 251 251 id = request.match_info['id'] 252 252 quality = request.match_info['quality']253 -1 q = int(quality[:-1], 10)-1 253 format = request.match_info['format'] 254 254 files = await fetch(f'https://api.vhx.tv/videos/{id}/files')255 -1 best = min(256 -1 (file for file in files if file['quality'] != 'adaptive'),257 -1 key=lambda f: abs(int(f['quality'][:-1], 10) - q),258 -1 )-1 255 filtered = [file for file in files if file['format'] == format] -1 256 if not filtered: -1 257 raise web.HTTPNotFound -1 258 if quality == 'adaptive': -1 259 best = filtered[0] -1 260 else: -1 261 q = int(quality[:-1], 10) -1 262 best = min(filtered, key=lambda f: abs(int(f['quality'][:-1], 10) - q)) 259 263 raise web.HTTPSeeOther(location=best['_links']['source']['href']) 260 264 261 265 @@ -282,5 +286,6 @@ if __name__ == '__main__': 282 286 app.router.add_get(r'/series/{id:\d+}/', series_view) 283 287 app.router.add_get(r'/series/{id:\d+}.rss', series_feed) 284 288 app.router.add_get(r'/video/{id:\d+}/', video_view)285 -1 app.router.add_get(r'/video/{id:\d+}-{quality:\d+p}.mp4', file_view)-1 289 app.router.add_get(r'/video/{id:\d+}-{quality:\d+p}.{format:mp4}', file_view) -1 290 app.router.add_get(r'/video/{id:\d+}-{quality:adaptive}.{format:(m3u8|mpd)}', file_view) # noqa 286 291 web.run_app(app, host='localhost', port=args.port)