Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.

Basic PVR

# Filename:
# Version: 081211
# Author: robz
# This script uses to check for the lastest episodes of your
# favorite tv shows, which you'll have listed in the "followed-shows" file.
# Run 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/ >/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.

"$(dirname "$0")"                                # Do cd to "" 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 :)

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

# End of list - a blank line is required above this line.
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
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)

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

timeout 60 \
wget --quiet --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.

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")" &

No comments: