app.js
const request = require('request');
app.post("/getYoutube", (req, res) => {
const cookies = "lang=en; _ga=GA1.2.1682187592.1407390651; _dc=1;";
const options = {
url : "http://en.savefrom.net/savefrom.php",
form: {
sf_url: req.body.sf_url,
sf_submit: ""
},
method: "POST",
headers: {
"Cache-Control" : "max-age=0",
"Connection" : "keep-alive",
"Content-Type" : 'application/x-www-form-urlencoded',
"Host" : "en.savefrom.net",
"Referer" : "http://en.savefrom.net",
"Origin" : "http://en.savefrom.net",
"Cookie" : cookies
}
};
const sRequest = request(options, (request, incomingMessage, responseBody) => {
res.send(responseBody);
sRequest.end();
});
});
html & JS
<div class="youtubeArea">
<div class="clearfix">
<div class="tarea-wrap">
<input type="text" name="sf_url" id="sf_url" value="" placeholder="Enter the URL" >
</div>
<button type="submit" onclick="getYoutube()">Download</button>
</div>
<div class="box clearfix"></div>
</div>
<div id="dummy" style="display:none"></div>
<script type="text/javascript">
function getYoutube(){
var params = {
"sf_url" : $("#sf_url").val()
};
$(".spinner, .dimd").show()
$.post("/getYoutube", params, function(data){
gResult = "";
data = data.split(';');
data[data.length - 3] = '';
data[data.length - 4] = "gResult = " + data[data.length - 4].replace("var", "");
data = data.join(';');
data = data.replace("(function(){", "").replace("})();", "");
$('#dummy').empty();
$('#dummy').append(data);
gResult = decodeURIComponent(gResult).split(';');
while(gResult.pop() == ""){};
gResult = gResult.join(';');
gResult = eval(gResult);
gResult = decodeURIComponent(gResult);
gResult = JSON.parse(gResult.match(/window.parent.sf.videoResult.show\((.*)\);/)[1]);
var downloadFlag = false;
$.each(gResult.url, function(index, url) {
if(downloadFlag) return;
if(url.name == "MP4") {
downloadFlag = true;
location.href = url.url;
}
});
})
.always(function(){ $(".spinner, .dimd").hide() })
}
</script>