-
-
Save anonymous/ed1fe37f0fd8977d2a08340c81d3ae64 to your computer and use it in GitHub Desktop.
Youtube Interface - DataFormat Conversion
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
<?php | |
function splitAndParse($str){ | |
$a = explode(',', $str); | |
$c = []; | |
foreach ($a as $itm){ | |
$pItm = []; | |
parse_str($itm, $pItm); | |
$c[] = $pItm; | |
} | |
return $c; | |
} | |
function parseStr($str){ | |
$a = []; | |
parse_str($str, $a); | |
return $a; | |
} | |
$vid = $_GET['v']; | |
$url = "https://www.youtube.com/get_video_info?video_id=".$vid."&el=detailpage&hl=en_US&c=WEB"; | |
$data = file_get_contents($url); | |
$out = []; | |
parse_str($data, $out); | |
$out['adaptive_fmts'] = splitAndParse($out['adaptive_fmts']); | |
$out['rvs'] = splitAndParse($out['rvs']); | |
$out['url_encoded_fmt_stream_map'] = splitAndParse($out['url_encoded_fmt_stream_map']); | |
$out['fflags'] = parseStr($out['fflags']); | |
$out['fmt_list'] = explode(',', $out['fmt_list']); | |
header('Content-Type: application/json'); | |
echo(json_encode($out, JSON_PRETTY_PRINT)); | |
?> |
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
<!DOCTYPE html> | |
<html lang="en" ng-app="app"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Test Script | Details</title> | |
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.9.1/polyfill.js"></script> | |
<!--[if lt IE 9]> | |
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script> | |
<script type="application/javascript" src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | |
<![endif]--> | |
<!--[if lte IE 8]> | |
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/selectivizr/1.0.2/selectivizr-min.js"></script> | |
<![endif]--> | |
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> | |
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script> | |
<script type="application/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.5/ace.js"></script> | |
</head> | |
<body ng-controller="MainCtl as main"> | |
<pre id="viewer"></pre> | |
<style type="text/css"> | |
html, body, #viewer { display: block; height: 100%; width: 100%; margin: 0px 0px 0px 0px; } | |
html, body { padding: 0px 0px 0px 0px; } | |
</style> | |
<script type="application/javascript"> | |
window.JsonEditor = function(id){ | |
var e = ace.edit(id); | |
e.setTheme('ace/theme/chaos'); | |
e.getSession().setMode('ace/mode/json'); | |
$('#'+id).data('AceEditor', e); | |
return e; | |
}; | |
window.appInstance =(function(){ | |
var app = angular.module('app', []); | |
app.controller('MainCtl', function($http){ | |
var main = this; | |
var vid = (function(){ var query = window.location.search.substr(1); return (query != "") ? query : "vtBqTFsiLxM"; })(); | |
$http.get('/yt/details?v='+vid).then(function(response){ | |
var details = response.data; | |
var jsonTxt = angular.toJson(details, true); | |
$('#viewer').text(jsonTxt); | |
main['video'] = {"id": vid, "details": details}; | |
main['editor'] = new JsonEditor('viewer'); | |
}); | |
window.main = main; | |
console.log(main); | |
}); | |
return app; | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment