diff video.py @ 39:b5b29f6ef5cb

cleanup and refactor
author drewp@bigasterisk.com
date Thu, 05 Dec 2024 17:01:53 -0800
parents 0aea9e55899b
children 239a83d46d48
line wrap: on
line diff
--- a/video.py	Wed Dec 04 21:50:16 2024 -0800
+++ b/video.py	Thu Dec 05 17:01:53 2024 -0800
@@ -34,16 +34,16 @@
     if not subdir.endswith('/'):
         # raise ValueError(f'not a dir {subdir=}')
         # ok we'll list the parent dir underneath
-        subdir = '/'.join(subdir.split('/')[:-1]) # todo move to FE
+        subdir = '/'.join(subdir.split('/')[:-1])  # todo move to FE
     else:
         subdir = subdir[:-1]
-    if subdir=="":
+    if subdir == "":
         subdir = "./"
-    if not (subdir.startswith('/') or subdir=='./'):
+    if not (subdir.startswith('/') or subdir == './'):
         raise ValueError(f'not a dir {subdir=}')
     subdir = subdir[1:]
     log.debug(f'videos request corrected to: {subdir=}')
-    
+
     vfInDir = store.findInDir(subdir)
     return JSONResponse({
         "videos": [{
@@ -81,13 +81,16 @@
 
     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:
+
+async def getThumbnail(db: pymongo.database.Database,
+                       req: Request) -> Response:
     webRelPath = req.query_params['webRelPath']
     fs = db.get_collection('fs')
     diskPath = getDiskPath(fs, webRelPath)
@@ -95,7 +98,6 @@
     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')
@@ -129,6 +131,7 @@
     app.state.processTask = asyncio.create_task(dl_queue.process())
     return app
 
+
 uvicorn.run(main,
             host="0.0.0.0",
             port=8004,