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
52 peertubeLink?: boolean
54 const { url } = options
56 const params = generateParams(window.location.search)
58 if (options.startTime !== undefined && options.startTime !== null) {
59 const startTimeInt = Math.floor(options.startTime)
60 params.set('start', secondsToTime(startTimeInt))
63 if (options.stopTime) {
64 const stopTimeInt = Math.floor(options.stopTime)
65 params.set('stop', secondsToTime(stopTimeInt))
68 if (options.subtitle) params.set('subtitle', options.subtitle)
70 if (options.loop === true) params.set('loop', '1')
71 if (options.autoplay === true) params.set('autoplay', '1')
72 if (options.muted === true) params.set('muted', '1')
73 if (options.title === false) params.set('title', '0')
74 if (options.warningTitle === false) params.set('warningTitle', '0')
75 if (options.controls === false) params.set('controls', '0')
76 if (options.peertubeLink === false) params.set('peertubeLink', '0')
78 return buildUrl(url, params)
81 function decoratePlaylistLink (options: {
84 playlistPosition?: number
86 const { url } = options
88 const params = generateParams(window.location.search)
90 if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition)
92 return buildUrl(url, params)
95 // ---------------------------------------------------------------------------
102 buildPlaylistWatchPath,
104 buildPlaylistEmbedPath,
107 buildPlaylistEmbedLink,
114 function buildUrl (url: string, params: URLSearchParams) {
115 let hasParams = false
116 params.forEach(() => { hasParams = true })
118 if (hasParams) return url + '?' + params.toString()
123 function generateParams (url: string) {
124 const params = new URLSearchParams(window.location.search)
125 // Unused parameters in embed
126 params.delete('videoId')
127 params.delete('resume')