diff video_ingest.py @ 17:071943adf000

dnd a file or a url which we'll queue and fetch
author drewp@bigasterisk.com
date Sun, 16 Apr 2023 03:19:33 -0700
parents
children 9e56e86a6814
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/video_ingest.py	Sun Apr 16 03:19:33 2023 -0700
@@ -0,0 +1,26 @@
+import asyncio
+from dataclasses import dataclass
+from typing import Any, Coroutine
+
+import dl_queue
+from video_file_store import VideoFileStore
+
+
+@dataclass
+class VideoIngest:
+    store: VideoFileStore
+
+    async def addContent(self, name: str, body: Coroutine[Any, Any, bytes]):
+        await self.store.save(name, iter([await body]))
+
+    async def ingestUrl(self, url: str):
+        dl_queue.queue.put({'url': url, 'outDir': str(self.store.top)})
+
+    async def events(self):
+        prev = None
+        while True:
+            p = dl_queue.pending()
+            if p != prev:
+                prev = p
+                yield p
+            await asyncio.sleep(1)