source: transmission/rss-sync.sh@ 325

Last change on this file since 325 was 285, checked in by Rick van der Zwet, 14 years ago

New idea, based on XML and persistent upload stores.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.1 KB
Line 
1#!/bin/sh
2#
3# Crude attempt to keep torrent in sync from FreeBSD RSS feed
4# eq autofeed them into transmission
5#
6# Lesson learned: Shell is NOT useable for XML parsing
7#
8# Licence: BSDLike
9# Rick van der Zwet <info@rickvanderzwet.nl>
10
11TORRENTQUEUE=/data/transmission/upload
12TORRENTRSS=${1-http://torrents.freebsd.org:8080/rss.xml}
13
14# Cleanup bits
15TMPDIR=`mktemp -d /tmp/$(basename $0).XXXXX`
16RSSFILE=$TMPDIR/output.rss
17trap "rm -Rf $TMPDIR; exit 1" 1 2 3 15
18trap "rm -Rf $TMPDIR; exit 0" 0
19
20
21# Check for new ones
22fetch -qo - $TORRENTRSS > $RSSFILE
23if [ \! -s "$RSSFILE" ]; then
24 echo "Failed to download RSS feed $TORRENTRSS"
25 exit 1
26fi
27
28# Split based on item
29awk -vTMPDIR=$TMPDIR '/<item>/{n++}{print > sprintf("%s/item.txt.%03i", TMPDIR ,n) }' $RSSFILE
30
31# Download the new ones please, if not yet existing
32for 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
41done
Note: See TracBrowser for help on using the repository browser.