]> git.ekhem.eu.org Git - server.git/commitdiff
[miniflux] Download entries with ydlpd.
authorJakub Czajka <jakub@ekhem.eu.org>
Wed, 18 Dec 2024 15:58:41 +0000 (16:58 +0100)
committerJakub Czajka <jakub@ekhem.eu.org>
Wed, 18 Dec 2024 15:58:41 +0000 (16:58 +0100)
miniflux/download.sh [new file with mode: 0755]
miniflux/rss.conf
miniflux/ydlpd.sh [new file with mode: 0755]

diff --git a/miniflux/download.sh b/miniflux/download.sh
new file mode 100755 (executable)
index 0000000..88d62a5
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Copyright (c) 2024 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+#
+# Clicking on the "Download" button on entry's page sends a POST request to
+# /entry/download/<entry_id>. This script resolves the <entry_id> to an <url>
+# and redirects the client to /ydlpd?url=<url> with HTTP 303 See Other [1]. This
+# causes the client to automatically send a GET request to that address.
+#
+# [1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303
+
+. /etc/environment
+
+VIDEO=$(/usr/bin/psql --user=miniflux \
+                      --dbname=${RSS_DB} \
+                      --tuples-only \
+                      --no-align \
+                      --command="
+SELECT url
+FROM entries
+WHERE id = ${ENTRY_ID}")
+
+echo "HTTP/1.1 303 See Other"
+echo "Location: /ydlpd?url=${VIDEO}"
+echo "Content-Type: text/html; charset=UTF-8"
+echo "Content-Length: 0"
+echo ""
index dbe0a09988e234fbe7739fcf169eae84f2a941a2..9cc60e6029c6b4f1dfe77adc4c7e91410a870e34 100644 (file)
@@ -15,6 +15,26 @@ server {
 
     root ${prod_dir}/${rss};
 
+    location ~ ^/entry/download/(\d+)$ {
+        include fastcgi_params;
+        fastcgi_pass unix:/var/run/fcgiwrap.socket;
+
+        fastcgi_read_timeout 30;
+
+        fastcgi_param ENTRY_ID ${dollar}1;
+        fastcgi_param SCRIPT_FILENAME ${dollar}document_root/download.sh;
+    }
+
+    location ~ ^/ydlpd(.*)$ {
+        include fastcgi_params;
+        fastcgi_pass unix:/var/run/fcgiwrap.socket;
+
+        fastcgi_read_timeout 30;
+
+        fastcgi_param URL ${dollar}arg_url;
+        fastcgi_param SCRIPT_FILENAME ${dollar}document_root/ydlpd.sh;
+    }
+
     location / {
         proxy_pass http://127.0.0.1:4080;
         proxy_redirect off;
diff --git a/miniflux/ydlpd.sh b/miniflux/ydlpd.sh
new file mode 100755 (executable)
index 0000000..3f3b3fa
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Copyright (c) 2024 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+#
+# If user downloads entry's page, miniflux embeds the HTML. The response needs to
+# have the following format [1]:
+#
+# {
+#   "content": "<page's HTML>",
+#   "reading_time": "<integer>"
+# }
+#
+# Moreover, the HTML embeded in JSON needs to have '\n' instead of new lines.
+# This script returns a HTML form to select the format for download and passes
+# it alongside video's URL to ydlpd for download.
+#
+# [1] https://github.com/miniflux/v2/blob/main/internal/ui/static/js/app.js#L355
+
+. /etc/environment
+
+PAGE=$(echo "\
+<form id='ydlpd' action='https://yt.${private_domain}/download'>
+  <fieldset>
+    <input type='text' id='url' name='url' value='${URL}' required />
+    <div class='container'>
+      <select id='format' name='format'>
+        <option value=''>--Select format--</option>
+        <option value='video'>video</option>
+        <option value='audio'>audio</option>
+      </select>
+      <button type='submit'>Download</button>
+    </div>
+  </fieldset>
+</form>" | sed 's/^[ \t]*//g')
+
+echo "HTTP/1.1 200 OK"
+echo "Content-type: text/json"
+echo ""
+echo -n "{\"content\": \"${PAGE}\"" | sed --null-data 's/\n/\\n/g'
+echo -n ", \"reading_time\": \"1\"}"