Skip to content

Commit

Permalink
Merge pull request #65 from zauberzeug/video_download
Browse files Browse the repository at this point in the history
Videos Page: Use existing media url for download
  • Loading branch information
falkoschindler authored Jan 5, 2024
2 parents d8f01e8 + 3b876e4 commit 68b61cf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions rosys/analysis/videos_page_.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path

import watchfiles
from nicegui import background_tasks, ui
from nicegui import background_tasks, run, ui

VIDEO_FILES = Path('~/.rosys/timelapse/videos').expanduser()

Expand All @@ -10,21 +10,21 @@ class VideosPage:

def __init__(self) -> None:
@ui.page('/videos', title='Videos')
def page():

async def page():
@ui.refreshable
def videos():
for mp4 in sorted(VIDEO_FILES.glob('*.mp4'), reverse=True):
async def videos():
for mp4 in sorted(await run.io_bound(VIDEO_FILES.glob, '*.mp4'), reverse=True):
with ui.row():
with ui.card().tight():
ui.video(mp4).classes('w-[800px]')
video = ui.video(mp4).classes('w-[800px]')
src = video._props['src'] # pylint: disable=protected-access
with ui.column():
ui.button(on_click=lambda mp4=mp4: mp4.unlink()).props('icon=delete flat')
ui.button(on_click=lambda mp4=mp4: ui.download(mp4)).props('icon=download flat')
ui.button(on_click=lambda src=src: ui.download(src)).props('icon=download flat')

async def watch_videos():
async for _ in watchfiles.awatch(VIDEO_FILES):
videos.refresh()

videos()
await videos()
background_tasks.create(watch_videos(), name='watch videos files')

0 comments on commit 68b61cf

Please sign in to comment.