Hi,
I've set up a script according to the instructions over here
http://kyyhkynen.net/stuff/mybook/torrent_helper.php
everything works well only that the script would not recognize the torrentz as being downloaded and will continue redownloading them as it loops.
any help would be appreciated.
Thanks ,
heres the script i'm using :
#!/bin/bash
# This is released under the GPL
# A tvrss script by chochem, a reworking of ughknight's (http://ubuntuforums.org/showthread.php?t=292386&page=2)
# Functions much like ughknights, except that it checks the feed against a list
# of already downloaded torrent files, then gets all the new ones.
# Also added functions are error checking and removing old unused torrent files
# REQUIRES:
# Text files containing a single feed url from tvrss.net (keep these in the 'tvrssdir' folder)
# "Xmlstarlet" to parse the feed (to get it, enter: "sudo apt-get install xmlstarlet")
# A torrent client that lets you use a "watch" folder (torrent files in said folder are automatically loaded)
# Please set the two directory variables and the waiting period under 'SETTINGS' to reflect your setup.
# The script will make the directories if they do not already exist.
# Though care has been taken to protect filenames and locations containing spaces, they should
# still be avoided in the directory and feed file names if at all possible.
# SETTINGS - CUSTOMIZE ACCORDING TO YOUR SETUP
# tvrssdir is the directory in which you put the files containing feed urls (and tvrss keeps its log and temp files)
tvrssdir=/shares/internal/PUBLIC/tvrss
# watchdir is the directory your torrent client checks for new torrents to load automatically
watchdir=/shares/internal/PUBLIC/Autoload
# waitingperiod is the time in hours between checks for new torrents (accepts decimals, e.g. 0.25 for 15 minutes)
waitingperiod=1
# maxage is used in a routine that deletes old torrent files from a show subscription. Torrents more than this number of months old gets deleted.
maxage=1
# END OF SETTINGS
while [ 1 ]; do
if [ ! -d "$tvrssdir" ]; then mkdir "$tvrssdir"; fi
if [ ! -d "$watchdir" ]; then mkdir "$watchdir"; fi
# For-each-tvshow-subscription-do loop starts here
for tvshow in $(ls "${tvrssdir}"); do
#Setting temporary files and variables
newtorrentscount=0
feedurl=$(cat "${tvrssdir}/${tvshow}")
tmpxml="${tvrssdir}/.tmpxml"
oldurllist="${tvrssdir}/.${tvshow}-oldurllist"
# Get the rss feed
echo "Working on the show \"$tvshow\""
echo "Getting the rss feed..."
wget -q -O "$tmpxml" "$feedurl" 2> /dev/null && echo "Feed file downloaded. Parsing file for new torrents..." || (
echo "The feed \"$tvshow\" at \"$feedurl\" could not be downloaded."
echo -e "\r\033[7mCheck the address and/or your connection.\033[0m"; echo
rm "$tmpxml"
)
# On condition that wget got hold of a file...
if [ -e "$tmpxml" ]; then
# Parse the feed file for torrent links
touch "$oldurllist"
oldurlstring=$(cat "$oldurllist")
currenturlstring=$(xml sel -t -m "/rss/channel/item/link" -v "concat(.,' ')" "$tmpxml" 2> /dev/null)
# Check for no results (this covers an empty feed as well as a parsing error)
if [ -z "$currenturlstring" ]; then
echo -e "\r\033[7mA file has been downloaded but parsing it resulted in no URLs.\033[0m"
echo "Either the address in the ${tvrssdir}/${tvshow} file does not refer to a tvrss.net feed or the feed is empty."; echo
else
# Check for URLs not in the log (the show's oldurllist), get new ones, add the entry to the log and inform user
for url in $(echo "$currenturlstring"); do
if [[ ! "$oldurlstring" =~ "$url" ]]; then
echo "$url is new. Getting torrent file..."
wget -q -O "${watchdir}/${tvshow}_$(date +%y%m%e)_$(date +%H%M%S%N).torrent" "$url"
echo "$url" >> "$oldurllist"
let "newtorrentscount++"
fi
done
# Evaluate / user output
if [ "$newtorrentscount" -gt 0 ]; then
echo -e "\r\033[7mFound ${newtorrentscount} new torrent(s) for \"$tvshow\"\033[0m"; echo
else
echo -e "\r\033[7mNo new torrents for \"$tvshow\"\033[0m"; echo
fi
# No results condition ends...
fi
# Cleaning up (remove tmpxml)
rm "$tmpxml"
# wget condition ends...
fi
# Check for old torrent files for this show and remove any older than two months
now=$(date +%s)
for filename in $(ls ${watchdir}/${tvshow}_*.torrent 2> /dev/null); do
birthday=$(date +%s -r "${filename}")
agesecs=$(($now-$birthday))
agemonths=$(($agesecs/2629743))
if [ $agemonths -gt $maxage ]; then
echo "Cleaning up old torrent file for \"$tvshow\"..."
rm "$filename"
fi
done
# For-each-tvshow-subscription-do loop ends...
done
# Fake cron is the below 2 commands
echo "Sleeping for ${waitingperiod} hour(s)..."
sleep ${waitingperiod}h
# Neverending loop ends...
done
exit