youtube proxy - easier than expecte · 2015-03-03 16:00
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=Uqza3rZxqIs
prerequisites:
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
Anonymous · 2015-03-03 22:19
This seems pretty nice. Why didn't you put it up on /lam/?
Anonymous · 2015-03-03 23:52
>>476
oops. uhm, my bad.
yeah i just wanted to show you guys how useful and easy node.js is for shuffling interwebs from one place to the other.
better filenames
var file = "downloads/"+req.url.substring(1).replace(/.*?watch\?v=([0-9A-Za-z]+)/, "$1").substring(0,11)+".mp4";
Anonymous · 2015-03-04 23:34
new version
you can now optionally add a file extension, e.g. mp4, mp3,opus or others that are supported by youtube-dl to the end of the url like so
https://yt.webspekt.de/https://www.youtube.com/watch?v=Uqza3rZxqIs.mp3
also youtube-dl supports lots of other video serving websites which can now be used the same way
if could make a git but it's not worth it yet
Anonymous · 2015-03-04 23:35
var spawn = require('child_process').spawn;
var fs = require("fs");
var http = require('http');
var mime=require("mime");
var server = http.createServer(function (req, res) {
var format = req.url.replace(/\/(.*)\.(.*?)/, "$2");
var url = req.url.replace(/\/(.*)\.(.*?)/, "$1");
if ( ! /^.*\.[a-z0-9]{3,5}$/.test(req.url) ) {
format="mp4";
url = req.url.replace(/\/(.*)/, "$1");
}
var file = url.replace(/[\/:?!&?=\.]/g, "")+"."+format;
var mimeType=mime.lookup(file);
var args = ["-o", "downloads/"+file];
if (format==="m4a") {
args.push("-x");
args.push("–audio-format");
args.push(format);
}
else if (format==="mp3") {
args.push("-x");
args.push("–audio-format");
args.push(format);
}
else if (format==="opus") {
args.push("-x");
args.push("–audio-format");
args.push(format);
} else {
args.push("-f");
args.push(format);
}
args.push(url);
var job = spawn('./youtube-dl',args);
console.log(args.join(" "));
job.on('close', function (code, signal) {
var fileStream = fs.createReadStream("downloads/"+file);
pipeReadstream ( req, res, fileStream, mimeType, file, function ( err ) {
console.log(err);
});
});
job.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
job.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
});
server.listen(8567);
// pipe some stream as HTTP response
function pipeReadstream( req, res, readStream, mimeType, filename, cb ) {
var headWritten = false;
readStream.on('data', function(data) {
if ( !headWritten ) {
res.writeHead(200, {'Content-disposition':'attachment; filename='+filename,'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 );
});
}
Anonymous · 2015-03-09 08:27
>>483
How about [code]&fmt=nnn[code]?
Anonymous · 2015-03-09 17:36
>>490
what
Anonymous · 2015-03-09 21:28
>>497
you used to be able to suffix youtube urls with a format code which would determine the video quality, but they dropped support for that a long time ago.
Anonymous · 2015-07-07 04:41
I made a thing using some javascript and youtube embeds. You use it with video/playlist IDs.
http://g4g.x10.mx/yt/yt.html
you can view the js source at http://g4g.x10.mx/yt/yt.js
Anonymous · 2015-07-07 08:22
>>498
youtube-dl has flags to specify quality but i couldnt get them working so i didnt add them
>>831
oh that is very cool! i actually tried feeding youtube playlist entries into my thing but it didnt work (always downloaded the first one or some soykaf) so your thing covers exactly that!
Anonymous · 2015-07-07 08:32
>>831
>so your thing covers exactly that!
well actually not, should look before i post. it's still cool.
there is actually a similar software running on reddit
https://www.reddit.com/r/radd_it/comments/1vjdw9/who_is_uplaylisterbot_and_what_can_it_do/
here is an example to play around with
http://radd.it/r/Cyberpunk/comments/31l9cl/video
it's quite shiny
the idea here was to generate a playlist from a bunch of links so people can watch them hands free
Anonymous · 2015-07-07 08:53
>>834
forgot pic
it's pretty clever.