Changeset 285
- Timestamp:
- Mar 3, 2011, 10:55:28 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
transmission/rss-sync.sh
r201 r285 1 1 #!/bin/sh 2 # $Id$3 2 # 4 3 # Crude attempt to keep torrent in sync from FreeBSD RSS feed 5 # eq autofeed them into transmission. to be run from cron: 4 # eq autofeed them into transmission 5 # 6 # Lesson learned: Shell is NOT useable for XML parsing 6 7 # 7 # 3 0 */3 * * transmission /data/transmission/rss-sync.sh 8 # 9 # Also make sure your transmission daemon is set to to auto-accept torrent 10 # files put in $TORRENTQUEUE directory 11 # 12 # Licence: BSDLike - http://rickvanderzwet.nl/LICENSE 8 # Licence: BSDLike 13 9 # Rick van der Zwet <info@rickvanderzwet.nl> 14 10 15 TORRENTLIST=/data/transmission/freebsd-rss.txt16 11 TORRENTQUEUE=/data/transmission/upload 17 TORRENT QUEUE=/tmp/rrs12 TORRENTRSS=${1-http://torrents.freebsd.org:8080/rss.xml} 18 13 19 14 # Cleanup bits 20 TMPFILE=`mktemp /tmp/$(basename $0).XXXXX` 21 trap "rm $TMPFILE; exit 1" 1 2 3 15 22 trap "rm $TMPFILE; exit 0" 0 15 TMPDIR=`mktemp -d /tmp/$(basename $0).XXXXX` 16 RSSFILE=$TMPDIR/output.rss 17 trap "rm -Rf $TMPDIR; exit 1" 1 2 3 15 18 trap "rm -Rf $TMPDIR; exit 0" 0 23 19 24 # More sure we can write to the permanent location25 touch $TORRENTLIST || exit 126 20 27 21 # Check for new ones 28 fetch -qo - http://torrents.freebsd.org:8080/rss.xml | awk -F\" '/type="application\/x-bittorrent"/ {print $2}' > $TMPFILE29 if [ \! -s "$ TMPFILE" ]; then30 echo "Failed to download RSS feed "22 fetch -qo - $TORRENTRSS > $RSSFILE 23 if [ \! -s "$RSSFILE" ]; then 24 echo "Failed to download RSS feed $TORRENTRSS" 31 25 exit 1 32 26 fi 33 27 34 NEWURLS=`comm -13 $TORRENTLIST $TMPFILE` 35 if [ -z "$NEWURLS" ]; then 36 exit 0 37 fi 28 # Split based on item 29 awk -vTMPDIR=$TMPDIR '/<item>/{n++}{print > sprintf("%s/item.txt.%03i", TMPDIR ,n) }' $RSSFILE 38 30 39 # Download the new ones please 40 fetch -o $TORRENTQUEUE $NEWURLS || exit 1 41 42 # All succesfull, lets make that list permanent 43 cat $TMPFILE > $TORRENTLIST 31 # Download the new ones please, if not yet existing 32 for ITEM in $TMPDIR/item.txt.???; do 33 URI=`awk -F\" '/^<enclosure url=/{print $2}' $ITEM` 34 [ -z "$URI" ] && continue 35 TITLE=`awk '/^<title>/{print $0}' $ITEM` 36 TARGET=$TORRENTQUEUE/`basename $URI` 37 if [ \! -r $TARGET ]; then 38 echo "# Adding torrent $TARGET ($TITLE)" 39 fetch -qo $TARGET $URI 40 fi 41 done
Note:
See TracChangeset
for help on using the changeset viewer.