summaryrefslogtreecommitdiff
path: root/modules/ytdl
diff options
context:
space:
mode:
Diffstat (limited to 'modules/ytdl')
-rwxr-xr-xmodules/ytdl/youtube-dl-Darwinbin0 -> 1149466 bytes
-rw-r--r--modules/ytdl/ytdl.html45
-rw-r--r--modules/ytdl/ytdl.js31
3 files changed, 76 insertions, 0 deletions
diff --git a/modules/ytdl/youtube-dl-Darwin b/modules/ytdl/youtube-dl-Darwin
new file mode 100755
index 0000000..97238a0
--- /dev/null
+++ b/modules/ytdl/youtube-dl-Darwin
Binary files 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 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>YTDL</title>
+<script>
+function retrieve_link(){
+ var link=document.getElementById("inputlink").value;
+ var xhr=new XMLHttpRequest();
+ xhr.addEventListener("readystatechange",function(){
+ if(xhr.readyState<4){
+ show_output(["(waiting to send)","(request opened)","(headers received)","(loading)"][xhr.readyState]);
+ }
+ if(xhr.readyState!=4)return;
+ var response;
+ if(xhr.responseText==null)response="(null)";
+ else response=xhr.responseText;
+ show_output(response,/^https?:\/\//.test(response));
+ });
+ xhr.open("GET","/ytdl/"+encodeURIComponent(link));
+ xhr.send();
+}
+
+function show_output(text,link){
+ var output=document.getElementById("output");
+ if(output.firstChild)output.removeChild(output.firstChild);
+ var e;
+ if(link){
+ e=document.createElement("a");
+ e.href=text;
+ e.appendChild(document.createTextNode(text));
+ } else e=document.createTextNode(text);
+ output.appendChild(e);
+}
+</script>
+</head>
+<body>
+<h1>YTDL</h1>
+<p>This page uses the <code>youtube-dl</code> utility to provide a download link for a given youtube video. It just selects whatever format <code>youtube-dl</code> considers "best"; this is normally video+audio, in the highest quality provided by YouTube.
+Enter a link or a video id below:</p>
+<input type="text" id="inputlink" size="100"><br>
+<input type="button" value="Retrieve link" onclick="retrieve_link()"><br>
+<pre id="output" style="width:100%;word-wrap:break-word;"></pre>
+</body>
+</html>
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);
+ });
+ });
+};