view video_ingest.py @ 22:ff73b95fc72f

frontend cleanups and improvements. this commit contains some future work too
author drewp@bigasterisk.com
date Mon, 17 Apr 2023 13:33:05 -0700
parents 071943adf000
children 9e56e86a6814
line wrap: on
line source

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)