sup i made a thing because youtube the website, youtube the app, and all other android youtube apps suck balls
http://webspekt.de:8567/https://www.youtube.com/watch?v=Uqza3rZxqIsprerequisites:
vanilla node.js 12 and ./youtube-dl
you can also use the youtube-dl command but you need to change it in the code
var spawn = require('child_process').spawn;
var fs = require("fs");
var serial=0;
var http = require('http');
var server = http.createServer(function (req, res) {
serial++;
var s = serial;
//clear the downloads directory when you restart the app or it will show the wrong videos.
var file = "downloads/temp"+s+".mp4";
var grep = spawn('./youtube-dl',["-o", file, req.url.substring(1)]);
grep.on('close', function (code, signal) {
var fileStream = fs.createReadStream(file);
var mimeType = "video/mp4";
pipeReadstream ( req, res, fileStream, mimeType, function ( err ) {
console.log(err);
});
});
});
server.listen(8567);
// pipe some stream as HTTP response
function pipeReadstream( req, res, readStream, mimeType, cb ) {
var headWritten = false;
readStream.on('data', function(data) {
if ( !headWritten ) {
res.writeHead(200, {'Content-Type': mimeType });
headWritten = true;
}
var flushed = res.write( data );
// Pause the read stream when the write stream gets saturated
if( !flushed ){
readStream.pause();
}
});
res.on('drain', function() {
// Resume the read stream when the write stream gets hungry
readStream.resume();
});
readStream.on('end', function() {
res.end();
});
readStream.on('error', function(err) {
cb ( err );
});
}
i will make it better someday but now i have to gooo