-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from zauberzeug/timelapse
Resurrect and enhance time lapse functionality
- Loading branch information
Showing
3 changed files
with
119 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,30 @@ | ||
from pathlib import Path | ||
|
||
from nicegui import app, ui | ||
from starlette import responses | ||
import watchfiles | ||
from nicegui import background_tasks, ui | ||
|
||
PATH = Path('~/.rosys/timelapse/videos').expanduser() | ||
VIDEO_FILES = Path('~/.rosys/timelapse/videos').expanduser() | ||
|
||
|
||
class VideosPage: | ||
|
||
def __init__(self) -> None: | ||
@ui.page('/videos', title='Videos') | ||
def page(): | ||
def update_list() -> None: | ||
video_list.clear() | ||
with video_list: | ||
for mp4 in sorted(PATH.glob('*.mp4'), reverse=True): | ||
ui.link(mp4.stem.replace('_', ' ').replace('-', ':'), f'/timelapse/{mp4.name}') | ||
video_list = ui.column() | ||
ui.timer(5, update_list) | ||
|
||
@app.get('/timelapse/{filename}') | ||
def get_timelapse(filename: str) -> responses.FileResponse: | ||
return responses.FileResponse(PATH / filename) | ||
|
||
@ui.refreshable | ||
def videos(): | ||
for mp4 in sorted(VIDEO_FILES.glob('*.mp4'), reverse=True): | ||
with ui.row(): | ||
with ui.card().tight(): | ||
ui.video(mp4).classes('w-[800px]') | ||
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') | ||
|
||
async def watch_videos(): | ||
async for _ in watchfiles.awatch(VIDEO_FILES): | ||
videos.refresh() | ||
|
||
videos() | ||
background_tasks.create(watch_videos(), name='watch videos files') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters