1 import { VideoFile } from '../../../../shared/models/videos'
3 function toTitleCase (str: string) {
4 return str.charAt(0).toUpperCase() + str.slice(1)
7 // https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
8 // Don't import all Angular stuff, just copy the code with shame
9 const dictionaryBytes: Array<{max: number, type: string}> = [
10 { max: 1024, type: 'B' },
11 { max: 1048576, type: 'KB' },
12 { max: 1073741824, type: 'MB' },
13 { max: 1.0995116e12, type: 'GB' }
15 function bytes (value) {
16 const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
17 const calc = Math.floor(value / (format.max / 1024)).toString()
19 return [ calc, format.type ]
22 function isMobile () {
23 return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent)
26 function buildVideoLink (time?: number) {
27 let href = window.location.href.replace('/embed/', '/watch/')
29 const timeInt = Math.floor(time)
31 if (window.location.search) href += '&start=' + timeInt
32 else href += '?start=' + timeInt
38 function buildVideoEmbed (embedUrl: string) {
39 return '<iframe width="560" height="315" ' +
40 'sandbox="allow-same-origin allow-scripts" ' +
41 'src="' + embedUrl + '" ' +
42 'frameborder="0" allowfullscreen>' +
46 function copyToClipboard (text: string) {
47 const el = document.createElement('textarea')
49 el.setAttribute('readonly', '')
50 el.style.position = 'absolute'
51 el.style.left = '-9999px'
52 document.body.appendChild(el)
54 document.execCommand('copy')
55 document.body.removeChild(el)
58 function videoFileMaxByResolution (files: VideoFile[]) {
61 for (let i = 1; i < files.length; i++) {
63 if (max.resolution.id < file.resolution.id) max = file
69 function videoFileMinByResolution (files: VideoFile[]) {
72 for (let i = 1; i < files.length; i++) {
74 if (min.resolution.id > file.resolution.id) min = file
80 // ---------------------------------------------------------------------------
86 videoFileMaxByResolution,
87 videoFileMinByResolution,