Mercurial > code > home > repos > video
annotate src/VideoPage.ts @ 12:e60be5d74c07
css edits and ingest link
author | drewp@bigasterisk.com |
---|---|
date | Sat, 15 Apr 2023 15:20:12 -0700 |
parents | f80f8c22752d |
children | b73941c4dc0a |
rev | line source |
---|---|
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
1 import { LitElement, html, css } from "lit"; |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
2 import { customElement, property } from "lit/decorators.js"; |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
3 import { PagePlayer } from "./PagePlayer"; |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
4 export { VideoSection } from "./VideoSection"; |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
5 export { PagePlayer } from "./PagePlayer"; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
6 import { ShakaVideoElement } from "./PagePlayer"; |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
7 interface VideoFile { |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
8 webRelPath: string; |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
9 label: string; |
6
ccfea3625cf6
render thumbs and display them (no video player at all atm)
drewp@bigasterisk.com
parents:
5
diff
changeset
|
10 thumbRelPath: string; |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
11 } |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
12 interface Subdir { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
13 label: string; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
14 path: string; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
15 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
16 |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
17 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
|
18 return "subdir=" + encodeURIComponent(subdir); |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
19 } |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
20 |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
21 @customElement("video-page") |
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
22 export class VideoPage extends LitElement { |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
23 videos: VideoFile[]; |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
24 subdirs: Subdir[]; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
25 @property() pathSegs: { label: string; subdir: string }[]; |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
26 constructor() { |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
27 super(); |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
28 this.videos = []; |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
29 this.subdirs = []; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
30 this.pathSegs = []; |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
31 this.loadVideos(); |
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
32 } |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
33 updatePathSegs(subdir: string) { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
34 this.pathSegs = [{ label: "TOP", subdir: "/" }]; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
35 if (subdir != "/") { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
36 let acc = ""; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
37 const segs = subdir.split("/"); |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
38 segs.splice(0, 1); // the root |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
39 for (let seg of segs) { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
40 acc += "/" + seg; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
41 this.pathSegs.push({ label: seg, subdir: acc }); |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
42 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
43 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
44 } |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
45 async loadVideos() { |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
46 const u = new URL(location.href); |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
47 const subdir = u.searchParams.get("subdir") || "/"; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
48 this.updatePathSegs(subdir); |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
49 const resp = await (await fetch("api/videos?" + subdirQuery(subdir))).json(); |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
50 this.videos = resp.videos as VideoFile[]; |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
51 this.subdirs = resp.subdirs as Subdir[]; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
52 this.requestUpdate(); |
4
c8a41359505c
server provides video listing from disk
drewp@bigasterisk.com
parents:
2
diff
changeset
|
53 } |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
54 static styles = [ |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
55 css` |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
56 a { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
57 color: white; |
12 | 58 |
59 } | |
60 .listing a { | |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
61 font-size: 20px; |
6
ccfea3625cf6
render thumbs and display them (no video player at all atm)
drewp@bigasterisk.com
parents:
5
diff
changeset
|
62 text-transform: uppercase; |
ccfea3625cf6
render thumbs and display them (no video player at all atm)
drewp@bigasterisk.com
parents:
5
diff
changeset
|
63 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
|
64 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
65 #path-segs > span { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
66 color: white; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
67 padding: 11px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
68 display: inline-block; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
69 background: #4ea1bd21; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
70 margin: 5px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
71 border-top-left-radius: 29px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
72 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
73 #path-segs > span:after { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
74 content: " >"; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
75 font-size: 33px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
76 vertical-align: middle; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
77 color: gray; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
78 } |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
79 .subdir { |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
80 vertical-align: top; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
81 color: white; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
82 padding: 11px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
83 display: inline-block; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
84 width: 300px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
85 background: #4ea1bd21; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
86 margin: 5px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
87 border-bottom-right-radius: 29px; |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
88 } |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
89 #scrim { |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
90 position: absolute; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
91 background: #000000b5; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
92 inset: 0; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
93 display: none; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
94 } |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
95 `, |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
96 ]; |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
97 render() { |
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
98 return html` |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
99 <div id="path-segs">${this.pathSegs.map((seg) => html`<span><a href="./?${subdirQuery(seg.subdir)}">${seg.label}</a></span>`)}</div> |
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
100 |
12 | 101 <div class="listing"> |
5
75b54be050bc
show one subdir of archive at once, with folders and parents-breadcrumbs
drewp@bigasterisk.com
parents:
4
diff
changeset
|
102 ${this.subdirs.map((s) => html`<div class="subdir"><a href="${"./?" + subdirQuery(s.path)}">${s.label}</a></div>`)} |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
103 ${this.videos.map( |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
104 (v) => html`<video-section @playVideo=${this.playVideo} thumbRelPath="${v.thumbRelPath}" title="${v.label}" manifest=${v.webRelPath}></video-section>` |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
105 )} |
12 | 106 </div> |
107 <p><a href="ingest/">Add new videos...</a></p> | |
108 | |
109 | |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
110 <div id="scrim" @click=${this.closePlayer}></div> |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
111 <page-player manifest=""></page-player> |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
112 `; |
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
113 } |
8
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
114 playVideo(ev: CustomEvent) { |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
115 const player = this.shadowRoot!.querySelector("page-player")! as PagePlayer; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
116 |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
117 player.manifest = ev.detail.manifest; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
118 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
|
119 |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
120 sv.src = ev.detail.manifest; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
121 sv.load().then(() => { |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
122 sv.play(); |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
123 }); |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
124 player.size = "big"; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
125 this.shadowRoot!.querySelector("#scrim")!.style.display = "block"; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
126 } |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
127 closePlayer() { |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
128 const player = this.shadowRoot!.querySelector("page-player")! as PagePlayer; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
129 player.size = "hidden"; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
130 |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
131 this.shadowRoot!.querySelector("#scrim")!.style.display = "none"; |
f80f8c22752d
start PagePlayer, a singleton player that appears on top
drewp@bigasterisk.com
parents:
6
diff
changeset
|
132 } |
2
78c1a2983010
rewrite UI and file serving parts; use vite
drewp@bigasterisk.com
parents:
diff
changeset
|
133 } |