From f00ba92ed2cc1a9c24ad783e83525d1b5a85b857 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Tue, 13 Sep 2016 11:43:06 +0200 Subject: Initial --- modules/ytdl/youtube-dl-Darwin | Bin 0 -> 1149466 bytes modules/ytdl/ytdl.html | 45 +++++++++++++++++++++++++++++++++++++++++ modules/ytdl/ytdl.js | 31 ++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100755 modules/ytdl/youtube-dl-Darwin create mode 100644 modules/ytdl/ytdl.html create mode 100644 modules/ytdl/ytdl.js (limited to 'modules/ytdl') diff --git a/modules/ytdl/youtube-dl-Darwin b/modules/ytdl/youtube-dl-Darwin new file mode 100755 index 0000000..97238a0 Binary files /dev/null and b/modules/ytdl/youtube-dl-Darwin differ diff --git a/modules/ytdl/ytdl.html b/modules/ytdl/ytdl.html new file mode 100644 index 0000000..e054b97 --- /dev/null +++ b/modules/ytdl/ytdl.html @@ -0,0 +1,45 @@ + + + + +YTDL + + + +

YTDL

+

This page uses the youtube-dl utility to provide a download link for a given youtube video. It just selects whatever format youtube-dl considers "best"; this is normally video+audio, in the highest quality provided by YouTube. +Enter a link or a video id below:

+
+
+

+
+
diff --git a/modules/ytdl/ytdl.js b/modules/ytdl/ytdl.js
new file mode 100644
index 0000000..3bbea16
--- /dev/null
+++ b/modules/ytdl/ytdl.js
@@ -0,0 +1,31 @@
+var cmn=require("../$common.js"),
+    child_process=require("child_process");
+
+module.exports=function(app,io,moddir){
+	app.param("ytdl_id",function(req,res,next,link){
+		link=unescape(link);
+		req.params.ytdl_id=link;
+		if(/['"\x00-\x1f]/.test(link)){
+			res.status(400).end("Invalid youtube link or id");
+			return;
+		}
+		next();
+	});
+	app.get("/ytdl",function(req,res){
+		res.sendFile(moddir+"/ytdl.html");
+	});
+	app.get("/ytdl/:ytdl_id",function(req,res){
+		var link=req.params.ytdl_id;
+		var cp=child_process.execFile("/usr/bin/env",["youtube-dl","-gf","best",link],{},function(err,stdout,stderr){
+			if(err){
+				//console.log(err);
+				res.status(404);
+				res.set("Content-Type","text/plain");
+				res.end("Youtube video id not found\n\n"+stdout+"\n\n"+stderr);
+				return;
+			}
+			res.set("Content-Type","text/plain");
+			res.send(stdout);
+		});
+	});
+};
-- 
cgit v1.2.3-70-g09d2