Skip to content

Instantly share code, notes, and snippets.

@x1unix
Created December 9, 2016 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x1unix/73a6a02f4bb510d1b3b13abee1bd409f to your computer and use it in GitHub Desktop.
Save x1unix/73a6a02f4bb510d1b3b13abee1bd409f to your computer and use it in GitHub Desktop.
Moonwalk Grabber
<?php
function grabPOST($url, $postDATA, $iOS = true) {
$ch = curl_init();
$ua = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';
if ($iOS!==false) curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postDATA);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt');
curl_setopt($ch, CURLOPT_REFERER, $url);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}
function grabGET($url, $iOS = true) {
$ch = curl_init();
$ua = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';
if ($iOS!==false) curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookie.txt');
curl_setopt($ch, CURLOPT_REFERER, $url);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}
echo "\n-\n";
$frameURL = "http://moonwalk.cc/video/3fc0db3c343e62c97fed4dd48b6e91bb/iframe";
$res = grabGET($frameURL);
preg_match("/video_token: \'([^\']+)\'/is", $res, $m);
if (!empty($m[1])) $token = trim($m[1]); else exit("No token\n");
echo "Token Found: ".$token."\n\n";
$res = grabPOST('http://moonwalk.cc/sessions/create', array('video_token'=>$token));
preg_match("/\"manifest_m3u8\":\"([^\"]+)\"/is", $res, $m);
if (!empty($m[1])) $manifest = trim($m[1]); else exit("No session started\n");
echo "Manifest Found: ".$manifest."\n\n";
$dirname = pathinfo($manifest);
$dirname = $dirname['dirname'];
$res = grabGET($manifest);
$resUNZIP = gzdecode($res);
if (!empty($resUNZIP)) $res = $resUNZIP;
print_r($res);
preg_match_all("/RESOLUTION=([^,]+),/is", $res, $m);
$res = explode("\n", $res);
foreach($res as $v) {
if (!empty($v)) {
if ($v[0]!='#') $t[] = $v;
}
}
foreach($t as $k=>$v) {
$tracks[] = Array('resolution' => $m[1][$k], 'track' => $dirname.'/'.$v);
}
print_r($tracks[0]);
unset($t);
// maybe compare resolution ang get better?
$res = grabGET($tracks[0]['track']);
$resUNZIP = gzdecode($res);
if (!empty($resUNZIP)) $res = $resUNZIP;
$res = explode("\n", $res);
foreach($res as $v) {
if (!empty($v)) {
if ($v[0]!='#') $t[] = $dirname.'/'.$v;
}
}
foreach($t as $k=>$v) {
file_put_contents("bb-1-3.mp4", file_get_contents($v), FILE_APPEND);
echo $k." from ".intval(count($t)-1)."\n";
}
echo "\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment