Mercurial > code > home > repos > video
annotate src/VideoPage.ts @ 46:882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
author | drewp@bigasterisk.com |
---|---|
date | Fri, 06 Dec 2024 01:16:54 -0800 |
parents | df51269bcef4 |
children | c2c51aae3e31 |
rev | line source |
---|---|
45 | 1 import { Router } from "@lit-labs/router"; |
39 | 2 import { LitElement, PropertyValues, TemplateResult, css, html, unsafeCSS } from "lit"; |
45 | 3 import { customElement, property, queryAsync } from "lit/decorators.js"; |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
13
diff
changeset
|
4 import { PagePlayer, ShakaVideoElement } from "./PagePlayer"; |
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
13
diff
changeset
|
5 import maincss from "./main.css?inline"; |
24 | 6 export { SlProgressBar } from "@shoelace-style/shoelace"; |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
13
diff
changeset
|
7 export { PagePlayer } from "./PagePlayer"; |
45 | 8 export { VBreadcrumbs } from "./VBreadcrumbs"; |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
9 export { VideoSection } from "./VideoSection"; |
45 | 10 |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
11 interface VideoFile { |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
12 webRelPath: string; |
39 | 13 webDataPath: string; |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
14 label: string; |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
15 } |
39 | 16 |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
17 interface Subdir { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
18 label: string; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
19 path: string; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
20 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
21 |
45 | 22 interface PageData { |
23 webDirRelPath: string; | |
24 dirLabel: string; | |
39 | 25 videos: VideoFile[]; |
26 subdirs: Subdir[]; | |
45 | 27 autoplay: VideoFile | null; |
39 | 28 } |
29 | |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
30 function subdirQuery(subdir: string): string { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
31 return "subdir=" + encodeURIComponent(subdir); |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
32 } |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
33 const PATH_PREFIX = "/video"; |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
34 let routerShared: Router; |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
35 |
39 | 36 class route { |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
37 path = PATH_PREFIX + "/*"; |
45 | 38 pageData: PageData | null = null; |
39 | 39 |
40 async enter(params: { [key: string]: string | undefined }): Promise<boolean> { | |
45 | 41 const webRelPath = "/" + params[0]!; // could be /a/dir/ or /a/video |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
42 const resp = await fetch(PATH_PREFIX + "/api/videos?" + subdirQuery(webRelPath)); |
39 | 43 if (resp.status == 404) { |
44 return false; | |
45 } | |
45 | 46 this.pageData = await resp.json(); |
47 if (!this.pageData) return false; | |
39 | 48 |
49 return true; | |
50 } | |
51 | |
52 render(p: { [key: string]: string | undefined }) { | |
45 | 53 return html`<video-page2 .pageData=${this.pageData}></video-page2>`; |
39 | 54 } |
55 } | |
56 | |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
57 @customElement("video-page") |
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
58 export class VideoPage extends LitElement { |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
59 static styles = [unsafeCSS(maincss)]; |
39 | 60 private _router = new Router(this, [new route()], {}); |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
61 |
45 | 62 constructor() { |
63 super(); | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
64 routerShared = this._router; |
45 | 65 } |
66 | |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
67 render() { |
45 | 68 const pd = (this._router.routes[0] as route).pageData; |
69 if (!pd) { | |
70 return html`loading...`; | |
71 throw new Error("no page data"); | |
72 } | |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
73 return html` |
39 | 74 <header> |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
75 <img src="${PATH_PREFIX}/logo1.png" title="JelloBello" /> |
45 | 76 <v-breadcrumbs dirPath=${pd.webDirRelPath}></v-breadcrumbs> |
39 | 77 </header> |
78 <main>${this._router.outlet()}</main> | |
41 | 79 <footer> |
80 <bigast-loginbar></bigast-loginbar> | |
81 <span><a href="ingest/">Add new videos...</a></span> | |
82 </footer> | |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
83 `; |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
84 } |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
85 } |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
86 |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
87 @customElement("video-page2") |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
88 export class VideoPage2 extends LitElement { |
45 | 89 @property() pageData?: PageData; |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
90 @queryAsync("page-player") pagePlayer!: Promise<PagePlayer>; |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
91 |
31 | 92 protected firstUpdated(_changedProperties: PropertyValues): void { |
93 document.addEventListener("keydown", (e) => { | |
94 if (e.key == "Escape") { | |
45 | 95 this.gotoDirListingPage(); |
31 | 96 } |
97 }); | |
98 } | |
39 | 99 |
45 | 100 async connectedCallback() { |
101 super.connectedCallback(); | |
102 if (this.pageData?.autoplay) { | |
103 this.startPlayer(this.pageData.autoplay); | |
104 // this might not autoplay | |
105 } else { | |
106 this.closePlayer(); | |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
107 } |
45 | 108 } |
109 protected update(changedProperties: PropertyValues): void { | |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
110 super.update(changedProperties); |
45 | 111 if (changedProperties.has("pageData")) { |
112 if (this.pageData?.autoplay) { | |
113 this.startPlayer(this.pageData.autoplay); | |
114 } else { | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
115 this.closePlayer(); |
45 | 116 } |
117 } | |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
118 } |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
119 |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
120 static styles = [ |
13
b73941c4dc0a
more wip on ingest page; shared styles
drewp@bigasterisk.com
parents:
12
diff
changeset
|
121 unsafeCSS(maincss), |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
122 css` |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
123 :host { |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
124 display: block; |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
125 } |
41 | 126 |
127 video-section { | |
128 margin: 8px; | |
129 } | |
130 | |
12 | 131 .listing a { |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
132 font-size: 20px; |
6
ccfea3625cf6
render thumbs and display them (no video player at all atm)
drewp@bigasterisk.com
parents:
5
diff
changeset
|
133 text-transform: uppercase; |
ccfea3625cf6
render thumbs and display them (no video player at all atm)
drewp@bigasterisk.com
parents:
5
diff
changeset
|
134 text-underline-offset: 10px; |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
135 } |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
136 |
41 | 137 .listing a .subdir { |
138 transition: background 0.5s; | |
139 transition-delay: 0.1s; | |
140 background: #4ea1bd21; | |
141 } | |
142 | |
143 .listing a:hover .subdir { | |
144 transition: background 0.5s; | |
145 background: #4ea1bd66; | |
146 } | |
147 | |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
148 .subdir { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
149 vertical-align: top; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
150 color: white; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
151 padding: 11px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
152 display: inline-block; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
153 width: 300px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
154 margin: 5px; |
45 | 155 border-radius: 5px; |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
156 } |
41 | 157 |
158 .subdir:after { | |
159 content: " › "; | |
160 color: #979797; | |
161 } | |
162 | |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
163 #scrim { |
22
ff73b95fc72f
frontend cleanups and improvements. this commit contains some future work too
drewp@bigasterisk.com
parents:
13
diff
changeset
|
164 position: fixed; |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
165 background: #000000b5; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
166 inset: 0; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
167 display: none; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
168 } |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
169 `, |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
170 ]; |
39 | 171 |
45 | 172 thumbSrc(vf: VideoFile) { |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
173 return PATH_PREFIX + "/api/thumbnail?webRelPath=" + encodeURIComponent(vf.webRelPath); |
39 | 174 } |
175 | |
176 renderSubdir(subdir: Subdir): TemplateResult { | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
177 return html`<a href="${PATH_PREFIX}${subdir.path}"><div class="subdir">${subdir.label}</div></a>`; |
39 | 178 } |
179 | |
180 renderVideoListing(video: VideoFile) { | |
181 return html`<video-section | |
45 | 182 @playVideo=${this.gotoVideoPlayerPage} |
183 webRelPath=${video.webRelPath} | |
39 | 184 thumbRelPath=${this.thumbSrc(video)} |
185 title="${video.label}" | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
186 manifest="${PATH_PREFIX}/files${video.webDataPath}" |
39 | 187 ></video-section>`; |
188 } | |
189 | |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
190 render() { |
45 | 191 if (this.pageData == null) { |
39 | 192 return html`<div>Loading...</div>`; |
193 } | |
194 const listings = [ | |
45 | 195 html`${this.pageData.subdirs.map((s) => this.renderSubdir(s))}`, // |
196 html`<div>${this.pageData.videos.map((v) => this.renderVideoListing(v))}</div>`, | |
39 | 197 ]; |
45 | 198 const dirTitle = this.pageData.dirLabel ? html`<h2>${this.pageData.dirLabel}</h2>` : html``; |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
199 return html` |
42 | 200 ${dirTitle} |
39 | 201 <div class="listing">${listings}</div> |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
202 |
45 | 203 <div id="scrim" @click=${this.gotoDirListingPage}></div> |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
204 <page-player manifest=""></page-player> |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
205 `; |
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
206 } |
39 | 207 |
38
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
208 escapeALittle(fileUri: string): string { |
0aea9e55899b
hack in path router - dirs kind of work; putting a video in the path doesn't
drewp@bigasterisk.com
parents:
37
diff
changeset
|
209 return fileUri.replace("#", encodeURIComponent("#")); |
33
6ee4c73decf4
fix playability of vids with # in their titles
drewp@bigasterisk.com
parents:
31
diff
changeset
|
210 } |
39 | 211 |
45 | 212 async gotoVideoPlayerPage(ev: CustomEvent) { |
213 const player = await this.pagePlayer; | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
214 this.goto(PATH_PREFIX + "" + ev.detail.webRelPath); |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
215 } |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
216 |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
217 gotoDirListingPage() { |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
218 this.goto(PATH_PREFIX + "" + this.pageData?.webDirRelPath); |
45 | 219 } |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
220 |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
221 getScrim(): HTMLElement { |
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
222 return this.shadowRoot!.querySelector("#scrim")!; |
45 | 223 } |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
224 |
45 | 225 async startPlayer(p: VideoFile) { |
226 const player = await this.pagePlayer; | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
227 player.manifest = this.escapeALittle(PATH_PREFIX + "/files" + p.webDataPath); |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
228 const sv = player.shadowRoot!.querySelector("shaka-video")! as ShakaVideoElement; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
229 |
33
6ee4c73decf4
fix playability of vids with # in their titles
drewp@bigasterisk.com
parents:
31
diff
changeset
|
230 sv.src = player.manifest; |
34 | 231 sv.autoplay = true; |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
232 player.size = "big"; |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
233 this.getScrim().style.display = "block"; |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
234 } |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
235 |
45 | 236 goto(url: string) { |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
237 routerShared.goto(url); |
45 | 238 window.history.pushState({}, "", url); |
239 } | |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
240 |
45 | 241 async closePlayer() { |
242 const player = await this.pagePlayer; | |
243 if (player.size === "hidden") { | |
244 return; | |
245 } | |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
246 player.size = "hidden"; |
46
882d0bb0f801
clean up; quiet logs; factor out PATH_PREFIX
drewp@bigasterisk.com
parents:
45
diff
changeset
|
247 this.getScrim().style.display = "none"; |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
248 } |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
249 } |