Created
July 30, 2022 06:23
-
-
Save balki/fe3339c796e2695fbaa7b6ebef540bc2 to your computer and use it in GitHub Desktop.
Shows latest entires in podcast as a table in commandline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dependencies: | |
# yq - https://github.com/mikefarah/yq | |
# xsv - https://github.com/burntsushi/xsv | |
# Usage: | |
# ❯ ./show-podcast.sh https://gotime.fm/rss | |
# This exec statement puts the script to a free file descriptor. i.e. to a in-memory temporary file whose path is /dev/fd/$fd | |
# yq does not support comments, we strip of '##.*' using a sed command before passing to yq | |
exec {fd}<<'YQSCRIPT' | |
.rss.channel.item ## Walk down the tree to the item array | |
| with(.[]; ## For each item, do the following | |
.download = .enclosure.+url, ## set download field to url attribute of enclosure tag | |
.title |= .[0], ## Some feeds have both <title> and <itunes:title>, use first one in that case | |
. |= pick([ ## pick only these tags | |
"pubDate", | |
"title", | |
"duration", ## It is actually <itunes:duration> tag, namespace ignored | |
"download" ## download is the field we set above, not from rss | |
]) | |
) | |
| ( ## Convert to array of array of entries for csv convertion | |
[ .[0] | keys ] ## Header row | |
+ [ .[] | [.*] ] ## Rest of the entries | |
) | |
YQSCRIPT | |
curl -sL "$1" | | |
yq -p xml | # This line is not needed from release 4.27.1. '-p xml' can be moved to next yq | |
yq --from-file <(sed 's/ *##.*//g' /dev/fd/$fd) -o csv | | |
head | xsv table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment