@growth-labs/video 0.3.4 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/package.json +9 -5
- package/src/cloudflare-workers.d.ts +3 -0
- package/src/components/Video.astro +1 -1
- package/src/index.ts +129 -0
- package/src/options.ts +119 -0
- package/src/routes/import.ts +92 -0
- package/src/routes/playback.ts +101 -0
- package/src/routes/session.ts +85 -0
- package/src/types.ts +46 -0
- package/src/utils/captions.ts +72 -0
- package/src/utils/chapters.ts +63 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/ingest.ts +220 -0
- package/src/utils/jsonld.ts +42 -0
- package/src/utils/keys.ts +42 -0
- package/src/utils/session.ts +96 -0
- package/src/utils/text-tracks.ts +100 -0
- package/src/utils/url.ts +41 -0
- package/src/utils/youtube.ts +30 -0
- package/src/virtual.d.ts +9 -0
- package/src/vite-plugin.ts +34 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface YouTubeEmbedOptions {
|
|
2
|
+
autoplay?: boolean
|
|
3
|
+
start?: number
|
|
4
|
+
end?: number
|
|
5
|
+
muted?: boolean
|
|
6
|
+
controls?: boolean
|
|
7
|
+
privacyMode?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function youtubeEmbedUrl(videoId: string, opts: YouTubeEmbedOptions = {}): string {
|
|
11
|
+
const host = opts.privacyMode === false ? 'www.youtube.com' : 'www.youtube-nocookie.com'
|
|
12
|
+
const params = new URLSearchParams()
|
|
13
|
+
if (opts.autoplay) params.set('autoplay', '1')
|
|
14
|
+
if (opts.muted) params.set('mute', '1')
|
|
15
|
+
if (opts.controls === false) params.set('controls', '0')
|
|
16
|
+
if (opts.start != null) params.set('start', String(opts.start))
|
|
17
|
+
if (opts.end != null) params.set('end', String(opts.end))
|
|
18
|
+
const qs = params.toString()
|
|
19
|
+
return `https://${host}/embed/${videoId}${qs ? `?${qs}` : ''}`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type YouTubeThumbnailQuality = 'default' | 'hq' | 'maxres'
|
|
23
|
+
|
|
24
|
+
export function youtubeThumbnailUrl(
|
|
25
|
+
videoId: string,
|
|
26
|
+
quality: YouTubeThumbnailQuality = 'maxres',
|
|
27
|
+
): string {
|
|
28
|
+
const suffix = quality === 'maxres' ? 'maxresdefault' : quality === 'hq' ? 'hqdefault' : 'default'
|
|
29
|
+
return `https://i.ytimg.com/vi/${videoId}/${suffix}.jpg`
|
|
30
|
+
}
|
package/src/virtual.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare module 'virtual:growth-labs/video/config' {
|
|
2
|
+
import type { ResolvedVideoOptions } from '@growth-labs/video'
|
|
3
|
+
export const config: ResolvedVideoOptions
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
declare module 'virtual:growth-labs/video/access-check' {
|
|
7
|
+
import type { AccessCheck } from '@growth-labs/video'
|
|
8
|
+
export const accessRegistry: { check?: AccessCheck }
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Plugin } from 'vite'
|
|
2
|
+
import type { ResolvedVideoOptions } from './options.js'
|
|
3
|
+
|
|
4
|
+
const VIRTUAL_MODULE_ID = 'virtual:growth-labs/video/config'
|
|
5
|
+
const RESOLVED_VIRTUAL_MODULE_ID = `\0${VIRTUAL_MODULE_ID}`
|
|
6
|
+
const ACCESS_CHECK_VIRTUAL_ID = 'virtual:growth-labs/video/access-check'
|
|
7
|
+
const RESOLVED_ACCESS_CHECK_VIRTUAL_ID = `\0${ACCESS_CHECK_VIRTUAL_ID}`
|
|
8
|
+
|
|
9
|
+
export function growthLabsVideoPlugin(config: ResolvedVideoOptions): Plugin {
|
|
10
|
+
return {
|
|
11
|
+
name: 'growth-labs-video-config',
|
|
12
|
+
resolveId(id) {
|
|
13
|
+
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID
|
|
14
|
+
if (id === ACCESS_CHECK_VIRTUAL_ID) return RESOLVED_ACCESS_CHECK_VIRTUAL_ID
|
|
15
|
+
},
|
|
16
|
+
load(id) {
|
|
17
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
18
|
+
return `export const config = ${JSON.stringify(config)};`
|
|
19
|
+
}
|
|
20
|
+
if (id === RESOLVED_ACCESS_CHECK_VIRTUAL_ID) {
|
|
21
|
+
const spec = config.premium?.accessCheckModule
|
|
22
|
+
if (!spec) {
|
|
23
|
+
return 'export const accessRegistry = {};\n'
|
|
24
|
+
}
|
|
25
|
+
const local = '__gl_video_access_check_0'
|
|
26
|
+
return [
|
|
27
|
+
`import { ${spec.export} as ${local} } from ${JSON.stringify(spec.module)};`,
|
|
28
|
+
`export const accessRegistry = { check: ${local} };`,
|
|
29
|
+
'',
|
|
30
|
+
].join('\n')
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|