#!/bin/bash #############==============-------------- # XTVI SSATEUR: Site-Specific Automatic Torrent Extractor Using RSS # Authored By: Andrew Rowls # !--> Works ONLY with torrent feeds from http://www.xtvi.com/all_tv_shows # !--> If this script successfully parses feeds from any other site, it's sheer coincidence # #####==============-------------- # IMPORTANT: XTVI has implemented CAPTCHAs for a reason. "To protect our servers from heavy # traffic". And I agree. While I don't believe this script will particularly tax XTVI's # servers simply by being run once, you should not be so rude as to run it many times # within a short time span, especially if you have many feeds you check. Since TV shows # typically don't air more than once a week, ideally you should only run this script # once a week. However, since it is typically desirable to have a copy of a show by the # day after it airs, I would recommend running the script no more than once per day, at # least several hours after the latest show of interest has aired. For example, my shows # typically air around 8-10PM EDT. The torrents for these shows are guaranteed to show up # by 5AM the next morning. Therefore, I have cron set to run this script once per day at # 5AM. This almost guarantees that I will be able to start downloading shows from the # previous night. # Again, please be courteous when setting this script to run. And don't blame me if XTVI # freezes, bans, locks, or warns you, for whatever reason. # #####==============-------------- # See the README for an explanation of the script # #####==============-------------- # # Fixes some issues with CRON's default env. Change HOME to your home directory, or remove if appropriate PATH=/bin:/usr/bin:/usr/sbin:$PATH HOME=/home/andrew db=~/bin/xtvirss/gotten.txt dest=/torrents/loading feeds=~/bin/xtvirss/feeds.txt cookies=~/bin/xtvirss/cookies.txt # Change these. user=xtvi_username pass=xtvi_pass cookies=`echo "$cookies" | replace " " "\ "` wgetopts="--keep-session-cookies --load-cookies $cookies --save-cookies $cookies" # Check if XTVI is up. If not, wait 2hrs before trying again. Etc. ping=`ping -c 1 -t 60 xtvi.com 2>&1 | grep "\(unknown host\)\|\(Time to live exceeded\)\|\(opendns.com\)" -c` while [ $ping -eq 1 ]; do echo -e "`date`\tXTVI.com is down." sleep 120m ping=`ping -c 1 -t 60 xtvi.com 2>&1 | grep "\(unknown host\)\|\(Time to live exceeded\)\|\(opendns.com\)" -c` done # If not logged in, log in to avoid captchas logged=`cat "$cookies" | grep "\($user\)\|\($pass\)" -c` if [ $logged -ne 2 ]; then wget $wgetopts --post-data "mode=dologin&name=$user&pass=$pass" -O /dev/null http://www.xtvi.com/torrents.php?mode=login 2>/dev/null fi feeds=`cat "$feeds" | grep -v "^#"` for RSS in $feeds; do titles=`wget $RSS -O- 2>/dev/null | grep "" | replace "<title>" "" "" "" " " "~"` i=0 for title in $titles; do file=`echo $title | replace "~" " "` # echo $file show=`echo "$file" | grep -io ".*S[0-9]\{1,2\}E[0-9]\{1,2\}"` # if [ -z "$show" ]; then # show=`echo "$file" | grep -io ".*[0-9]\{1,2\}x[0-9]\{1,2\}"` # fi if [ -z "$show" ]; then continue fi name=`echo "$show" | grep -io ".*[ \.]" | replace "." " " "-" " " "_" " "` while [ -n "`echo "$name" | grep \" \{2\}\"`" ]; do name=`echo "$name" | replace " " " "` done name=`echo "\`expr "$name" : '[ ]*\(.*\)[ *]$'\`"` # echo -e "\t\"$show\"" # echo -e "\t\"$name\"" season=$((`echo "$show" | grep -io "S[0-9]\{1,2\}" | replace "S" "" "s" ""`)) # if [ $season -eq 0 ]; then # season=$((`echo "$show" | grep -io "[0-9]\{1,2\}x" | replace "X" "" "x" ""`)) # fi if [ $season -ne 0 ]; then # echo -e "\t$season" episode=$((`echo "$show" | grep -io "E[0-9]\{1,2\}" | replace "E" "" "e" "" | sed 's/^0//'`)) # echo -e "\t$episode" if [ $episode -ne 0 ]; then # echo -e "\t$name $season $episode" gotten=`cat "$db" | grep -v "^#" | grep -ic "$name $season $episode"` if [ $gotten -eq 0 ]; then echo "$name $season $episode" >> "$db" links=`wget $RSS -O- 2>/dev/null | grep "" | replace "" "" "" "" " " "~"` j=0 for link in $links; do if [ $j -eq $i ]; then link=`echo $link | replace "~" " " "&" "&"` #echo $file #echo -e "\t$link" name=`echo "$name" | replace " " "."` url=`wget $wgetopts -O- "$link" 2>/dev/null | grep -o "$file"` url=`echo "$url" | grep -o "\"[^\"]*\"" | replace "\"" "" "torrents.php?mode=details&id=" ""` wget $wgetopts -O /dev/null "http://www.xtvi.com/torrents.php?mode=details&id=$url" 2>/dev/null url="http://www.xtvi.com/torrents.php?mode=gettorrent&id=$url" #echo -e "\t$url" wget $wgetopts -O "$dest/${file}.torrent" "$url" 2>/dev/null if [ `grep -ic "cookies are required" "$dest/${$ rm "$dest/${file}.torrent" else echo "$name $season $episode" >> "$db" fi fi j=$(($j+1)) done fi fi fi i=$(($i+1)) done done