Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: Command line RSS reader for TVrss wanted

  1. #21
    Join Date
    Sep 2006
    Location
    Denmark
    Beans
    202
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Command line RSS reader for TVrss wanted

    thanks - glad you like it

  2. #22
    Join Date
    Sep 2010
    Location
    California, USA
    Beans
    0

    Re: Command line RSS reader for TVrss wanted

    Hiya,

    The tvrss script from this thread has been incredibly helpful to me! I've been using it for about a year, and recently decided to add some tolerance for wget errors, i.e., when links are not yet live. I had a problem where the script thought it had properly downloaded a torrent file, added it to the oldurllist, and therefore never tried to grab the torrent again.

    The script is currently setup to run as a daemon/monit script which sleeps for a period of time, but could easily be modified to run standalone, by cron or what-have-you. If anyone is interested, please let me know! Fair warning: I'm not a coder by trade, so I imagine it's a bit ugly. Any input would be welcome!

  3. #23
    Join Date
    Oct 2008
    Beans
    27

    Red face Re: Command line RSS reader for TVrss wanted

    Quote Originally Posted by zoomb View Post
    Hiya,

    The tvrss script from this thread has been incredibly helpful to me! I've been using it for about a year, and recently decided to add some tolerance for wget errors, i.e., when links are not yet live. I had a problem where the script thought it had properly downloaded a torrent file, added it to the oldurllist, and therefore never tried to grab the torrent again.

    The script is currently setup to run as a daemon/monit script which sleeps for a period of time, but could easily be modified to run standalone, by cron or what-have-you. If anyone is interested, please let me know! Fair warning: I'm not a coder by trade, so I imagine it's a bit ugly. Any input would be welcome!

    Any chance you could post it here, for us?

  4. #24
    Join Date
    Oct 2008
    Beans
    27

    Re: Command line RSS reader for TVrss wanted

    Quote Originally Posted by chochem View Post
    I've put a very different version of this up on my web site. The new version is easier to configure (has it's own configuration file), has an option to add new subscriptions and is crontab friendly. Check it out here.
    Oh No. The link is broken. Does anyone still have a copy of the script that link points to?

  5. #25
    Join Date
    Sep 2010
    Location
    California, USA
    Beans
    0

    Post Re: Command line RSS reader for TVrss wanted

    Quote Originally Posted by Badcam View Post
    Any chance you could post it here, for us?
    Certainly!

    You should only really need to modify the initial variable settings in the #variables# section to suit your environment. Everything else should be good to go.

    If you need help, the traditional "-h" or "--help" command line modifier will do the trick.

    - zoomb


    P.S. I'm 30KB over the upload limit, so here's my code.

    Code:
    #!/bin/bash
    # a RSS torrent subscription script 
    # based on 0.33 by chochem
    # revised by zoomb
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    ########################
    ### check for conf file
    ########################
    ORIGINAL_IFS=$IFS
    IFS=$'\n'
    
    if [ -f ~/.tvrss ]; then
    	. ~/.tvrss
    else
    	echo "Config file missing. Please run 'tvrss --setup' to create one."
    	exit
    fi
    
    # ensure folders in config file exist
    [ -d "$tvrssdir" ] || mkdir -p "$tvrssdir"
    [ -d "$watchdir" ] || mkdir -p "$watchdir"
    [ -d "$mediadir" ] || mkdir -p "$mediadir"
    
    ###############
    ### variables
    ###############
    
    ### This script assumes that you want to keep all logs in the same location that you are
    ### keeping all configuration files and, theoretically, from where you are running the 
    ### script, though this is not necessary.
    
    ## command directory
    com_dir="$tvrssdir"
    
    ## output file
    out_log="tvrss-log.txt"
    
    ## path to output file
    output="$com_dir"/"$out_log"
    
    ## file storing errored urls from previous run
    url_store="$com_dir"/url-store.txt
    
    ## file storing temporary urls
    url_tmp="$com_dir"/url-tmp.txt
    
    ## file storing urls to be worked on
    url_cache="$com_dir"/url-cache.txt
    
    ## file storing temporary show titles
    name_tmp="$com_dir"/name-tmp.txt
    
    ## file storing temporary show publishing dates
    date_tmp="$com_dir"/date-tmp.txt
    
    ## number of times run
    cycle=0
    
    # ensure log archive folder exists
    [ -d "$com_dir"/logs ] || mkdir -p "$com_dir"/logs
    
    
    ##############
    ### functions
    ##############
    
    printhelp () {
    printf "tvrss is a torrent RSS subscription script. It will check your 
    feeds for new torrent files (.torrent) or media files and download them 
    to a designated folder. It can be run manually but it is probably preferable 
    adding it as a crontab entry or combining it with daemon and monit.
    
    It requires a .tvrss configuration file in the home folder, so run it
    once as 'tvrss --setup' to create one. This will allow you to designate 
    three folders: (1) a 'tvrss' folder where your subsciption files and log 
    files (log of previously downloaded torrents) will be kept, (2) a 'watch' 
    folder where the .torrent files will be saved, and (3) a folder where your 
    AV media is stored.
    
    Subscriptions are given to the script in the form of lines in the 'feeds' 
    file, a text file containing a single 
    '[name][tab][media type][tab][feed url]' 
    set per line. This should be kept in the 'tvrss' folder, and can be edited 
    manually or by using 
    \"tvrss --add '[feed name of choice]' '[media type]' '[url]'\" 
    (the quotes are important). You can also use 
    \"tvrss -i\" to interactively add a feed.
    
    There are built-in notifications to the user when run in the foreground,
    mostly for the purpose of debugging. Because the script runs for 15 minutes
    (though this can be easily modified), I would recommend running it in the 
    background. Also, the number of downloaded torrents is added to a counting 
    file in /tmp (thus it will be reset whenever /tmp is cleared, usually at reboot), 
    making it available for other scripts/programs to pick up, e.g. 'watch'.
    
    REQUIRES:
    - xmlstarlet to parse the feed (apt package: xmlstarlet)
    - suggested: a torrent client that lets you use a watch folder (torrent files
      in said folder are automatically loaded), e.g. vuze, rtorrent and utorrent.
    "
    
    }
    
    setupConfFile () {
    rm ~/.tvrss &> /dev/null
    
    tvrssdir="\*"
    watchdir="\*"
    mediadir="\*"
    
    printf "Entering tvrss configuration. This will produce a configuration file
    (.tvrss) in your home directory in order to save your settings. Please see 
    'tvrss --help' for more details."
    
    echo
    
    read -p "Where would you like tvrss to store your tvrss .feed and .log files 
    (e.g. '/home/user/p2p/tvrss')? " tvrssdir
    
    while [ ! -d "$tvrssdir" ]; do
    	read -p "$tvrssdir is not a directory - do you wish to create it now? (yes/no/exit) " reply
    	case $reply in
    		yes)
    		mkdir -p "$tvrssdir"
    		;;
    		no) 
    		echo "Please try again."
    		echo
    		read -p "Where would you like tvrss to store your tvrss .feed and .log files? " tvrssdir
    		;;
    		exit)
    		echo .tvrss file has not been created.
    		exit
    		;;
    		*)
    		echo "Please enter either 'yes', 'no', or 'exit'."
    		;;
    	esac
    done
    
    echo
    
    read -p "Where would you like tvrss to store your downloaded .torrent files 
    (suggestion: the folder you have told your torrent client to watch for new 
    .torrent files, e.g. '/home/user/p2p/watch')? " watchdir
    
    while [ ! -d "$watchdir" ]; do
    	read -p "$watchdir is not a directory - do you wish to create it now? (yes/no/exit) " reply
    	case $reply in
    		yes)
    		mkdir -p "$watchdir"
    		;;
    		no) 
    		echo "Please try again."
    		echo
    		read -p "Where would you like tvrss to store your downloaded .torrent files? " watchdir
    		;;
    		exit)
    		echo .tvrss file has not been created.
    		exit
    		;;
    		*)
    		echo "Please enter either 'yes', 'no', or 'exit'."
    		;;
    	esac
    done
    
    echo
    
    read -p "Where would you like tvrss to store your media files
    (suggestion: the folder where your torrent client saves media by default)? " mediadir
    
    while [ ! -d "$mediadir" ]; do
    	read -p "$mediadir is not a directory - do you wish to create it now? (yes/no/exit) " reply
    	case $reply in
    		yes)
    		mkdir -p "$mediadir"
    		;;
    		no) 
    		echo "Please try again."
    		echo
    		read -p "Where would you like tvrss to store your media files? " mediadir
    		;;
    		exit)
    		echo .tvrss file has not been created.
    		exit
    		;;
    		*)
    		echo "Please enter either 'yes', 'no', or 'exit'."
    		;;
    	esac
    done
    
    echo "tvrssdir=${tvrssdir}" > ~/.tvrss
    echo "watchdir=${watchdir}" >> ~/.tvrss
    echo "mediadir=${mediadir}" >> ~/.tvrss
    
    echo "Setup done"
    }
    
    
    interAdd()
    {
    touch "$tvrssdir"/feeds
    
    local namestring="$(cat $tvrssdir/feeds)"
    
    read -p "What would you like to call the show? Make sure to use a single 'word': " tvshowname
    
    while [[ "$namestring" =~ "$tvshowname" ]]; do
    	read -p "Name already exists. Please try a different monicker: " tvshowname
    done
    
    read -p "What filetype is in the feed? (torrent or other): " tvshowtype
    
    while [[ "$tvshowtype" != "torrent" && "$tvshowtype" != "other" ]]; do
    read -p "Please enter 'torrent' or 'other': " tvshowtype
    done
    
    read -p "What is the url of the feed? " tvshowurl
    
    while [[ "$namestring" =~ "$tvshowurl" ]]; do
    	read -p "Url already exists. Do you need to complete this entry (yes or no): " choice
    
    	case $choice in
    		yes)
    		read -p "Please enter a modified url: " tvshowurl
    		;;
    		no)
    		echo "OK then, thanks!" && exit
    		;;
    		*)
    		echo "Please enter 'yes' or 'no': "
    	esac
    
    done
    
    echo -e "$tvshowname\t$tvshowtype\t$tvshowurl" >> "$tvrssdir"/feeds
    
    }
    
    
    
    ## usage: log_chk "name based on purpose of log" ##
    log_chk()
    {
    # name of log file
    local log="$(echo "$1")"
    
    # path to original log
    local old_log="$(echo "$com_dir"/"$log")"
    
    # path to archived log
    local new_log="$(echo "$com_dir"/logs/"`date +%Y%m%d`"_"$log")"
    
    
    if [ -f "$old_log" ]; then
    
    	# date original log was created
    	local old_date="$(expr substr "`cat $old_log`" 1 8)"
    	
    	# date of current script run
    	local new_date="$(date +%Y%m%d)"
    
    	#if original log is not from today, archive it and create new log
    	if [ "$old_date" != "$new_date" ]; then
    		echo "`date +%Y%m%d-%H%M%S` Moving log files." >> $old_log
    
    		temp_out="$(echo `mv -v "$old_log" "$new_log"`)"
    
    		echo "$temp_out" >> $new_log
    	
    		log_init
    
    	fi
    	
    else
    	log_init
    		
    fi
    
    }
    
    log_init()
    {
    # initialize new log
    	date +%Y%m%d-%H%M%S >> $output
    	echo >> $output
    	
    	echo Watch directory is "$watchdir" >> $output
    	
    	echo Media directory is "$mediadir" >> $output
    	
    	echo Command directory is "$com_dir" >> $output
    	
    	echo TVRSS directory is "$tvrssdir" >> $output
    	echo >> $output
    	
    	echo Output goes to "$out_log" >> $output
    	echo with path "$output" >> $output
    	echo >> $output
    	
    	echo Store file for errored urls is "$url_store" >> $output
    
    	echo ------------------ >> $output
    	echo >> $output
    
    }
    
    
    ## usage: log_cln /path/to/folder log ##
    log_cln()
    {
    local log_folder="$1"
    
    local log="$2"
    
    # check if last character of $log_folder is a "/"
    local char="$(echo "$log_folder" | awk '{print substr($0,length,1)}')"
    
    if [ "$char" != "/" ]; then
    	log_folder="$(echo "$log_folder"/)"
    fi
    
    local log_output="$(find "$log_folder" -type f -iname '*"$log"' -mtime +7 -exec rm -fv {} 2>&1 \;)"
    
    
    # if logfile exists, remove it
    if [[ "$log_output" ]]; then
    	date +%Y%m%d-%H%M%S >> $log_folder/logclean.txt
    	echo $log_output >> $log_folder/logclean.txt
    	echo >> $log_folder/logclean.txt
    fi
    
    }
    
    ## usage: form_chk "fileform"
    form_chk()
    {
    #local fu=fileurl
    #local ft=filetitle
    #local fc=filecat
    #local fd=filedate
    #local fn=filename
    #local fo=tmp_fname
    #local ex=extension
    
    fform="$(echo "$1")"
    
    [[ "$fform" ]] || fform="$(echo fd-ft.ex)"
    
    form=$(echo "$fform" | sed -e 's/fu/\$fileurl/g' -e 's/ft/\$filetitle/g' -e 's/fc/\$filecat/g' -e 's/fd/\$filedate/g' -e 's/fn/\$filename/g' -e 's/fo/\$tmp_fname/g' -e 's/ex/\$extension/g')
    
    final=$(eval echo "$form")
    
    }
    
    ## usage: url_chk "fileurl" "filetype" "filetitle" "filecat" "filedate" "fileform"
    url_chk()
    {
    local fileurl="$1"
    
    echo File URL is $fileurl
    echo
    sleep 1
    
    local filetype="$2"
    
    echo File type is $filetype
    echo
    sleep 1
    
    local filetitle="$3"
    
    echo File title is $filetitle
    echo
    sleep 1
    
    local filecat="$4"
    
    echo File category is $filecat
    echo
    sleep 1
    
    local filedate="$5"
    
    
    # if filedate is empty, fill it with current date
    [[ "$filedate" ]] || filedate="$(echo `date +%Y%m%d`)"
    
    
    echo Filedate is $filedate
    echo
    sleep 1
    
    local fileform="$6"
    
    echo Fileform is $fileform
    echo
    sleep 1
    
    
    # grab end of url after final "/" as filename
    local filename="$(echo `expr "$fileurl" : '.*//*/*\(.*\)'`)"
    
    echo Filename is $filename
    echo
    sleep 1
    
    # grab last 8 characters of the url to check later (looking for .torrent)
    local end="$(echo `expr "$fileurl" : '.*\(........\)'`)"
    
    echo Last 8 characters are $end
    echo
    sleep 1
    
    
    # and just in case file is not a torrent, grab characters after last "."
    local extension="$(echo `expr "$filename" : '.*\.\(.*\)'`)"
    
    echo Extension seems to be $extension
    echo
    sleep 1
    
    # filename without extension for naming use
    local tmp_fname="$(expr "$filename" : '\(.*\)\.')"
    
    echo Filename without extension is $tmp_fname
    echo
    sleep 1
    
    
    # if the filetype is torrent, place file in watch directory and set extension to "torrent"
    if [ "$filetype" = "torrent" ]; then
    	filedir="$watchdir"
    	extension="$(echo torrent)"
    
    # else, put the file in a folder in the media directory
    else
    	filedir="${mediadir}"/"$filecat"
    	[ -d "$filedir" ] || mkdir -p "$filedir"
    
    fi
    
    echo Directory for this file should be $filedir
    echo
    sleep 1
    
    
    form_chk "$fileform"
    
    echo Attempting to put "$final" in folder "$filedir"/...
    echo
    sleep 2
    
    
    # capture all messages from wget
    status=$(wget --tries=2 -O "${filedir}"/"$final" "${fileurl}" 2>&1)
    
    # echo $status
    
    # will contain information if there is a 404 error
    error="$(echo $status | grep ERROR)"
    
    # will contain information if there is another type of failure
    failed="$(echo $status | grep failed)"
    
    # will contain information if the file was empty
    empty="$(find "$filedir"/ -maxdepth 1 -empty -iname '$final')"
    
    }
    
    
    #if [[ "$1" ]]; then
    # check for help & setup parameters
    case "$1" in 
    	-h) 
    		printhelp 
    		exit
    	;;
    	
    	--help) 
    		printhelp 
    		exit
    	;;
    	
    	--setup) 
    		setupConfFile
    		exit
    	;;
    	
    	--add) 
    		echo -e "$2\t$3\t$4" >> "${tvrssdir}/feeds"
    		echo "${2} feed added." 
    		exit
    	;;
    	
    	-i) 
    		interAdd
    		exit
    	;;
    	
    	--log) 
    		cat "$output" 
    		exit
    	;;
    	
    	--feeds) 
    		cat "$tvrssdir"/feeds 
    		exit
    	;;
    	
    	--quick) 
    		num_cycles=1
    	;;
    	
    	--run)
    		shopt -s extglob
    
    		num_cycles="$2"
    
    		while [[ "$num_cycles" != +([0-9]) ]]; do
    			echo Number of cycles not recognized.
    			read -p "How many times do you want tvrss to run?: " num_cycles
    		done
    		
    		echo Will run $num_cycles times.
    	;;
    	
    	*) printf "Available options: 
    	'-h' | '--help'\t\t Help message 
    	'--setup'\t\t Interactive setup 
    	'--add'\t\t\t Add feed by commandline arguments
    	'-i'\t\t\t Add feed interactively
    	'--log'\t\t\t Display output log
    	'--feeds'\t\t Current list of feeds
    	'--quick'\t\t Runs script only once
    	'--run'\t\t\t Runs the number of times specified"
    	echo
    	exit
    	;;
    
    esac
    
    #fi
    
    
    ###################
    ### main exec loop
    ###################
    
    ## zero out pseudo-notifications
    newtorrentscount=0
    
    ## check that no logs already exist. if they do, check that they are current 
    ## or put them with old logs
    log_chk $out_log
    
    
    #### default style ####
    ### run script for 1 hour in 15 minute intervals 
    echo Number of cycles to run is $num_cycles
    echo
    if [ -z $num_cycles ]; then
    	num_cycles=4
    fi
    echo Verifying the number of cycles - $num_cycles
    echo
    
    ## for loop 1 ##
    for ((i=1;i<=$num_cycles;i++)); do
    
    	cycle=$i
    	
    	echo `date` >> "$output"
    	
    #	echo - Cycle is "$cycle" - >> "$output"
    	echo Cycle is "$cycle"
    #	echo >> "$output"
    	echo
    	
    	echo Checking errored urls... >> "$output"
    	echo Checking errored urls...
    	echo
    	
    	touch "$url_store"
    
    	if [[ "`cat $url_store`" ]]; then	
    		cat "$url_store" > "$url_cache"
    
    		if [ -f "$url_tmp" ]; then
    			rm -f "$url_tmp"
    		fi
    		
    		touch "$url_tmp"
    
    ## for loop 1-A ##	
    		for url_entry in $(cat "$url_cache"); do
    		
    			showname="$(echo "$url_entry" | cut -f 1)"
    			mediatype="$(echo "$url_entry" | cut -f 2)"
    			tv_title="$(echo "$url_entry" | cut -f 3)"
    			tv_date="$(echo "$url_entry" | cut -f 4)"
    			tv_url="$(echo "$url_entry" | cut -f 5)"
    			tv_form="$(echo "$url_entry" | cut -f 6)"
    			
    			oldurllist="${tvrssdir}/${showname}.log"
    			touch "$oldurllist"
    			
    			rm -f /tmp/tmpxml &> /dev/null
    		
    			url_chk "$tv_url" "$mediatype" "$tv_title" "$showname" "$tv_date"
    			
    			if [[ "$error" || "$failed" || "$empty" ]]; then
    				echo Still having trouble...
    				echo
    				echo -e "${showname}\t${mediatype}\t${tv_title}\t${tv_date}\t${tv_url}\t${tv_form}" >> "$url_tmp"
    				echo Still having trouble with "$final" >> "$output"
    				echo with url "$tv_url" >> "$output"
    				echo >> "$output"
    				
    			else
    				echo "$tv_url" >> "$oldurllist"
    				echo "$tv_title" at >> "$output"
    				echo "$tv_url" >> "$output"
    				echo >> "$output"
    			fi
    
    ## for loop 1-A done ##
    		done
    	
    		cat "$url_tmp" > "$url_store"
    		echo URL check complete. >> "$output"
    		echo URL check complete.
    		echo >> "$output"
    		echo
    		
    	else
    		echo No urls to check. >> "$output"
    		echo No urls to check.
    		echo >> "$output"
    		echo
    	
    	fi
    	
    #	echo >> "$output"
    
    ## run subroutine to check show feed every 5 minutes (15 min * 1/5 runs/min = 3 runs)
    
    ## for loop 1-B ##	
    	for ((x=1;x<=3;x++)); do
    
    		subcycle=$x
    		
    #		echo -- Subcycle is "$cycle" - "$subcycle" -- >> "$output"
    #		echo >> "$output"
    		
    		echo Subcycle is $cycle - $subcycle
    		echo
    
    	# for-each-tvshow-subscription-do loop
    
    ## for loop 1-B-a ##
    		for tvshow in $(cat "$tvrssdir"/feeds); do
    	
    			# clearing temporary files and variables
    			rm -f /tmp/tmpxml &> /dev/null
    			
    			showname="$(echo "$tvshow" | cut -f 1)"
    			echo "$showname"
    			
    			mediatype="$(echo "$tvshow" | cut -f 2)" 
    			echo "$mediatype"
    			
    			feedurl="$(echo "$tvshow" | cut -f 3)" 
    			echo "$feedurl"
    			
    			fileform="$(echo "$tvshow" | cut -f 4)"
    			echo "$fileform"
    			
    			oldurllist="${tvrssdir}/${showname}.log"
    			touch "$oldurllist"
    			
    			oldurlstring=$(cat "$oldurllist")
    			errorurlstring=$(cat "$url_store")
    			
    			count=0
    	
    			# start log feed
    			echo `date` >> "$output"
    			echo "$showname" >> "$output"
    		
    		
    			# get and parse the rss feed
    			currenturlstring="$(xmlstarlet sel --net -t -m "/rss/channel/item" -v "enclosure/@url" -o "" -n "$feedurl")"
    		
    			# check for URLs not in the log, get new ones, add the entry to the log file
    			if [ -n "$currenturlstring" ]; then 
    
    			# initiate loop counter for file title position
    				loop=1
    			
    			# cache titles in file
    				xmlstarlet sel --net -t -m "/rss/channel/item" -v "title" -n "$feedurl" | sed 's/\([(),:!?'"'"']\)//g' | sed -e 's/\&amp;/and/g' -e 's/ -//g' | sed 's/ /./g' | sed 's/\.\././g' > $name_tmp
    			
    			# cache publish dates
    				xmlstarlet sel --net -t -m "/rss/channel/item" -v "pubDate" -n "$feedurl" > $date_tmp
    			
    
    #			cat $name_tmp
    
    ## for loop 1-B-a-i ##
    				for url in $currenturlstring; do
    					
    					counter=$loop
    					let "loop++"
    					
    					if [[ ! "$oldurlstring" =~ "$url" && ! "$errorurlstring" =~ "$url" ]]; then
    					
    						showtitle="$(sed -n "$counter"p "$name_tmp")"
    					
    					
    						# check if last character of $showtitle is a "."
    						last_char="$(echo "$showtitle" | awk '{print substr($0,length,1)}')"
    						
    						if [ "$last_char" = "." ]; then
    							showtitle="$(expr "$showtitle" : '\(.*\).')"
    						fi
    					
    					
    						pubDate="$(expr "`sed -n "$counter"p "$date_tmp"`" : '.*,\(.*20[0-9][0-9]\).*')"
    					
    						showdate="$(date -d "$pubDate" +%Y%m%d)"
    						
    						echo Show $showtitle published on $pubDate aka $showdate
    					
    					# check file extension and media type, and download to correct directory
    						url_chk "$url" "$mediatype" "$showtitle" "$showname" "$showdate" "$fileform"
    
    				
    					# if file does not exist or times out, save url to check later and log error to output
    						if [[ "$error" || "$failed" || "$empty" ]]; then
    							echo File not downloaded properly...
    							
    							if [[ "$error" || "$empty" ]]; then	
    								echo "$final" does not seem to exist >> "$output"
    								echo "at $url" >> "$output"
    								
    							else
    								echo "$final" failed to download >> "$output"
    								echo "from $url" >> "$output"
    								
    							fi
    							
    							echo Will check it later. >> "$output"
    							
    							echo -e "${showname}\t${mediatype}\t${showtitle}\t${showdate}\t${url}\t${fileform}" >> "$url_store"
    
    					
    					# else, copy url to old list and confirm in output
    						else
    							echo Success!
    							echo
    							
    							echo "$url" >> "$oldurllist"
    							echo "$showtitle" at >> "$output"
    							echo "$url" >> "$output"
    							echo >> "$output"
    							
    							let "newtorrentscount++"
    							
    							count=$newtorrentscount
    					
    							echo Count is $count with url \"$url\" in folder \"$filedir/\"
    							echo
    						fi
    					fi
    			
    					
    					# sleep 1
    
    ## for loop 1-B-a-i done ##
    				done
    				
    				echo
    				echo "Currenturlstring check is done."
    				echo
    			
    				if [ "$count" -lt "1" ]; then
    					echo No new files. >> "$output"
    					echo No new files.
    					echo >> "$output"
    					echo
    				fi
    				
    				echo Pausing for 1 second.
    				sleep 1
    				echo
    
    			else
    				echo "Xmlstarlet found no torrents in the feed $showname. Are you sure it is valid?" >> "$output"
    				
    				echo Pausing for 5 seconds.
    				sleep 5
    				echo
    			fi
    	
    			echo Loop for $showname is complete.
    			echo
    			
    ## for loop 1-B-a done ##
    		done
    		
    		
    		echo Pausing for 1 second.
    		sleep 1
    		echo
    		
    #		echo >> "$output"
    
    		# pseudonotification
    		touch /tmp/newtorrents
    		oldcount=$(cat /tmp/newtorrents)
    		if [ -z "$oldcount" ]; then oldcount=0; fi
    		newsum=$(($newtorrentscount+$oldcount))
    		echo $newsum > /tmp/newtorrents
    		
    		echo "Done with Subcycle $cycle - $subcycle"
    		echo
    
    		if [ $num_cycles -eq 1 ]; then
    			echo Quick run complete. && exit
    		fi
    
    		echo Pausing for 5 minutes.
    		echo
    
    ## for loop 1-B-b ##		
    		for ((a=1;a<=5;a++)); do
    			if [ "$a" != "5" ]; then
    				echo Minute $a
    
    ## for loop 1-B-b-i ##
    				for ((b=1;b<=5;b++)); do
    					sleep 10
    					echo .
    
    ## for loop 1-B-b-i done ##
    				done
    			
    			sleep 10
    			echo
    			
    			else
    				echo Minute 5
    				sleep 10
    				echo .
    				sleep 10
    				echo .
    				sleep 10
    				echo 30 seconds and counting...
    				sleep 10
    				echo 20 seconds and counting...
    				sleep 10
    				echo 10 seconds and counting...
    				sleep 5
    
    ## for loop 1-B-b-ii ##		
    				for ((c=1;c<=5;c++)); do
    					echo "$((6-$c))"
    					sleep 1
    					
    ## for loop 1-B-b-ii done ##
    				done
    			fi
    
    ## for loop 1-B-b done ##
    		done
    		
    		echo
    		
    ## for loop 1-B done ##
    	done
    
    	echo "Done with Cycle $cycle"
    	echo
    
    ## for loop 1 done ##	
    done
    
    IFS=$ORIGINAL_IFS
    # echo IFS is $IFS
    
    ## swap logfiles if necessary
    log_chk $out_log
    log_cln "$com_dir"/logs/ "$out_log"

    I couldn't find the original, so here's something very close if you're interested. I added the "cronlog" bits, as I was using cron at the time in order to run the script.

    Code:
    #!/bin/bash
    # a tvrss.net torrent subscription script 
    # 0.33 by chochem
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation, either version 3 of the License, or
    # (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    printhelp () {
    printf "tvrss is a tvrss.net subscription script. It will check your feeds for 
    new torrent files (.torrent) and download them to a designated folder.
    It can be run manually but it's probably preferable adding it as a 
    crontab entry.
    
    It requires a .tvrss configuration file in the home folder, so run it
    once as 'tvrss --setup' to create one. This will allow you to designate 
    two folders: a 'tvrss' folder where your sbusciption files and log files
    (log of previously downloaded torrents) will be kept) and a 'watch' 
    folder where the .torrent files will be saved.
    
    Subscriptions are given to the script in the form of lines in the 'feeds' file,
    a text file containing a single '[name][tab][feed url]' set per line. This should 
    be kept in the 'tvrss' folder, and can be edited manually or created/expanded by 
    using \"tvrss --add '[feed name of choice]' '[url]'\" (the quotes are important).
    
    There is no notification of the user per se, but the number of downloaded torrents
    is added to the number in a counting file in /tmp (thus it will be reset whenever /tmp 
    is cleared, usually at reboot), making it available for other scripts/programs to pick 
    up, e.g. 'watch'.
    
    REQUIRES:
    - xmlstarlet to parse the feed (apt package: xmlstarlet)
    - suggested: a torrent client that lets you use a watch folder (torrent files
      in said folder are automatically loaded), e.g. rtorrent and utorrent.
    "
    exit
    }
    
    setupConfFile () {
    rm ~/.tvrss &> /dev/null
    printf "Entering tvrss configuration. This will produce a configuration file
    (.tvrss) in your home directory in order to save your settings. Please see 
    'tvrss --help' for more details."
    echo
    read -p "Where would you like tvrss to store your tvrss .feed and .log files 
    (e.g. '/home/user/p2p/tvrss')? " tvrssdir
    if [ ! -d "$tvrssdir" ]; then 
    	read -p "$tvrssdir is not a directory - do you wish to create it now? (y/n) " reply
    	if [ "$reply" = "y" ]; then 
    		mkdir -p "$tvrssdir" && echo "tvrssdir=${tvrssdir}" >> ~/.tvrss
    	else
    		echo "Please try again" && exit
    	fi
    else 
    	echo "tvrssdir=${tvrssdir}" >> ~/.tvrss
    fi
    echo
    read -p "Where would you like tvrss to store your downloaded .torrent files 
    (suggestion: the folder you have told your torrent client to watch for new 
    .torrent files, e.g. '/home/user/p2p/watch')? " watchdir
    if [ ! -d "$watchdir" ]; then 
    	read -p "$watchdir is not a directory - do you wish to create it now? (y/n) " reply
    	if [ "$reply" = "y" ]; then 
    		mkdir -p "$watchdir" && echo "watchdir=${watchdir}" >> ~/.tvrss
    	else
    		echo "Please try again" && exit
    	fi
    else 
    	echo "watchdir=${watchdir}" >> ~/.tvrss
    fi
    echo "Setup done" && exit
    }
    
    # check for conf file
    ORIGINAL_IFS=$IFS
    IFS=$'\n'
    if [ -f ~/.tvrss ]; then
    	. ~/.tvrss
    else
    	echo "Config file missing. Please run 'tvrss --setup' to create one."
    	exit
    fi
    
    # check for help & setup parameters
    case "$1" in 
    	-h) printhelp;;
    	--help) printhelp;;
    	--setup) setupConfFile;;
    	--add) echo -e "$2\t$3" >> "${tvrssdir}/feeds" && echo "${2} feed added." && exit;;
    esac
    
    # global initialisation
    [ -d "$tvrssdir" ] || mkdir -p "$tvrssdir"
    [ -d "$watchdir" ] || mkdir -p "$watchdir"
    newtorrentscount=0
    
    # for-each-tvshow-subscription-do loop
    for tvshow in $(cat "$tvrssdir"/feeds); do
    
    	# clearing temporary files and variables
    	rm "$tvrssdir"/tmp/tmpxml &> /dev/null
    	showname="$(echo "$tvshow" | cut -f 1)"
    	feedurl="$(echo "$tvshow" | cut -f 2)"
    	oldurllist="${tvrssdir}/${showname}.log"
    	cronlog="${tvrssdir}/cron.txt"
    	touch "$oldurllist"
    	touch "$cronlog"
    	oldurlstring=$(cat "$oldurllist")
    	count=0
    	
    	# start log feed
    	echo `date` >> "$cronlog"
    	
    	# get and parse the rss feed
    	currenturlstring="$(xmlstarlet sel --net -t -m "/rss/channel/item" -v "link" -o "" -n "$feedurl")"
    		
    	# check for URLs not in the log, get new ones, add the entry to the log file
    	if [ -n "$currenturlstring" ]; then 
    		for url in $currenturlstring; do
    			if [[ ! "$oldurlstring" =~ "$url" ]]; then
    			#	torrentfilename="${watchdir}/${showname}_$(date +%y%m%e)_$(date +%H%M%S%N).torrent"
    			#	wget -q -O "$torrentfilename" "$url"
    				wget -q -P "${watchdir}" "$url"
    				echo "$url" >> "$oldurllist"
    				echo "$url" >> "$cronlog"
    				let "newtorrentscount++"
    			fi
    			
    			count=$newtorrentscount
    
    		done
    			
    		if [ "$count" -lt "1" ]; then
    			echo No torrents. >> "$cronlog"
    		fi
    
    	else
    		echo "Xmlstarlet found no torrents in the feed $showname. Are you sure it is valid?" >> "$cronlog"
    	
    	fi
    	
    done
    IFS=$ORIGINAL_IFS
    
    # pseudonotification
    touch "$tvrssdir"/tmp/newtorrents
    oldcount=$(cat "$tvrssdir"/tmp/newtorrents)
    if [ -z $oldcount ]; then oldcount=0; fi
    newsum=$(($newtorrentscount+$oldcount))
    echo $newsum > "$tvrssdir"/tmp/newtorrents

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •