youtube-rss: generate an rss from a channel with youtube-dl, jq and GNU date

This commit is contained in:
gutmet 2020-10-31 17:14:51 +01:00
parent 2f194d1750
commit 07d6c05fd6

40
youtube-rss Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
playlistURL="$1"
playlistJSON=`youtube-dl "$playlistURL" --flat-playlist -J`
uploader=`echo "$playlistJSON" | jq -r '.uploader'`
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">
<channel>
<title>$uploader</title>
<link>$playlistURL</link>
<description>$uploader</description>
"
entries=`echo "$playlistJSON" | jq -r '.entries[] | .url + " " + .title'`
pubdate=`date --rfc-email`
echo "$entries" | while read entry; do
url=`echo "$entry" | cut -d' ' -f1`
title=`echo "$entry" | cut -d' ' -f2-`
pubdate=`date --rfc-email -d "$pubdate - 5 seconds"`
embedURL="https://www.youtube.com/embed/$url"
link="https://www.youtube.com/watch?v=$url"
echo "
<item>
<title><![CDATA[ $title ]]></title>
<content:encoded><![CDATA[ <iframe src=\"$embedURL\" allowfullscreen /> ]]></content:encoded>
<guid>$link</guid>
<link>$link</link>
<pubDate>$pubdate</pubDate>
</item>
"
done
echo "
</channel>
</rss>
"