aboutsummaryrefslogtreecommitdiff
path: root/youtube-rss
blob: 9e0f75b4eda3c22e66a6fb189c290f76d70c6e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash

playlistURL="$1"
noItems="$2"

set -e

playlistJSON=`youtube-dl "$playlistURL" --flat-playlist -J --playlist-end "$noItems"`
uploader=`echo "$playlistJSON" | jq -r '.uploader'`
entries=`echo "$playlistJSON" | jq -r '.entries[] | .url + " " + .title'`

if [ "$entries" = "null" ] || [ "$entries" = "" ]; then
  exit 1
fi


echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">
<channel>
<title><![CDATA[ $uploader ]]></title>
<link><![CDATA[ $playlistURL ]]></link>
<description><![CDATA[ $playlistURL ]]></description>
"



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>
"