Mercurial > code > home > repos > video
diff video.py @ 37:7cacfae58430
thumbnails rewrite - store in db; don't use YT-provided pics for now
author | drewp@bigasterisk.com |
---|---|
date | Tue, 03 Dec 2024 19:28:11 -0800 |
parents | ed16fdbb3996 |
children | 0aea9e55899b |
line wrap: on
line diff
--- a/video.py Tue Dec 03 00:08:22 2024 -0800 +++ b/video.py Tue Dec 03 19:28:11 2024 -0800 @@ -1,7 +1,7 @@ import asyncio +from functools import partial import json import logging -from pathlib import Path import uvicorn from prometheus_client import Gauge @@ -16,6 +16,8 @@ from video_file_store import VideoFileStore from video_ingest import VideoIngest from mongo_required import open_mongo_or_die +import pymongo.database +import thumbnail logging.basicConfig(level=logging.DEBUG) log = logging.getLogger() @@ -66,6 +68,22 @@ return EventSourceResponse(g()) +def getDiskPath(fs, webRelPath): + doc = fs.find_one({'webRelPath': webRelPath}) + if doc is None: + raise ValueError + return doc['diskPath'] + +async def getThumbnail(db: pymongo.database.Database, req: Request) -> Response: + webRelPath = req.query_params['webRelPath'] + fs = db.get_collection('fs') + diskPath = getDiskPath(fs, webRelPath) + th = db.get_collection('thumb') + async with asyncio.timeout(10): + data = await thumbnail.getThumbnailData(th, diskPath) + return Response(content=data, media_type='image/jpeg') + + db = open_mongo_or_die().get_database('video') store = VideoFileStore(db.get_collection('fs')) @@ -87,6 +105,7 @@ ingestVideoUrl, methods=['POST']), Route('/video/api/ingest/queue', ingestQueue), + Route('/video/api/thumbnail', partial(getThumbnail, db)), ], ) @@ -97,7 +116,6 @@ app.state.processTask = asyncio.create_task(dl_queue.process()) return app - uvicorn.run(main, host="0.0.0.0", port=8004,