Use feed_to_gph instead of parsing the feed - 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 4ca722a7e6fb8f8ea2a37317fb227cb2fa7afc9e
(DIR) parent 98ebe683720aad07223ea0e3ba6e6350e0a7218f
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sat, 8 Sep 2018 00:45:50
Use feed_to_gph instead of parsing the feed
Diffstat:
youtube/channel.dcgi | 95 ++++-----------------------------------------------
1 files changed, 8 insertions(+), 87 deletions(-)
---
diff -r 98ebe683720a -r 4ca722a7e6fb youtube/channel.dcgi
--- a/youtube/channel.dcgi Sat Sep 08 00:41:19 2018 +0200
+++ b/youtube/channel.dcgi Sat Sep 08 00:45:50 2018 +0200
@@ -1,90 +1,11 @@
#!/bin/sh
+. ../common/feed.sh
+
+FEED_AUTHOR=yes
+FEED_CONTENT=yes
+FEED_DATE=yes
+
channel="$2"
-
-/usr/bin/ftp -V -o - "https://www.youtube.com/feeds/videos.xml?channel_id=${channel}" |
-/usr/bin/awk '
-function print_feed_title(feed_title) {
- print "t"
- print "t" html_decode(feed_title) " - YouTube Channel"
- print "t"
-}
-
-function print_entry(published, title, url, thumbnail, description, views) {
- gsub("\\|", "\\|", title)
- print "[h|" html_decode(title) "|" "URL:" url "|server|port]"
- print "tPublished: " substr(published, 1, 10) # ignore hour:minute
- print "tViews: " views
- sub(/^/, "t", description)
- gsub(/\n/, "\nt", description)
- sub(/$/, "\nt", description)
- print html_decode(description)
-}
-
-function html_decode(s)
-{
- gsub("\\&", "\\&", s)
- gsub("\\<", "<", s)
- gsub("\\>", ">", s)
- gsub("\\"", "\"", s)
-
- return s
-}
-
-/<title>/ && !feed_title {
- sub(/^ *<title>/, "")
- sub(/<\/title>$/, "")
- feed_title = $0
- print_feed_title(feed_title)
-}
-
-/<published>/ {
- sub(/^ *<published>/, "")
- sub(/<\/published>$/, "")
- published = $0
-}
-
-/<media:title>/ {
- sub(/^ *<media:title>/, "")
- sub(/<\/media:title>$/, "")
- title = $0
-}
-
-/<media:content / {
- if (match($0, /url="[^"]+"/)) {
- # Ignore url=" and "
- url = substr($0, RSTART + 5, RLENGTH - 6)
- sub("/v/", "/watch?v=", url)
- sub("\\?version=3", "", url)
- }
-}
-
-/<media:thumbnail / {
- if (match($0, /url="[^"]+"/)) {
- # Ignore url=" and "
- thumbnail = substr($0, RSTART + 5, RLENGTH - 6)
- }
-}
-
-/<media:description>/, /<\/media:description>/ {
- sub(/<\/media:description>$/, "")
- sub(/^ *<media:description>/, "")
- if (!description) {
- description = $0
- } else {
- description = description "\n" $0
- }
-}
-
-/<media:statistics / {
- if (match($0, /views="[^"]+"/)) {
- # Ignore views=" and "
- views = substr($0, RSTART + 7, RLENGTH - 8)
- }
-}
-
-published && title && url && thumbnail && description && views {
- print_entry(published, title, url, thumbnail, description, views)
- published = title = url = thumbnail = description = views = ""
-}
-'
+/usr/pkg/bin/curl -gs "https://www.youtube.com/feeds/videos.xml?channel_id=${channel}" |
+feed_to_gph