kerryandjane wrote:reading all the entries i assume this would be what we're wanting to just click on an RSS feed and it will automatically start downloading the file we RSS to right?
You don't need to click on anything - the script (once configured and scheduled with cron) will automatically parse an RSS feed and download the torrents that are in the feed - it can either download all torrents in the feed or you can specify a Regular Expression to filter the torrents it actually gets. You just need to configure which RSS feeds you want to check and set the Regular Expressions as shown in the
MLDonkey Page.
My requirements for the script have changed slightly.... I've split the "Broadcatching" (getting the torrents from the RSS feed) and the automatic loading of the torrents into two parts. I have a folder on my DiskStation where the synocatch script saves the torrent files and another script loads them from the folder into the DownloadStation... This means it doesn't matter whether the script puts the torrent files in the folder or if I do it myself - they'll automatically be picked up and downloaded.
Automating .torrent downloads by RSSPut these
files in the same folder
"synocatch.shell"- Code: Select all
#!/opt/bin/bash
# SynoCatch - Torrent downloading by RSS (hacked by h0me5k1n)
#
# Script based on http://linc.homeunix.org:8080/scripts/bashpodder
# discussion on http://forum.synology.com/enu/viewtopic.php?f=38&t=18039
#need bash and xsltproc installed by ipkg
###CONFIGURATION PARAMETERS
## directory to put the downloaded torrents,with trailing slash
torrentdir="/volume1/downloads/"
# User Vars
CONFG="bp.conf"
# Debug Log (set to /dev/null to turn off)
DEBUG="/dev/null"
#DEBUG="debug.log"
# Make script crontab friendly:
cd $(dirname $0)
echo -e "\nExecuting $0 on $(date)" >> $DEBUG
# feed dump reset
rm -f rssdata
# Read the bp.conf file and wget any url not already in the catch.log file:
while read subscription
do
xmldata=$(wget $(echo "$subscription" | sed 's/[^@]*@\(.*\)/\1/') -q -O -)
expression=$(echo "$subscription" | sed 's/\([^@]*\)@.*/\1/')
# If $expression is blank or is the same as the source then use a wildcard
if [ "$expression" = "$subscription" ] || [ -z "$expression" ];
then
expression="."
fi
# Parsing xml depending on where the torrent url is located inside <link> tags or as the value for the attribute enclosure
if fgrep -iq enclosure <<< "$xmldata"
then
file=$(echo "$xmldata" | xsltproc parse_enclosure.xsl - 2> /dev/null)
else
file=$(echo "$xmldata" | xsltproc parse_link.xsl - 2> /dev/null)
fi
# Protect against the white space gotchas
# file=$(tr ' \\\t\r' '_/__' <<< "$file") # doesnt work oon Synology DS207
file=${file//\ /_}
file=${file//\\/}
for url in $file
do
# echo "url is $url"
if echo "$url" | egrep -i $expression &> /dev/null
then
torrent=$(sed 's/\([^#]*\)#.*/\1/' <<< "$url")
if ! fgrep -i "$torrent" catch.log > /dev/null
then
# URL and Mininova fixer
torrent=$(echo "$torrent" | sed -e "s/mininova.org\/tor/mininova.org\/get/g")
## parse the filename from the end of the $url variable (after the #)
torrentname=$( echo $url | sed 's/^.*\#//' )
# append .torrent on the end
torrentname=$torrentname.torrent
# Get the torrent, name it correctly and put it in the right directory
if wget --connect-timeout=10 --tries=2 -qncH -O $torrentdir$torrentname $torrent
then
echo "$torrentname downloaded from $torrent" >> $DEBUG
else
echo "failed to get $torrentname from $torrent" >> $DEBUG
fi
# Delete the torrent file if it's an empty file
if [ -s "$torrentdir$torrentname" ]
then
echo "$url" >> catch.log
else
echo "$torrentname is 0kb... deleting..." >> $DEBUG
rm $torrentdir$torrentname
fi
fi
fi
# rssdata is for test matching
echo "$url" >> rssdata
done
done < $CONFG
[*] You need to configure the "torrentdir" variable with the folder that you want the torrent files downloaded to.
[*] You can set the "DEBUG" variable to troubleshoot the script.
[*] In this version I have fixed the issue found previously where 0kb torrent files were downloaded and causing errors.
the
"bp.conf" file as shown in the
MLDonkey Page[*] Customise the links for your own torrent requirements
the
"parse_enclosure.xsl" file as shown in the
MLDonkey Pagethe
"parse_link.xsl" file as shown in the
MLDonkey PageYou need "bash" and "libxslt" installed by ipkg too
- Code: Select all
ipkg install bash libxslt
edit your "/etc/crontab" file and add entries to configure when the script will run... this is what mine looks like:
- Code: Select all
# Synocatch script - load torrents from RSS feeds
5 10,11,23,2,4,6,7,8 * * * root /PATHTOSCRIPT/synocatch.shell &>/dev/null
[*] The first line is a "comment".
[*] You'll need to edit the "PATHTOSCRIPT" section
[*] This runs the script at 2.05am, 4.05am, 6.05am, 7.05am, 8.05am, 10.05am, 11.05am and 11.05pm every day
[*] The format of the crontab entry is important - IIRC you must use tabs between entries and NOT spaces
[*] you can restart crontab without rebooting using the following command
- Code: Select all
/usr/syno/etc.defaults/rc.d/S04crond.sh stop && /usr/syno/etc.defaults/rc.d/S04crond.sh start
Loading Torrent Files Saved in a DirectoryThis script will look at the contents of a folder and if it finds any torrent files it will load them... I have a version which does nzb files at the same time too!
"syno_torrent_load.shell"- Code: Select all
#!/bin/sh
# Script to start .torrent files saved in a predefined folder
###CONFIGURATION PARAMETERS
## directory to put the downloaded torrents,with trailing slash
TORRENTDIR="/volume1/downloads"
SCRIPTNAME=`basename $0`
LOGFILE=/dev/null
# Make script crontab friendly:
cd $(dirname $0)
# Check for file presence
if ls $TORRENTDIR | grep torrent ;
then
# enter date in log file
echo "-----------------------" >> $LOGFILE
echo "LOG TIMESTAMP - $(date)" >> $LOGFILE
find $TORRENTDIR -type f -name "*.torrent" | while read EACHFILE
do
# Remove spaces and square brackets from filename
TORRENT=`echo $EACHFILE | sed 's/\([ ]\)/\\\ /g' | sed 's/\([[]\)/\\\[/g' |sed 's/\([]]\)/\\\]/g'`
NEWFILENAME=`echo $EACHFILE | sed 's/[ ]*//g' | sed 's/[[]*//g' | sed 's/[]]*//g'`
# Echo the variables (for debugging)
#echo TORRENT is $TORRENT
#echo NEWFILENAME is $NEWFILENAME
mv "$EACHFILE" "$NEWFILENAME"
# load into the downloadstation
if downloadstation torrent "$NEWFILENAME"
then
rm "$NEWFILENAME"
echo -e "$NEWFILENAME loaded" >> $LOGFILE
else
echo -e "failed to load $NEWFILENAME using downloadstation cli utility" >> $LOGFILE
fi
done
else
echo "No .torrent files found" >> $LOGFILE
fi
[*] You need to configure the "TORRENTDIR" with the folder that you want the torrent files downloaded to.
[*] You can set the "LOGFILE" variable to troubleshoot the script.
Install
DownloadStation CLI by Wawe[*] I recommend editing the DownloadStation CLI script as per
the post by blouz. This will ensure that the torrent added use the seeding configuration you have set up.
edit your "/etc/crontab" file and add entries to configure when the script will run... this is what mine looks like:
- Code: Select all
# Synology Torrent Loader - loads torrents saved in a folder
10 0,1,2,3,4,5,6,7,22,23 * * * root /PATHTOSCRIPT/syno_torrent_load.shell &>/dev/null
[*] The first line is a "comment".
[*] You'll need to edit the "PATHTOSCRIPT" section
[*] This runs the script at 0.10am, 1.10am, 2.10am, 3.10am, 4.10am, 5.10am, 6.10am, 7.10am, 10.10pm and 11.10pm every day
[*] The format of the crontab entry is important - IIRC you must use tabs between entries and NOT spaces
[*] you can restart crontab without rebooting using the following command
- Code: Select all
/usr/syno/etc.defaults/rc.d/S04crond.sh stop && /usr/syno/etc.defaults/rc.d/S04crond.sh start
Combining the ScriptsUsing the information in this thread - the first post and these additional instructions - the scripts could easily be combined to automate the Broadcatching and the loading into DownloadStation into a single script if that's what you want... It's just not what I want
Other ScriptsI have another script which runs by crontab to "manage" the torrent downloads using the DownloadStation CLI... Once torrents are finished they won't disappear from the DownloadStation until they are manually removed. That script checks for "COMPLETED" downloads and removes any it finds. I'll post that another day... ^^ that lot took me ages to write!

Thanks to Wawe, blouz and
linc