diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-31 13:08:31 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-31 13:08:31 +0200 |
commit | 6eaa0169f9da659cab431aaf49367a0075bba5d7 (patch) | |
tree | 348961bc17d267d20e561681cc6f70717fff1d19 | |
parent | 9ca1bd5cdaeb199c99faa892fe4911a85e9fbe29 (diff) |
First public version w/o video, mp3 up to 30MB
-rw-r--r-- | debian/README.Debian | 33 | ||||
-rw-r--r-- | debian/control | 1 | ||||
-rw-r--r-- | downtube.cpp | 33 | ||||
-rw-r--r-- | html/index.html | 2 | ||||
-rw-r--r-- | webserver.conf.example | 8 |
5 files changed, 72 insertions, 5 deletions
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 + + <path requested="/downtube"> + <plugin>static-files</plugin> + <target>/usr/lib/downtube/html</target> + </path> + <path requested="/downtube/downtube.fcgi"> + <plugin>fcgi</plugin> + <target>127.0.0.1:9004</target> + </path> + +* 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:<br/> <input type="radio" id="mp3" name="format" value="mp3" checked> <label for="mp3">MP3 (Audio)</label><br> - <input type="radio" id="mp4" name="format" value="mp4"> + <input type="radio" id="mp4" name="format" value="mp4" disabled> <label for="mp4">MP4 (Video)</label><br> </p> 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 @@ + <path requested="/downtube"> + <plugin>static-files</plugin> + <target>/usr/lib/downtube/html</target> + </path> + <path requested="/downtube/downtube.fcgi"> + <plugin>fcgi</plugin> + <target>127.0.0.1:9004</target> + </path> |