@ -1,4 +1,5 @@
var desertBusStart = new Date ( "1970-01-01T00:00:00Z" ) ;
var desertBusStart = new Date ( "1970-01-01T00:00:00Z" ) ;
var timeFormat = 'BUSTIME' ;
pageSetup = function ( ) {
pageSetup = function ( ) {
//Get values from ThrimShim
//Get values from ThrimShim
@ -15,10 +16,7 @@ pageSetup = function() {
document . getElementById ( "StreamName" ) . value = data . video _channel ;
document . getElementById ( "StreamName" ) . value = data . video _channel ;
document . getElementById ( "hiddenSubmissionID" ) . value = data . id ;
document . getElementById ( "hiddenSubmissionID" ) . value = data . id ;
// set stream start/end, then copy to bustime inputs
setTimeRange ( fromTimestamp ( data . event _start ) , fromTimestamp ( data . event _end ) ) ;
document . getElementById ( "StreamStart" ) . value = data . event _start ;
document . getElementById ( "StreamEnd" ) . value = data . event _end ;
setBustimeRange ( ) ;
// title and description both default to row description
// title and description both default to row description
document . getElementById ( "VideoTitle" ) . value = data . video _title ? data . video _title : data . description ;
document . getElementById ( "VideoTitle" ) . value = data . video _title ? data . video _title : data . description ;
document . getElementById ( "VideoDescription" ) . value = data . video _description ? data . video _description : data . description ;
document . getElementById ( "VideoDescription" ) . value = data . video _description ? data . video _description : data . description ;
@ -54,10 +52,10 @@ pageSetup = function() {
document . getElementById ( "StreamName" ) . value = data . video _channel ;
document . getElementById ( "StreamName" ) . value = data . video _channel ;
setOptions ( 'uploadLocation' , data . upload _locations ) ;
setOptions ( 'uploadLocation' , data . upload _locations ) ;
// Default time range to the last 10min. This is useful for giffers, immediate replay, etc.
// Default time range to the last 10min. This is useful for immediate replay, etc.
document . getElem entByI d( "StreamStart" ) . value = new Date ( new Date ( ) . getTime ( ) - 1000 * 60 * 10 ) . toISOString ( ) . substring ( 0 , 19 ) ;
end = new Date ( ) ;
document . getElementById ( "StreamEnd" ) . value = new Date ( ) . toISOString ( ) . substring ( 0 , 19 ) ;
start = new Date ( end . getTime ( ) - 1000 * 60 * 10 ) ;
set BustimeRange( ) ;
set TimeRange( start , end ) ;
loadPlaylist ( ) ;
loadPlaylist ( ) ;
} ) ;
} ) ;
@ -65,12 +63,13 @@ pageSetup = function() {
}
}
} ;
} ;
timestampToBustime = function ( ts ) {
// Time-formatting functions
date = new Date ( ts + "Z" ) ;
toBustime = function ( date ) {
return ( date < desertBusStart ? "-" : "" ) + videojs . formatTime ( Math . abs ( ( date - desertBusStart ) / 1000 ) , 600.01 ) . padStart ( 7 , "0:" ) ;
return ( date < desertBusStart ? "-" : "" ) + videojs . formatTime ( Math . abs ( ( date - desertBusStart ) / 1000 ) , 600.01 ) . padStart ( 7 , "0:" ) ;
} ;
} ;
bustimeToTimestamp = function ( bustime ) {
fromBustime = function ( bustime ) {
direction = 1 ;
direction = 1 ;
if ( bustime . startsWith ( "-" ) ) {
if ( bustime . startsWith ( "-" ) ) {
bustime = bustime . slice ( 1 ) ;
bustime = bustime . slice ( 1 ) ;
@ -78,17 +77,45 @@ bustimeToTimestamp = function(bustime) {
}
}
parts = bustime . split ( ':' )
parts = bustime . split ( ':' )
bustime _ms = ( parseInt ( parts [ 0 ] ) + parts [ 1 ] / 60 + parts [ 2 ] / 3600 ) * 1000 * 60 * 60 ;
bustime _ms = ( parseInt ( parts [ 0 ] ) + parts [ 1 ] / 60 + parts [ 2 ] / 3600 ) * 1000 * 60 * 60 ;
return new Date ( desertBusStart . getTime ( ) + direction * bustime _ms ) .toISOString ( ) . substring ( 0 , 19 ) ;
return new Date ( desertBusStart . getTime ( ) + direction * bustime _ms ) ;
} ;
} ;
setBustimeRange = function ( ) {
toTimestamp = function ( date ) {
document . getElementById ( "BusTimeStart" ) . value = timestampToBustime ( document . getElementById ( "StreamStart" ) . value ) ;
return date . toISOString ( ) . substring ( 0 , 19 ) ;
document . getElementById ( "BusTimeEnd" ) . value = timestampToBustime ( document . getElementById ( "StreamEnd" ) . value ) ;
}
} ;
setStreamRange = function ( ) {
fromTimestamp = function ( ts ) {
document . getElementById ( "StreamStart" ) . value = bustimeToTimestamp ( document . getElementById ( "BusTimeStart" ) . value ) ;
return new Date ( ts + "Z" ) ;
document . getElementById ( "StreamEnd" ) . value = bustimeToTimestamp ( document . getElementById ( "BusTimeEnd" ) . value ) ;
}
// Set the stream start/end range from a pair of Dates using the current format
// If given null, sets to blank.
setTimeRange = function ( start , end ) {
toFunc = {
UTC : toTimestamp ,
BUSTIME : toBustime ,
} [ timeFormat ] ;
document . getElementById ( "StreamStart" ) . value = ( start ) ? toFunc ( start ) : "" ;
document . getElementById ( "StreamEnd" ) . value = ( end ) ? toFunc ( end ) : "" ;
}
// Get the current start/end range as Dates using the current format
// Returns an object containing 'start' and 'end' fields.
// If either is empty / invalid, returns null.
getTimeRange = function ( ) {
fromFunc = {
UTC : fromTimestamp ,
BUSTIME : fromBustime ,
} [ timeFormat ] ;
convert = function ( value ) {
if ( ! value ) { return null ; }
date = fromFunc ( value ) ;
return ( isNaN ( date ) ) ? null : date ;
} ;
return {
start : convert ( document . getElementById ( "StreamStart" ) . value ) ,
end : convert ( document . getElementById ( "StreamEnd" ) . value ) ,
} ;
}
}
toggleHiddenPane = function ( paneID ) {
toggleHiddenPane = function ( paneID ) {
@ -102,19 +129,10 @@ toggleUltrawide = function() {
}
}
toggleTimeInput = function ( toggleInput ) {
toggleTimeInput = function ( toggleInput ) {
if ( toggleInput == "UTC" ) {
// Get times using current format, then change format, then write them back
setStreamRange ( ) ;
range = getTimeRange ( ) ;
document . getElementById ( "BusTimeStart" ) . style . display = "none" ;
timeFormat = toggleInput ;
document . getElementById ( "BusTimeEnd" ) . style . display = "none" ;
setTimeRange ( range . start , range . end ) ;
document . getElementById ( "StreamStart" ) . style . display = "" ;
document . getElementById ( "StreamEnd" ) . style . display = "" ;
} else {
setBustimeRange ( ) ;
document . getElementById ( "StreamStart" ) . style . display = "none" ;
document . getElementById ( "StreamEnd" ) . style . display = "none" ;
document . getElementById ( "BusTimeStart" ) . style . display = "" ;
document . getElementById ( "BusTimeEnd" ) . style . display = "" ;
}
}
}
// For a given select input element id, add the given list of options.
// For a given select input element id, add the given list of options.
@ -129,19 +147,23 @@ setOptions = function(element, options, selected) {
} ) ;
} ) ;
}
}
buildQuery = function ( params ) {
return Object . keys ( params ) . filter ( key => params [ key ] !== null ) . map ( key =>
encodeURIComponent ( key ) + '=' + encodeURIComponent ( params [ key ] )
) . join ( '&' ) ;
}
loadPlaylist = function ( startTrim , endTrim , defaultQuality ) {
loadPlaylist = function ( startTrim , endTrim , defaultQuality ) {
var playlist = "/playlist/" + document . getElementById ( "StreamName" ) . value + ".m3u8" ;
var playlist = "/playlist/" + document . getElementById ( "StreamName" ) . value + ".m3u8" ;
// If we're using bustime, update stream start/end from it first
var range = getTimeRange ( ) ;
if ( document . getElementById ( "BusTimeToggleBus" ) . checked ) {
var queryString = buildQuery ( {
setStreamRange ( ) ;
// if not null, format as timestamp
}
start : range . start && toTimestamp ( range . start ) ,
end : range . end && toTimestamp ( range . end ) ,
var streamStart = document . getElementById ( "StreamStart" ) . value ? "start=" + document . getElementById ( "StreamStart" ) . value : null ;
} ) ;
var streamEnd = document . getElementById ( "StreamEnd" ) . value ? "end=" + document . getElementById ( "StreamEnd" ) . value : null ;
var queryString = ( streamStart || streamEnd ) ? "?" + [ streamStart , streamEnd ] . filter ( ( a ) => ! ! a ) . join ( "&" ) : "" ;
setupPlayer ( playlist + queryString , startTrim , endTrim ) ;
setupPlayer ( playlist + '?' + queryString , startTrim , endTrim ) ;
//Get quality levels for advanced properties.
//Get quality levels for advanced properties.
document . getElementById ( 'qualityLevel' ) . innerHTML = "" ;
document . getElementById ( 'qualityLevel' ) . innerHTML = "" ;
@ -215,9 +237,11 @@ thrimbletrimmerDownload = function() {
var targetURL = "/cut/" + document . getElementById ( "StreamName" ) . value +
var targetURL = "/cut/" + document . getElementById ( "StreamName" ) . value +
"/" + document . getElementById ( 'qualityLevel' ) . options [ document . getElementById ( 'qualityLevel' ) . options . selectedIndex ] . value + ".ts" +
"/" + document . getElementById ( 'qualityLevel' ) . options [ document . getElementById ( 'qualityLevel' ) . options . selectedIndex ] . value + ".ts" +
"?start=" + downloadStart +
"?" + buildQuery ( {
"&end=" + downloadEnd +
start : downloadStart ,
"&allow_holes=" + String ( document . getElementById ( 'AllowHoles' ) . checked ) ;
end : downloadEnd ,
allow _holes : String ( document . getElementById ( 'AllowHoles' ) . checked ) ,
} ) ;
console . log ( targetURL ) ;
console . log ( targetURL ) ;
document . getElementById ( 'outputFile' ) . src = targetURL ;
document . getElementById ( 'outputFile' ) . src = targetURL ;
}
}