Last active
November 5, 2019 15:23
-
-
Save ftence/9d2d8b9fa657f6d2508a9e057c1e325e to your computer and use it in GitHub Desktop.
Serve movie data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Constants | |
'YOUR_READ_TOKEN' 'TOKEN' STORE | |
50 'SPLITS' STORE | |
'http://127.0.0.1:8080/api/v0/exec' 'data_warp10_url' STORE | |
{ | |
'path' '/warpflix/data' | |
'prefix' false // Only respond to http(s)://endpoint/warpflix/data | |
'macro' | |
<% | |
<% | |
'request' STORE // Store the request map | |
$request 'params' GET 'params' STORE // Store the parameters map | |
$params 'end' GET 'end' STORE | |
$params 'start' GET 'start' STORE | |
$end ISNULL $start ISNULL OR // If either start or end are unspecified, this is a request for the init segment | |
<% | |
// Return the init segment | |
'0' 'track' STORE | |
0 'end' STORE | |
-1 'timespan' STORE | |
%> | |
<% | |
'~[12]' 'track' STORE // Fetch the two tracks | |
$end 0 GET TOLONG 'end' STORE | |
$start 0 GET TOLONG 'start' STORE | |
$end $start - | |
1 + // Add 1 to include $start in FETCH | |
'timespan' STORE | |
%> | |
IFTE | |
// Fetch the data on a remote instance | |
<' | |
[ | |
'{{{token}}}' | |
'what_is_warp_10.mp4' | |
{ 'track' '{{{track}}}' } | |
{{{end}}} {{{timespan}}} | |
] FETCH | |
'> | |
{ 'token' !$TOKEN 'track' $track 'end' $end 'timespan' $timespan } TEMPLATE | |
!$data_warp10_url | |
REXECZ | |
SORT // Sort by tick | |
<% LABELS 'track' GET TOLONG %> SORTBY // SORT by track number | |
// Join all the values | |
VALUES FLATTEN | |
'' JOIN | |
// Convert the joint values to a byte array. | |
'ISO-8859-1' ->BYTES | |
'data' STORE | |
// Return the data as octet-stream | |
{ | |
'status' 200 | |
'headers' | |
{ | |
'Content-Type' 'application/octet-stream' | |
'Access-Control-Allow-Origin' '*' | |
} | |
'body' $data | |
} | |
%> | |
<% | |
// If there is an error, display it as a JSON | |
{ | |
'status' 500 | |
'headers' | |
{ | |
'Content-Type' 'application/json' | |
'Access-Control-Allow-Origin' '*' | |
} | |
'body' { 'error' ERROR } ->JSON | |
} | |
%> | |
<% %> | |
TRY | |
%> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment