dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

lbry2rss (2309B)


      1 #!/bin/sh
      2 #
      3 # usage: lbry2rss "lbry://@lbry.social#1" > lbry.social.rss
      4 # Works with newsboat and mpv!
      5 # usage in newsboat:
      6 #   "exec:lbry2rss 'lbry://@<channel>'"
      7 
      8 CHNL="$1"
      9 
     10 get_channel_data() {
     11 	local CHNL_REQ="{
     12 		\"jsonrpc\":\"2.0\",
     13 		\"method\":\"resolve\",
     14 		\"params\":{
     15 			\"urls\":[\"$CHNL\"]
     16 		}
     17 	}"
     18 	local CHNL_QRY=".result | to_entries[].value |
     19 	.value.title,
     20 	.short_url,
     21 	.value.description
     22 	"
     23 	local CHNL_DATA="$(curl \
     24 		--data-binary "$CHNL_REQ" \
     25 		-H 'content-type:text/plain;' \
     26 		--silent https://api.lbry.tv/api/v1/proxy \
     27 	| jq "$CHNL_QRY" \
     28 	| sed \
     29 		-e 's/^"//' \
     30 		-e 's/"$//' \
     31 	| awk '
     32 		NR == 1 {gsub(/&/, "&amp;"); print "<title>"$0"</title>"}
     33 		NR == 2 {print "<link>"$0"</link>"}
     34 		NR == 3 {print "<description><![CDATA["$0"]]></description>"}
     35 	'
     36 	)"
     37 
     38 	echo "$CHNL_DATA"
     39 }
     40 
     41 get_feed_items() {
     42 	local LIST_REQ="{
     43 		\"jsonrpc\":\"2.0\",
     44 		\"method\":\"claim_search\",
     45 		\"params\":{
     46 			\"channel\":\"$CHNL\",
     47 			\"order_by\":[\"release_time\"],
     48 			\"page\":$1,
     49 			\"page_size\":50
     50 		}
     51 	}"
     52 	local LIST_QRY=".result.items[] |
     53 	.value.title,
     54 	.value.thumbnail.url,
     55 	.value.description,
     56 	\"https://api.lbry.tv/content/claims/\"
     57 		+.normalized_name+\"/\"
     58 		+.claim_id
     59 		+\"/stream\",
     60 	.permanent_url,
     61 	.meta.creation_timestamp
     62 	"
     63 	local LIST_DATA="$(curl \
     64 		--data-binary "$LIST_REQ" \
     65 		-H 'content-type:text/plain;' \
     66 		--silent https://api.lbry.tv/api/v1/proxy \
     67 	| jq "$LIST_QRY" \
     68 	| sed \
     69 		-e 's/^"//' \
     70 		-e 's/"$//' \
     71 	| awk '
     72 		NR % 6 == 1 {print "<item>"}
     73 		NR % 6 == 1 {gsub(/&/, "&amp;"); print "\t<title>"$0"</title>"}
     74 		NR % 6 == 2 {print "\t<description><![CDATA[<img src=\""$0"\" width=\"480\" height=\"360\" />"}
     75 		NR % 6 == 3 {gsub(/\\n/, "</p><p>"); print "<p>"$0"</p>]]></description>"}
     76 		NR % 6 == 4 {print "\t<link>"$0"</link>"}
     77 		NR % 6 == 5 {print "\t<guid isPermaLink=\"false\">"$0"</guid>"}
     78 		NR % 6 == 0 {print "\t<pubDate>"strftime("%a, %d %b %Y %T %z",$0)"</pubDate>"}
     79 		NR % 6 == 0 {print "</item>"}
     80 	' \
     81 	| sed 's:<p></p>::g'
     82 	)"
     83 
     84 	echo "$LIST_DATA"
     85 }
     86 
     87 
     88 echo '<?xml version="1.0" encoding="UTF-8" ?>
     89 <rss version="2.0">
     90 <channel>'
     91 get_channel_data
     92 i=1
     93 if [ "$LBRY2RSSFULL" = "true" ]; then
     94 	while :; do
     95 		data="$(get_feed_items $i)"
     96 		i=$((i+1))
     97 		[ "$data" = "" ] && break || echo "$data"
     98 	done
     99 else
    100 	get_feed_items 1
    101 fi
    102 echo '</channel>
    103 </rss>'