@ -1,10 +1,10 @@
var desertBusStart = new Date ( "1970-01-01T00:00:00Z" ) ;
let desertBusStart = new Date ( "1970-01-01T00:00:00Z" ) ;
var timeFormat = "AGO" ;
let timeFormat = "AGO" ;
function pageSetup ( isEditor ) {
function pageSetup ( isEditor ) {
//Get values from ThrimShim
//Get values from ThrimShim
if ( isEditor && /id=/ . test ( document . location . search ) ) {
if ( isEditor && /id=/ . test ( document . location . search ) ) {
var rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
const rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
fetch ( "/thrimshim/" + rowId )
fetch ( "/thrimshim/" + rowId )
. then ( data => data . json ( ) )
. then ( data => data . json ( ) )
. then ( function ( data ) {
. then ( function ( data ) {
@ -24,10 +24,10 @@ function pageSetup(isEditor) {
// Apply padding - start 1min early, finish 2min late because these times are generally
// Apply padding - start 1min early, finish 2min late because these times are generally
// rounded down to the minute, so if something ends at "00:10" it might actually end
// rounded down to the minute, so if something ends at "00:10" it might actually end
// at 00:10:59 so we should pad to 00:12:00.
// at 00:10:59 so we should pad to 00:12:00.
var start = data . event _start
const start = data . event _start
? new Date ( fromTimestamp ( data . event _start ) . getTime ( ) - 60 * 1000 )
? new Date ( fromTimestamp ( data . event _start ) . getTime ( ) - 60 * 1000 )
: null ;
: null ;
var end = data . event _end
const end = data . event _end
? new Date ( fromTimestamp ( data . event _end ) . getTime ( ) + 2 * 60 * 1000 )
? new Date ( fromTimestamp ( data . event _end ) . getTime ( ) + 2 * 60 * 1000 )
: null ;
: null ;
setTimeRange ( start , end ) ;
setTimeRange ( start , end ) ;
@ -102,12 +102,12 @@ function pageSetup(isEditor) {
// Time-formatting functions
// Time-formatting functions
function parseDuration ( duration ) {
function parseDuration ( duration ) {
var direction = 1 ;
let direction = 1 ;
if ( duration . startsWith ( "-" ) ) {
if ( duration . startsWith ( "-" ) ) {
duration = duration . slice ( 1 ) ;
duration = duration . slice ( 1 ) ;
direction = - 1 ;
direction = - 1 ;
}
}
var parts = duration . split ( ":" ) ;
const parts = duration . split ( ":" ) ;
return (
return (
( parseInt ( parts [ 0 ] ) + ( parts [ 1 ] || "0" ) / 60 + ( parts [ 2 ] || "0" ) / 3600 ) * 60 * 60 * direction
( parseInt ( parts [ 0 ] ) + ( parts [ 1 ] || "0" ) / 60 + ( parts [ 2 ] || "0" ) / 3600 ) * 60 * 60 * direction
) ;
) ;
@ -147,7 +147,7 @@ function fromAgo(ago) {
// Set the stream start/end range from a pair of Dates using the current format
// Set the stream start/end range from a pair of Dates using the current format
// If given null, sets to blank.
// If given null, sets to blank.
function setTimeRange ( start , end ) {
function setTimeRange ( start , end ) {
var toFunc = {
const toFunc = {
UTC : toTimestamp ,
UTC : toTimestamp ,
BUSTIME : toBustime ,
BUSTIME : toBustime ,
AGO : toAgo ,
AGO : toAgo ,
@ -160,16 +160,16 @@ function setTimeRange(start, end) {
// Returns an object containing 'start' and 'end' fields.
// Returns an object containing 'start' and 'end' fields.
// If either is empty / invalid, returns null.
// If either is empty / invalid, returns null.
function getTimeRange ( ) {
function getTimeRange ( ) {
var fromFunc = {
const fromFunc = {
UTC : fromTimestamp ,
UTC : fromTimestamp ,
BUSTIME : fromBustime ,
BUSTIME : fromBustime ,
AGO : fromAgo ,
AGO : fromAgo ,
} [ timeFormat ] ;
} [ timeFormat ] ;
var convert = function ( value ) {
function convert ( value ) {
if ( ! value ) {
if ( ! value ) {
return null ;
return null ;
}
}
var date = fromFunc ( value ) ;
const date = fromFunc ( value ) ;
return isNaN ( date ) ? null : date ;
return isNaN ( date ) ? null : date ;
} ;
} ;
return {
return {
@ -179,7 +179,7 @@ function getTimeRange() {
} ;
} ;
function getTimeRangeAsTimestamp ( ) {
function getTimeRangeAsTimestamp ( ) {
var range = getTimeRange ( ) ;
const range = getTimeRange ( ) ;
return {
return {
// if not null, format as timestamp
// if not null, format as timestamp
start : range . start && toTimestamp ( range . start ) ,
start : range . start && toTimestamp ( range . start ) ,
@ -188,12 +188,12 @@ function getTimeRangeAsTimestamp() {
} ;
} ;
function toggleHiddenPane ( paneID ) {
function toggleHiddenPane ( paneID ) {
var pane = document . getElementById ( paneID ) ;
const pane = document . getElementById ( paneID ) ;
pane . style . display = pane . style . display === "none" ? "block" : "none" ;
pane . style . display = pane . style . display === "none" ? "block" : "none" ;
} ;
} ;
function toggleUltrawide ( ) {
function toggleUltrawide ( ) {
var body = document . getElementsByTagName ( "Body" ) [ 0 ] ;
const body = document . getElementsByTagName ( "Body" ) [ 0 ] ;
body . classList . contains ( "ultrawide" )
body . classList . contains ( "ultrawide" )
? body . classList . remove ( "ultrawide" )
? body . classList . remove ( "ultrawide" )
: body . classList . add ( "ultrawide" ) ;
: body . classList . add ( "ultrawide" ) ;
@ -201,7 +201,7 @@ function toggleUltrawide() {
function toggleTimeInput ( toggleInput ) {
function toggleTimeInput ( toggleInput ) {
// Get times using current format, then change format, then write them back
// Get times using current format, then change format, then write them back
var range = getTimeRange ( ) ;
const range = getTimeRange ( ) ;
timeFormat = toggleInput ;
timeFormat = toggleInput ;
setTimeRange ( range . start , range . end ) ;
setTimeRange ( range . start , range . end ) ;
} ;
} ;
@ -213,7 +213,7 @@ function setOptions(element, options, selected) {
if ( ! selected && options . length > 0 ) {
if ( ! selected && options . length > 0 ) {
selected = options [ 0 ] ;
selected = options [ 0 ] ;
}
}
options . forEach ( function ( option ) {
options . forEach ( option => {
document . getElementById ( element ) . innerHTML +=
document . getElementById ( element ) . innerHTML +=
'<option value="' +
'<option value="' +
option +
option +
@ -233,14 +233,14 @@ function buildQuery(params) {
} ;
} ;
function loadPlaylist ( isEditor , startTrim , endTrim , defaultQuality ) {
function loadPlaylist ( isEditor , startTrim , endTrim , defaultQuality ) {
var playlist = "/playlist/" + document . getElementById ( "StreamName" ) . value + ".m3u8" ;
const playlist = "/playlist/" + document . getElementById ( "StreamName" ) . value + ".m3u8" ;
var range = getTimeRangeAsTimestamp ( ) ;
const range = getTimeRangeAsTimestamp ( ) ;
var queryString = buildQuery ( range ) ;
const queryString = buildQuery ( range ) ;
// Preserve existing edit times
// Preserve existing edit times
if ( player && player . trimmingControls && player . vhs . playlists . master ) {
if ( player && player . trimmingControls && player . vhs . playlists . master ) {
var discontinuities = mapDiscontinuities ( ) ;
const discontinuities = mapDiscontinuities ( ) ;
if ( ! startTrim ) {
if ( ! startTrim ) {
startTrim = getRealTimeForPlayerTime (
startTrim = getRealTimeForPlayerTime (
discontinuities ,
discontinuities ,
@ -282,21 +282,21 @@ function loadPlaylist(isEditor, startTrim, endTrim, defaultQuality) {
function thrimbletrimmerSubmit ( state , override _changes = false ) {
function thrimbletrimmerSubmit ( state , override _changes = false ) {
document . getElementById ( "SubmitButton" ) . disabled = true ;
document . getElementById ( "SubmitButton" ) . disabled = true ;
var discontinuities = mapDiscontinuities ( ) ;
const discontinuities = mapDiscontinuities ( ) ;
var start = getRealTimeForPlayerTime (
let start = getRealTimeForPlayerTime (
discontinuities ,
discontinuities ,
player . trimmingControls ( ) . options . startTrim
player . trimmingControls ( ) . options . startTrim
) ;
) ;
if ( start ) {
if ( start ) {
start = start . replace ( "Z" , "" ) ;
start = start . replace ( "Z" , "" ) ;
}
}
var end = getRealTimeForPlayerTime ( discontinuities , player . trimmingControls ( ) . options . endTrim ) ;
let end = getRealTimeForPlayerTime ( discontinuities , player . trimmingControls ( ) . options . endTrim ) ;
if ( end ) {
if ( end ) {
end = end . replace ( "Z" , "" ) ;
end = end . replace ( "Z" , "" ) ;
}
}
var wubData = {
const wubData = {
video _start : start ,
video _start : start ,
video _end : end ,
video _end : end ,
video _title : document . getElementById ( "VideoTitle" ) . value ,
video _title : document . getElementById ( "VideoTitle" ) . value ,
@ -326,10 +326,9 @@ function thrimbletrimmerSubmit(state, override_changes = false) {
wubData . token = user . getAuthResponse ( ) . id _token ;
wubData . token = user . getAuthResponse ( ) . id _token ;
}
}
if ( override _changes ) {
if ( override _changes ) {
wubData ["override_changes" ] = true ;
wubData .override _changes = true ;
}
}
console . log ( wubData ) ;
console . log ( "Submitting" , wubData ) ;
console . log ( JSON . stringify ( wubData ) ) ;
if ( ! wubData . video _start ) {
if ( ! wubData . video _start ) {
alert ( "No start time set" ) ;
alert ( "No start time set" ) ;
@ -341,7 +340,7 @@ function thrimbletrimmerSubmit(state, override_changes = false) {
}
}
//Submit to thrimshim
//Submit to thrimshim
var rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
const rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
fetch ( "/thrimshim/" + rowId , {
fetch ( "/thrimshim/" + rowId , {
method : "POST" ,
method : "POST" ,
headers : {
headers : {
@ -352,13 +351,14 @@ function thrimbletrimmerSubmit(state, override_changes = false) {
} ) . then ( response =>
} ) . then ( response =>
response . text ( ) . then ( text => {
response . text ( ) . then ( text => {
if ( ! response . ok ) {
if ( ! response . ok ) {
var error = response . statusText + ": " + text ;
if ( response . status == 409 ) {
if ( response . status == 409 ) {
dialogue = text + "\nClick Ok to submit anyway; Click Cancel to return to editing" ;
dialogue = text + "\nClick Ok to submit anyway; Click Cancel to return to editing" ;
if ( confirm ( dialogue ) ) {
if ( confirm ( dialogue ) ) {
thrimbletrimmerSubmit ( state , true ) ;
thrimbletrimmerSubmit ( state , true ) ;
}
}
} else {
} else {
const error = response . statusText + ": " + text ;
console . log ( "Failed to submit:" , error ) ;
alert ( error ) ;
alert ( error ) ;
}
}
} else if ( state == "EDITED" ) {
} else if ( state == "EDITED" ) {
@ -372,13 +372,13 @@ function thrimbletrimmerSubmit(state, override_changes = false) {
} ;
} ;
function thrimbletrimmerDownload ( isEditor ) {
function thrimbletrimmerDownload ( isEditor ) {
var range = getTimeRangeAsTimestamp ( ) ;
const range = getTimeRangeAsTimestamp ( ) ;
if ( isEditor ) {
if ( isEditor ) {
if ( player . trimmingControls ( ) . options . startTrim >= player . trimmingControls ( ) . options . endTrim ) {
if ( player . trimmingControls ( ) . options . startTrim >= player . trimmingControls ( ) . options . endTrim ) {
alert ( "End Time must be greater than Start Time" ) ;
alert ( "End Time must be greater than Start Time" ) ;
return ;
return ;
}
}
var discontinuities = mapDiscontinuities ( ) ;
const discontinuities = mapDiscontinuities ( ) ;
range . start = getRealTimeForPlayerTime (
range . start = getRealTimeForPlayerTime (
discontinuities ,
discontinuities ,
player . trimmingControls ( ) . options . startTrim
player . trimmingControls ( ) . options . startTrim
@ -389,7 +389,7 @@ function thrimbletrimmerDownload(isEditor) {
) ;
) ;
}
}
var targetURL =
const targetURL =
"/cut/" +
"/cut/" +
document . getElementById ( "StreamName" ) . value +
document . getElementById ( "StreamName" ) . value +
"/" +
"/" +
@ -411,18 +411,17 @@ function thrimbletrimmerDownload(isEditor) {
// Always allow holes in non-editor, accidentially including holes isn't important
// Always allow holes in non-editor, accidentially including holes isn't important
allow _holes : isEditor ? String ( document . getElementById ( "AllowHoles" ) . checked ) : "true" ,
allow _holes : isEditor ? String ( document . getElementById ( "AllowHoles" ) . checked ) : "true" ,
} ) ;
} ) ;
console . log ( targetURL ) ;
document . getElementById ( "DownloadLink" ) . href = targetURL ;
document . getElementById ( "DownloadLink" ) . href = targetURL ;
document . getElementById ( "DownloadLink" ) . style . display = "" ;
document . getElementById ( "DownloadLink" ) . style . display = "" ;
} ;
} ;
function thrimbletrimmerManualLink ( ) {
function thrimbletrimmerManualLink ( ) {
document . getElementById ( "ManualButton" ) . disabled = true ;
document . getElementById ( "ManualButton" ) . disabled = true ;
var rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
const rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
var upload _location = document . getElementById ( "ManualYoutube" ) . checked
const upload _location = document . getElementById ( "ManualYoutube" ) . checked
? "youtube-manual"
? "youtube-manual"
: "manual" ;
: "manual" ;
var body = {
const body = {
link : document . getElementById ( "ManualLink" ) . value ,
link : document . getElementById ( "ManualLink" ) . value ,
upload _location : upload _location ,
upload _location : upload _location ,
} ;
} ;
@ -439,8 +438,8 @@ function thrimbletrimmerManualLink() {
} ) . then ( response =>
} ) . then ( response =>
response . text ( ) . then ( text => {
response . text ( ) . then ( text => {
if ( ! response . ok ) {
if ( ! response . ok ) {
var error = response . statusText + ": " + text ;
const error = response . statusText + ": " + text ;
console . log ( error ) ;
console . log ( "Failed to set manual link:" , error ) ;
alert ( error ) ;
alert ( error ) ;
document . getElementById ( "ManualButton" ) . disabled = false ;
document . getElementById ( "ManualButton" ) . disabled = false ;
} else {
} else {
@ -454,7 +453,7 @@ function thrimbletrimmerManualLink() {
} ;
} ;
function thrimbletrimmerResetLink ( force ) {
function thrimbletrimmerResetLink ( force ) {
var rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
const rowId = /id=(.*)(?:&|$)/ . exec ( document . location . search ) [ 1 ] ;
if (
if (
force &&
force &&
! confirm (
! confirm (
@ -469,7 +468,7 @@ function thrimbletrimmerResetLink(force) {
}
}
document . getElementById ( "ResetButton" ) . disabled = true ;
document . getElementById ( "ResetButton" ) . disabled = true ;
document . getElementById ( "CancelButton" ) . disabled = true ;
document . getElementById ( "CancelButton" ) . disabled = true ;
var body = { } ;
const body = { } ;
if ( ! ! user ) {
if ( ! ! user ) {
body . token = user . getAuthResponse ( ) . id _token ;
body . token = user . getAuthResponse ( ) . id _token ;
}
}
@ -483,8 +482,8 @@ function thrimbletrimmerResetLink(force) {
} ) . then ( response =>
} ) . then ( response =>
response . text ( ) . then ( text => {
response . text ( ) . then ( text => {
if ( ! response . ok ) {
if ( ! response . ok ) {
var error = response . statusText + ": " + text ;
const error = response . statusText + ": " + text ;
console . log ( error ) ;
console . log ( "Failed to reset:" , error ) ;
alert ( error ) ;
alert ( error ) ;
document . getElementById ( "ResetButton" ) . disabled = false ;
document . getElementById ( "ResetButton" ) . disabled = false ;
document . getElementById ( "CancelButton" ) . disabled = true ;
document . getElementById ( "CancelButton" ) . disabled = true ;
@ -510,6 +509,6 @@ function tags_string_to_list(tag_string) {
} ;
} ;
function round _trip _tag _string ( ) {
function round _trip _tag _string ( ) {
var element = document . getElementById ( "VideoTags" ) ;
const element = document . getElementById ( "VideoTags" ) ;
element . value = tags _list _to _string ( tags _string _to _list ( element . value ) ) ;
element . value = tags _list _to _string ( tags _string _to _list ( element . value ) ) ;
} ;
} ;