Changeset 285 for transmission


Ignore:
Timestamp:
Mar 3, 2011, 10:55:28 AM (14 years ago)
Author:
Rick van der Zwet
Message:

New idea, based on XML and persistent upload stores.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • transmission/rss-sync.sh

    r201 r285  
    11#!/bin/sh
    2 # $Id$
    32#
    43# 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
    67#
    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
    139# Rick van der Zwet <info@rickvanderzwet.nl>
    1410
    15 TORRENTLIST=/data/transmission/freebsd-rss.txt
    1611TORRENTQUEUE=/data/transmission/upload
    17 TORRENTQUEUE=/tmp/rrs
     12TORRENTRSS=${1-http://torrents.freebsd.org:8080/rss.xml}
    1813
    1914# 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
     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
    2319
    24 # More sure we can write to the permanent location
    25 touch $TORRENTLIST || exit 1
    2620
    2721# Check for new ones
    28 fetch -qo - http://torrents.freebsd.org:8080/rss.xml | awk -F\" '/type="application\/x-bittorrent"/ {print $2}'  > $TMPFILE
    29 if [ \! -s "$TMPFILE" ]; then
    30   echo "Failed to download RSS feed"
     22fetch -qo - $TORRENTRSS > $RSSFILE
     23if [ \! -s "$RSSFILE" ]; then
     24  echo "Failed to download RSS feed $TORRENTRSS"
    3125  exit 1
    3226fi
    3327
    34 NEWURLS=`comm -13 $TORRENTLIST $TMPFILE`
    35 if [ -z "$NEWURLS" ]; then
    36   exit 0
    37 fi
     28# Split based on item
     29awk -vTMPDIR=$TMPDIR '/<item>/{n++}{print > sprintf("%s/item.txt.%03i", TMPDIR ,n) }' $RSSFILE
    3830
    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
     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 TracChangeset for help on using the changeset viewer.