Page 1 of 1

Scripts: Auto Ezrss, New Blocklists.

Posted: Mon Jun 25, 2012 8:25 pm
by robz
Auto Ezrss

Code: Select all

#!/bin/bash
# Filename: mypvr.sh
# Version: 081211
# Author: robz
# This script uses http://ezrss.it to check for the lastest episodes of your
# favorite tv shows, which you'll have listed in the "followed-shows" file.
# Run mypvr.sh from your chosen directory. First, the above list file will be
# set up, once this is done the script can be controlled via a crontab or on
# PC startup, or both. Here's a crontab to check for new shows every 2 hours.
# 25 */2 * * * export DISPLAY=:0 && /$HOME/PVR/mypvr.sh >/dev/null 2>&1
# Selected .torrent trackers will be sent to your "Downloads" directory ready
# to be picked up by "Transmission" gui/daemon or any other client that can be
# set to auto-load from a monitored directory.

SHOW_NAME_EXACT=""                  # Allow some search leeway.
QUALITY="hdtv"                      # HDTV standard quality.
QUALITY_EXACT="true"                # Only hdtv not 720p - no huge files.
DWNLDS="$HOME/Downloads"            # Default Downloads, change if you like.
green="<span color=\"#008000\">"    # Green ok! :p

func_form_url ()                                    # Create web search url.
{
WEBSITE="http://ezrss.it/search/index.php?show_name="$SHOW_NAME"&\
show_name_exact=$SHOW_NAME_EXACT&date=&quality=$QUALITY&\
quality_exact=$QUALITY_EXACT&release_group=&mode=simple"
}

cd "$(dirname "$0")"                                # Do cd to "mypvr.sh" dir.

trap "rm -f "newlist" "urllist"; exit" \
INT TERM EXIT                                       # Clean up cruft on close.

if [ ! -e "donelist" ]; then touch donelist; fi     # Check donelist exists.
if [ ! -e "followed-shows" ]; then                  # Check shows list exists.
cat > followed-shows << EOF
# Type the names of tv shows to be followed into this list.
# Hash commented, like this line, and blank lines will be ignored.
# To stop a show search, comment "#" the line or delete it :)

Spooks
#Terra Nova < examples, delete and replace with yours.
Dexter

# End of list - a blank line is required above this line.
EOF
gedit followed-shows                                # Edit new shows list.
exit; fi

while read SHOW_NAME; do                            # Read followed-shows list.
    if [[ "${SHOW_NAME:0:1}" != "#" && -n "$SHOW_NAME" ]]; then
        SHOW_NAME=$(echo "$SHOW_NAME" | sed -e 's/ \+/+/g')
        func_form_url                               # Create custom url.
        # Get web pages for shows, take episode at top of page - newest.
        wget -q --random-wait -O - $WEBSITE |\
        egrep -om1 "http:.*.torrent" >> urllist
    fi
done < followed-shows                               # Feed followed-shows.

sort -u urllist > newlist                           # De-dupe, make copy.

# Whittle away the URL bumf for a naked "newlist".
sed -i 's#http:/[^",]*/##' newlist
sed -i 's/\([Ee][0-9][0-9]\)\+.*/\1/' newlist       # S01E02 - s01e02.
sed -i 's/\([Xx][0-9][0-9]\)\+.*/\1/' newlist       # 1X02 - 1x02 - 01X02.
#sed -i 's/\([0-9][0-9][0-9]\)\+.*/\1/' newlist     # 102 ? (V2009)?! aah!
sed -i '/torrent/d' newlist                         # Remove strays.

sort newlist -o newlist                             # Sort stripped list.

NEW=$(comm --check-order -23 newlist donelist)      # Compare new/existing.
if [ -z "$NEW" ]; then exit; fi                     # $tring null? then exit.

for LINE in $NEW; do SEL+=" TRUE $LINE"; done       # Prepend entries "TRUE".

# Option for 10 mins to choose/cancel or it auto-downloads all new trackers.
CHOOSE=$(zenity --title "PVR" --timeout 600 --width 300 --height 225 \
--list --text "$green""There are new TV episodes available</span>" \
--checklist --column " #" --column "Download torrent trackers for:" $SEL)
EXITCODE="$?"

if [ "$EXITCCODE" = 1 ] || [[ "$EXITCODE" = 0 && -z "$CHOOSE" ]]; then
    exit                                            # Null entry or cancel.
elif [ -z "$CHOOSE" ]; then                         # $CHOOSE empty, use $NEW.
    CHOOSE=$(echo $NEW | sed 's/  */|/g')           # Add "|" egrep delimiters.
    zenity --notification --text "Auto download of latest TV trackers"\
    & disown
fi

timeout 60 \
wget --no-clobber --random-wait --directory-prefix=$DWNLDS \
--input-file=$(egrep $(echo $CHOOSE) urllist)       # Go "wget" the trackers.

CHOOSE=$(echo "$CHOOSE" | sed 's/|/ /g')            # Strip delimiters.

# If tracker has downloaded correctly, make entry to "donelist".
for LINE in $CHOOSE; do
    if [ $(ls "$DWNLDS" | grep $LINE) ]; then echo "$LINE" >> donelist
    elif [ -z $PID ]; then zenity --notification\
        --text="`echo -e "One or more trackers has failed to download.\
        \nNext try is scheduled for $(date --date='+2 hours' +%H:25) hours."`"\
        & disown
        PID=$!                                      # Just one notification.
    fi
done

sort donelist -o donelist                           # Sort new "donelist".

notify-send -i '/usr/share/icons/hicolor/scalable/apps/transmission.svg' \
"Tracker files downloaded" "$(ls "$DWNLDS" | grep "\.torrent")" &
New Blocklists.

Code: Select all

#!/bin/bash
# Filename: blocklists.sh
# Version: 180511
# Author: robz
# AFAIK "transmission" can only be configured to download a single blocklist
# automatically. That default, if set, being the level1 blocklist from
# http://update.transmissionbt.com/level1.gz. This script is to auto download
# the latest or extra P2P blocklists to suppliment or replace the default.
# All being well the script will download from the "$URLS" list and create a
# file which "transmisson-gtk" can parse, the old list will then be replaced
# ready for "transmission-gtk" to create a new binery file on startup.
# If this doesn't happen for some reason the existing will be left in place.
# Script can be used on it's own, or uncomment the last line and create a
# custom launcher for the Transmission bittorent client.

# Some reading http://torrentfreak.com/do-p2p-blocklists-keep-you-safe/
# Some suggested urls:
# http://list.iblocklist.com/?list=bt_level1        # General default list.
# http://list.iblocklist.com/?list=bt_level2        # Labs or researchers.
# http://list.iblocklist.com/?list=bt_level3        # The paranoids list.
# http://list.iblocklist.com/?list=bt_bogon         # Unallocated addresses.
# http://list.iblocklist.com/?list=bt_templist      # Suspected bad peers.
# http://list.iblocklist.com/?list=bt_spyware       # Suspected spy/malware.

# Add urls to this $URLS list.
URLS="
http://list.iblocklist.com/?list=bt_level1
http://list.iblocklist.com/?list=bt_level2
http://list.iblocklist.com/?list=bt_level3
http://list.iblocklist.com/?list=bt_bogon
"                                                   # $List of lists.
TMP="/tmp/blocklists/"                              # Temporary workspace.
LISTS="$HOME/.config/transmission/blocklists"       # Blocklists location.

rm -rf $TMP; mkdir $TMP; cd $TMP                    # Clear the way.
wget --retry-connrefused $URLS                      # Get lists.....persist.
if [ ! $? = 0 ]; then exit $?; fi
cat * > extras.gz                                   # Concatenate the lists.
gunzip -c extras.gz > extras
if [ ! $? = 0 ]; then exit $?; fi
if [[ -s "extras" ]]; then
    sort -u extras -o extras.txt                    # Sort unique to txt file.
else exit $?
fi
rm -f $LISTS/extras*                                # Purge old txt/bin files.
mv -f extras.txt $LISTS/"extras-$(date +%d-%b-%R).txt"

#transmission-gtk &                                 # Start bt client?
Both these work for me with Ubuntu 12.04, any suggestions to improve my dodgy code are welcome.
robz.

Re: Scripts: Auto Ezrss, New Blocklists.

Posted: Sun Jul 01, 2012 6:39 pm
by shaneosdn
Just wanted to check on the blocklists script. All I have to do is execute and Transmission will read the blocklist from its .config directory or do I need to edit transmission somewhere?