# HG changeset patch # User drewp@bigasterisk.com # Date 1733476614 28800 # Node ID 882d0bb0f80135287b2e798e9d879b7173b43f24 # Parent df51269bcef4c8c9b086494da040fef8708520ae clean up; quiet logs; factor out PATH_PREFIX diff -r df51269bcef4 -r 882d0bb0f801 src/VideoPage.ts --- a/src/VideoPage.ts Fri Dec 06 01:02:33 2024 -0800 +++ b/src/VideoPage.ts Fri Dec 06 01:16:54 2024 -0800 @@ -30,15 +30,16 @@ function subdirQuery(subdir: string): string { return "subdir=" + encodeURIComponent(subdir); } +const PATH_PREFIX = "/video"; +let routerShared: Router; class route { - path = "/video/*"; + path = PATH_PREFIX + "/*"; pageData: PageData | null = null; async enter(params: { [key: string]: string | undefined }): Promise { const webRelPath = "/" + params[0]!; // could be /a/dir/ or /a/video - console.log("enter", webRelPath); - const resp = await fetch("/video/api/videos?" + subdirQuery(webRelPath)); + const resp = await fetch(PATH_PREFIX + "/api/videos?" + subdirQuery(webRelPath)); if (resp.status == 404) { return false; } @@ -49,7 +50,6 @@ } render(p: { [key: string]: string | undefined }) { - console.log("render", this.pageData); return html``; } } @@ -61,20 +61,18 @@ constructor() { super(); - window.rr = this._router; + routerShared = this._router; } render() { const pd = (this._router.routes[0] as route).pageData; if (!pd) { - console.log("no page data", this._router.routes); return html`loading...`; throw new Error("no page data"); } - console.log("yes page data", pd); return html`
- +
${this._router.outlet()}
@@ -89,6 +87,7 @@ @customElement("video-page2") export class VideoPage2 extends LitElement { @property() pageData?: PageData; + @queryAsync("page-player") pagePlayer!: Promise; protected firstUpdated(_changedProperties: PropertyValues): void { document.addEventListener("keydown", (e) => { @@ -101,8 +100,6 @@ async connectedCallback() { super.connectedCallback(); if (this.pageData?.autoplay) { - //this.playVideo({ detail: { manifest: this.pageData.autoplay.webDataPath } } as CustomEvent); - console.log("we're a player page now", this.pageData.autoplay); this.startPlayer(this.pageData.autoplay); // this might not autoplay } else { @@ -115,10 +112,9 @@ if (this.pageData?.autoplay) { this.startPlayer(this.pageData.autoplay); } else { - this.closePlayer(); + this.closePlayer(); } } - console.log("updated", this.pageData?.autoplay); } static styles = [ @@ -174,11 +170,11 @@ ]; thumbSrc(vf: VideoFile) { - return "/video/api/thumbnail?webRelPath=" + encodeURIComponent(vf.webRelPath); + return PATH_PREFIX + "/api/thumbnail?webRelPath=" + encodeURIComponent(vf.webRelPath); } renderSubdir(subdir: Subdir): TemplateResult { - return html`
${subdir.label}
`; + return html`
${subdir.label}
`; } renderVideoListing(video: VideoFile) { @@ -187,7 +183,7 @@ webRelPath=${video.webRelPath} thumbRelPath=${this.thumbSrc(video)} title="${video.label}" - manifest="/video/files${video.webDataPath}" + manifest="${PATH_PREFIX}/files${video.webDataPath}" >`; } @@ -212,41 +208,42 @@ escapeALittle(fileUri: string): string { return fileUri.replace("#", encodeURIComponent("#")); } - @queryAsync("page-player") pagePlayer: Promise; async gotoVideoPlayerPage(ev: CustomEvent) { const player = await this.pagePlayer; - console.log("playing", player, ev.detail.manifest, ev.detail.webRelPath); - this.goto("/video" + ev.detail.webRelPath); + this.goto(PATH_PREFIX + "" + ev.detail.webRelPath); + } + + gotoDirListingPage() { + this.goto(PATH_PREFIX + "" + this.pageData?.webDirRelPath); } - async gotoDirListingPage() { - this.goto("/video" + this.pageData?.webDirRelPath); + + getScrim(): HTMLElement { + return this.shadowRoot!.querySelector("#scrim")!; } - + async startPlayer(p: VideoFile) { const player = await this.pagePlayer; - player.manifest = this.escapeALittle("/video/files" + p.webDataPath); + player.manifest = this.escapeALittle(PATH_PREFIX + "/files" + p.webDataPath); const sv = player.shadowRoot!.querySelector("shaka-video")! as ShakaVideoElement; sv.src = player.manifest; sv.autoplay = true; player.size = "big"; - this.shadowRoot!.querySelector("#scrim")!.style.display = "block"; + this.getScrim().style.display = "block"; } + goto(url: string) { - window.rr.goto(url); + routerShared.goto(url); window.history.pushState({}, "", url); } + async closePlayer() { const player = await this.pagePlayer; if (player.size === "hidden") { - console.log("wasn't playing", player.size); return; } - // return; - // this.goto("/video/" + this.pageData?.webDirRelPath); player.size = "hidden"; - - this.shadowRoot!.querySelector("#scrim")!.style.display = "none"; + this.getScrim().style.display = "none"; } } diff -r df51269bcef4 -r 882d0bb0f801 video.py --- a/video.py Fri Dec 06 01:02:33 2024 -0800 +++ b/video.py Fri Dec 06 01:16:54 2024 -0800 @@ -1,8 +1,10 @@ import asyncio -from functools import partial import json import logging +from functools import partial +from urllib.parse import unquote +import pymongo.database import uvicorn from prometheus_client import Gauge from sse_starlette.sse import EventSourceResponse @@ -13,12 +15,10 @@ from starlette_exporter import PrometheusMiddleware, handle_metrics import dl_queue +import thumbnail +from mongo_required import open_mongo_or_die from video_file_store import VideoFileStore from video_ingest import VideoIngest -from mongo_required import open_mongo_or_die -import pymongo.database -import thumbnail -from urllib.parse import unquote logging.basicConfig(level=logging.DEBUG) log = logging.getLogger()