inactivityTimeout: number,
peertubeLink: boolean,
poster: string,
- startTime: number
+ startTime: number | string
theaterMode: boolean,
videoCaptions: VideoJSCaption[],
controls?: boolean,
import { renderVideo } from './video-renderer'
import './settings-menu-button'
import { PeertubePluginOptions, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'
-import { isMobile, videoFileMaxByResolution, videoFileMinByResolution } from './utils'
+import { isMobile, videoFileMaxByResolution, videoFileMinByResolution, timeToInt } from './utils'
import * as CacheChunkStore from 'cache-chunk-store'
import { PeertubeChunkStore } from './peertube-chunk-store'
import {
// Disable auto play on iOS
this.autoplay = options.autoplay && this.isIOS() === false
- this.startTime = options.startTime
+ this.startTime = timeToInt(options.startTime)
this.videoFiles = options.videoFiles
this.videoViewUrl = options.videoViewUrl
this.videoDuration = options.videoDuration
// Magnet hash is not up to date with the torrent file, add directly the torrent file
if (err.message.indexOf('incorrect info hash') !== -1) {
console.error('Incorrect info hash detected, falling back to torrent file.')
- const options = { forcePlay: true }
- return this.addTorrent(this.torrent['xs'], previousVideoFile, options, done)
+ const newOptions = { forcePlay: true, seek: options.seek }
+ return this.addTorrent(this.torrent['xs'], previousVideoFile, newOptions, done)
}
return console.warn(err)
playerElement: HTMLVideoElement
videoViewUrl: string
videoDuration: number
- startTime: number
+ startTime: number | string
autoplay: boolean,
videoCaptions: VideoJSCaption[]
}
}
function buildVideoLink (time?: number) {
- let href = window.location.href.replace('/embed/', '/watch/')
+ const baseEmbedPath = window.location.pathname.replace('/embed/', '/watch/')
+ const baseEmbedURL = window.location.origin + baseEmbedPath
+
if (time) {
const timeInt = Math.floor(time)
- if (window.location.search) href += '&start=' + timeInt
- else href += '?start=' + timeInt
+ const params = new URLSearchParams(window.location.search)
+ params.set('start', secondsToTime(timeInt))
+
+ return baseEmbedURL + '?' + params.toString()
}
- return href
+ return baseEmbedURL
+}
+
+function timeToInt (time: number | string) {
+ if (typeof time === 'number') return time
+
+ const reg = /^((\d+)h)?((\d+)m)?((\d+)s?)?$/
+ const matches = time.match(reg)
+
+ if (!matches) return 0
+
+ const hours = parseInt(matches[2] || '0', 10)
+ const minutes = parseInt(matches[4] || '0', 10)
+ const seconds = parseInt(matches[6] || '0', 10)
+
+ return hours * 3600 + minutes * 60 + seconds
+}
+
+function secondsToTime (seconds: number) {
+ let time = ''
+
+ let hours = Math.floor(seconds / 3600)
+ if (hours >= 1) time = hours + 'h'
+
+ seconds %= 3600
+ let minutes = Math.floor(seconds / 60)
+ if (minutes >= 1) time += minutes + 'm'
+
+ seconds %= 60
+ if (seconds >= 1) time += seconds + 's'
+
+ return time
}
function buildVideoEmbed (embedUrl: string) {
export {
toTitleCase,
+ timeToInt,
buildVideoLink,
buildVideoEmbed,
videoFileMaxByResolution,
muted = false
loop = false
enableApi = false
- startTime = 0
+ startTime: number | string = 0
scope = 'peertube'
static async main () {
this.scope = this.getParamString(params, 'scope', this.scope)
const startTimeParamString = params.get('start')
- const startTimeParamNumber = parseInt(startTimeParamString, 10)
-
- if (isNaN(startTimeParamNumber) === false) this.startTime = startTimeParamNumber
+ if (startTimeParamString) this.startTime = startTimeParamString
} catch (err) {
console.error('Cannot get params from URL.', err)
}