1 import { Video, VideoPlaylist } from '../../models'
2 import { secondsToTime } from './date'
4 function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) {
5 return (base ?? window.location.origin) + buildPlaylistWatchPath(playlist)
8 function buildPlaylistWatchPath (playlist: Pick<VideoPlaylist, 'shortUUID'>) {
9 return '/w/p/' + playlist.shortUUID
12 function buildVideoWatchPath (video: Pick<Video, 'shortUUID'>) {
13 return '/w/' + video.shortUUID
16 function buildVideoLink (video: Pick<Video, 'shortUUID'>, base?: string) {
17 return (base ?? window.location.origin) + buildVideoWatchPath(video)
20 function buildPlaylistEmbedPath (playlist: Pick<VideoPlaylist, 'uuid'>) {
21 return '/video-playlists/embed/' + playlist.uuid
24 function buildPlaylistEmbedLink (playlist: Pick<VideoPlaylist, 'uuid'>, base?: string) {
25 return (base ?? window.location.origin) + buildPlaylistEmbedPath(playlist)
28 function buildVideoEmbedPath (video: Pick<Video, 'uuid'>) {
29 return '/videos/embed/' + video.uuid
32 function buildVideoEmbedLink (video: Pick<Video, 'uuid'>, base?: string) {
33 return (base ?? window.location.origin) + buildVideoEmbedPath(video)
36 function decorateVideoLink (options: {
50 warningTitle?: boolean
55 peertubeLink?: boolean
58 const { url } = options
60 const params = new URLSearchParams()
62 if (options.startTime !== undefined && options.startTime !== null) {
63 const startTimeInt = Math.floor(options.startTime)
64 params.set('start', secondsToTime(startTimeInt))
67 if (options.stopTime) {
68 const stopTimeInt = Math.floor(options.stopTime)
69 params.set('stop', secondsToTime(stopTimeInt))
72 if (options.subtitle) params.set('subtitle', options.subtitle)
74 if (options.loop === true) params.set('loop', '1')
75 if (options.autoplay === true) params.set('autoplay', '1')
76 if (options.muted === true) params.set('muted', '1')
77 if (options.title === false) params.set('title', '0')
78 if (options.warningTitle === false) params.set('warningTitle', '0')
80 if (options.controls === false) params.set('controls', '0')
81 if (options.controlBar === false) params.set('controlBar', '0')
83 if (options.peertubeLink === false) params.set('peertubeLink', '0')
84 if (options.p2p !== undefined) params.set('p2p', options.p2p ? '1' : '0')
86 return buildUrl(url, params)
89 function decoratePlaylistLink (options: {
92 playlistPosition?: number
94 const { url } = options
96 const params = new URLSearchParams()
98 if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition)
100 return buildUrl(url, params)
103 // ---------------------------------------------------------------------------
110 buildPlaylistWatchPath,
112 buildPlaylistEmbedPath,
115 buildPlaylistEmbedLink,
122 function buildUrl (url: string, params: URLSearchParams) {
123 let hasParams = false
124 params.forEach(() => { hasParams = true })
126 if (hasParams) return url + '?' + params.toString()