Add a search DCGI inspired by idiotbox - gophercgis - Collection of gopher CGI/DCGI for geomyidae
(HTM) hg clone https://bitbucket.org/iamleot/gophercgis
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) changeset ea292405584756dd47a3580622af8b5f46a6c05d
(DIR) parent d5d8d32687f0a546da5e0e0aaf9d41437ec9b0e6
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sat, 15 Sep 2018 23:43:04
Add a search DCGI inspired by idiotbox
Diffstat:
youtube/search.dcgi | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 76 insertions(+), 0 deletions(-)
---
diff -r d5d8d32687f0 -r ea2924055847 youtube/search.dcgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/youtube/search.dcgi Sat Sep 15 23:43:04 2018 +0200
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+SEARCH_CGI="/cgi/youtube/search.dcgi"
+
+if [ -n "$1" ]; then
+ query=$(printf "%s" "$1" | vis -h)
+ url="https://www.youtube.com/results?search_query=${query}"
+fi
+
+if [ -n "$2" ]; then
+ url="https://www.youtube.com$2"
+fi
+
+echo "t"
+echo "tYouTube"
+echo "t"
+
+/usr/pkg/bin/curl -H 'Accept-Language: en-US' -Ls -- "${url}" |
+awk '
+/<h3 class="yt-lockup-title ">/ {
+ if (!match($0, /href="\/watch\?v=[^"]+"/)) {
+ next
+ }
+
+ video_id = substr($0, RSTART + 15, RLENGTH - 16)
+
+ # ignore non-video (i.e. playlist/channel)
+ if (length(video_id) != 11) {
+ next
+ }
+
+ match($0, /title="[^"]+"/)
+ title = substr($0, RSTART + 7, RLENGTH - 8)
+
+ match($0, / - Duration: ([0-9]+:)?[0-9]+:[0-9]+\./)
+ duration = substr($0, RSTART + 13, RLENGTH - 14)
+
+ match($0, /<a href="\/(channel|user).* >.*<\/a>/)
+ author = substr($0, RSTART, RLENGTH)
+ sub(/<a href="\/(channel|user).* >/, "", author)
+ sub(/<\/a>.*/, "", author)
+
+ desc = sprintf("%s (%s) %s", title, duration, author)
+ gsub("\\|", "\\|", desc)
+ gsub("'", "\047", desc)
+ gsub("&", "\\&", desc)
+
+ printf("[h|%s|URL:https://www.youtube.com/watch?v=%s|server|port]\n",
+ desc, video_id)
+}
+
+/« Previous/ {
+ if (!match($0, /href="\/results\?[^"]+"/)) {
+ next
+ }
+
+ page_prev = substr($0, RSTART + 6, RLENGTH - 7)
+ printf("\n")
+ printf("[1|<< Previous|'"${SEARCH_CGI}"'?%s|server|port]\n", page_prev)
+}
+
+/Next »/ {
+ if (!match($0, /href="\/results\?[^"]+"/)) {
+ next
+ }
+
+ page_next = substr($0, RSTART + 6, RLENGTH - 7)
+ if (!page_prev) {
+ printf("\n")
+ }
+ printf("[1|>> Next|'"${SEARCH_CGI}"'?%s|server|port]\n", page_next)
+}
+'
+
+echo "t"
+echo "[7|Search|${SEARCH_CGI}|server|port]"