-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpodgrab
executable file
·57 lines (47 loc) · 1.53 KB
/
podgrab
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
50
51
52
53
54
55
56
#!/bin/bash
RIPPER=/usr/bin/streamripper
TOPDIR=/var/downloads/podcasts
NAME=$1
RSSFILE=${TOPDIR}/${NAME}.xml
MAXITEMS=10
BASE=http://foo.bar/podcasts
URL=$1
LENGTH=$2
[ -d ${TOPDIR}/${NAME} ] || mkdir -p ${TOPDIR}/${NAME}
$RIPPER $STREAM $URL -d ${TOPDIR} -a ${NAME}/${NAME}_%d -l $LENGTH --quiet
rm ${TOPDIR}/$NAME/*cue
ls -r1 ${TOPDIR}/$NAME/*mp3 | tail -n +$((${MAXITEMS}+1)) | xargs rm -f
BUILDDATE=$(date +"%a, %d %b %Y %T %Z")
cat <<EOHEADER >$RSSFILE
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>$NAME</title>
<description>$NAME captures</description>
<link>$BASE/$NAME.xml</link>
<language>en-us</language>
<copyright>None</copyright>
<lastBuildDate>$BUILDDATE</lastBuildDate>
<pubDate>$BUILDDATE</pubDate>
EOHEADER
for item in $(find ${TOPDIR}/${NAME} -name \*.mp3)
do
URL=$(echo $item | sed "s#$TOPDIR#$BASE#")
SIZE=$(ls -l $item | awk '{print $5}')
ITEMDATE=$(date -r $item +"%a, %d %b %Y %T %Z")
cat <<EOITEM >>$RSSFILE
<item>
<title>$NAME</title>
<link>$URL</link>
<guid>$URL</guid>
<description></description>
<enclosure url="$URL" length="$SIZE" type="audio/mpeg"/>
<category>$NAME</category>
<pubDate>$ITEMDATE</pubDate>
</item>
EOITEM
done
cat <<EOFOOT >>$RSSFILE
</channel>
</rss>
EOFOOT