From 6eaa0169f9da659cab431aaf49367a0075bba5d7 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 31 May 2020 13:08:31 +0200 Subject: First public version w/o video, mp3 up to 30MB --- debian/README.Debian | 33 +++++++++++++++++++++++++++++++++ debian/control | 1 + downtube.cpp | 33 +++++++++++++++++++++++++++++---- html/index.html | 2 +- webserver.conf.example | 8 ++++++++ 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 webserver.conf.example diff --git a/debian/README.Debian b/debian/README.Debian index 1bd0c56..fc40992 100644 --- a/debian/README.Debian +++ b/debian/README.Debian @@ -4,6 +4,39 @@ downtube for Debian This package is the Debian version of downtube. +Configuration +------------- + +* You can add this to /etc/webserver.conf + + + static-files + /usr/lib/downtube/html + + + fcgi + 127.0.0.1:9004 + + +* Enable: + + # systemctl enable downtube.service + +* Start: + + # systemctl start downtube + +* Stop: + + # systemctl stop downtube + +* Query Status: + + # systemctl status downtube + + and observe /var/log/syslog + + Contact ------- diff --git a/debian/control b/debian/control index 854fb77..492d660 100644 --- a/debian/control +++ b/debian/control @@ -9,6 +9,7 @@ Homepage: http://www.reichwein.it/downtube/ Package: downtube Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, spawn-fcgi +Recommends: webserver Homepage: http://www.reichwein.it/downtube/ Description: Web application for video download Downtube can help you download a video specified in a HTML form, transformed diff --git a/downtube.cpp b/downtube.cpp index 93f88ba..b3ed581 100644 --- a/downtube.cpp +++ b/downtube.cpp @@ -120,12 +120,17 @@ int main(void) //FCGX_FPrintF(request.out, "path: %s\r\n", tempDir.getPath().string().c_str()); if (command == "getfilename") { - std::string cmd{"youtube-dl -o '%(title)s."s + format + "' --get-filename --no-call-home --restrict-filenames "s + url + " > filename.txt"}; + //std::string cmd{"youtube-dl -o '%(title)s."s + format + "' --get-filename --no-call-home --restrict-filenames "s + url + " > filename.txt"}; + // Recoding to MP4 is too slow currently. So keep original format for now + std::string cmd{"youtube-dl -o '%(title)s.%(ext)s' --get-filename --no-call-home --restrict-filenames "s + url + " > filename.txt"}; if (system(cmd.c_str())) throw std::runtime_error("Can't guess filename"); std::string filename {File::getFile("filename.txt")}; boost::algorithm::trim(filename); + + if (format == "mp3") + filename = fs::path{filename}.stem().string() + ".mp3"; FCGX_PutS("Content-Type: text/plain\r\n\r\n", request.out); FCGX_FPrintF(request.out, "%s", filename.c_str()); @@ -135,15 +140,35 @@ int main(void) system(cmd.c_str()); // Ignore error - "ERROR: Stream #1:0 -> #0:1 (copy)" - seems to be ok std::string filedata {File::getFile("audio.mp3")}; // may throw + + if (filedata.size() > 30000000) + throw std::runtime_error("File too big"); FCGX_PutS("Content-Type: application/octet-stream\r\n", request.out); FCGX_FPrintF(request.out, "Content-Length: %d\r\n\r\n", filedata.size()); FCGX_PutStr(filedata.c_str(), filedata.size(), request.out); - } else if (format == "mp4") { - std::string cmd{"youtube-dl --no-warnings --no-call-home --no-progress --recode-video mp4 -o video.mp4 --restrict-filenames "s + url}; + } else if (false && format == "mp4") { // disabled for now + //std::string cmd{"youtube-dl --no-warnings --no-call-home --no-progress --recode-video mp4 -o video.mp4 --restrict-filenames "s + url}; + // Recoding to MP4 is too slow currently. So keep original format for now + std::string cmd{"youtube-dl --no-warnings --no-call-home --no-progress -o video.mp4 --restrict-filenames "s + url}; system(cmd.c_str()); // Ignore error + + // youtube-dl gets it wrong and creates, e.g. video.mkv. + // So find it and load it + fs::directory_iterator di{fs::current_path()}; + fs::path filename; + for (const auto& i: di) { + if (i.path().stem().string() == "video"s) { + filename = i.path().filename().string(); + break; + } + } - std::string filedata {File::getFile("video.mp4")}; // may throw + if (filename.empty()) { + throw std::runtime_error("No video file found."); + } + + std::string filedata {File::getFile(filename)}; // may throw FCGX_PutS("Content-Type: application/octet-stream\r\n", request.out); FCGX_FPrintF(request.out, "Content-Length: %d\r\n\r\n", filedata.size()); diff --git a/html/index.html b/html/index.html index 05ab9d6..2892e79 100644 --- a/html/index.html +++ b/html/index.html @@ -22,7 +22,7 @@ Transform to format:

- +

diff --git a/webserver.conf.example b/webserver.conf.example new file mode 100644 index 0000000..2cb0e0a --- /dev/null +++ b/webserver.conf.example @@ -0,0 +1,8 @@ + + static-files + /usr/lib/downtube/html + + + fcgi + 127.0.0.1:9004 + -- cgit v1.2.3