Skip to content

Instantly share code, notes, and snippets.

@ftence ftence/serve_data.mc2
Last active Nov 5, 2019

Embed
What would you like to do?
Serve movie data
// 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
You can’t perform that action at this time.