Home / Naruto downloader script

If, as me, you like Naruto, this script is perhapse for you !
The script will scan bakasan.net every couple of minutes and search if the new episode is out, and download it automatically if yes !
Naruto is a funny and distractive manga I like. BakaSan is a team of translators who provides an english version of Naruto. Download the serie is legal in some cuntrys, because of a lack of deposed copyrights in them.

Screenshot of the script running in Konsole

Requierments

You need to download and install BitTorrent.
Normaly, lynx, grep and awk are installed with your distribution : they are needed for the script.

How to use

First, create a file "~/naruto_downloader.bash" for exemple and paste the code below.
Make the file executable. With the command chmod +x ~/naruto_downloader.bash. Or by file Properties / Permitions / "Is executable" in a grapic desktop.
That's all : all times you have a new episode to download, just run ~/naruto_downloader.bash 79, where 79 is the number of the soon available episode !
By default, the episode will be saved in your home directory, with name "~/[BakaSan]_Naruto_$number.avi". You can edit the script and change the variable target. You also can change time to set a different wait time between tries.

The script

#!/bin/bash
#naruto_downloader.bash

# This script download the last espisode of Naruto from [BakaSan]
#  as soon as it is out (few minutes)

# Episode to download
#  $# : Number of arguments given to the script
#  $1 : 1° argument given to the script
if [ $# != 1 ]; then
  echo "Usage : $0 episodeNumber"
  exit 1;
fi
number=$1

##
## You can configure those two parameters :
##

# Target file where to save the downloaded episode :
target=~/[BakaSan]_Naruto_$number.avi
# Wait duration (in minutes) between each trys :
time=5

echo "Wait for download Naruto episode #$number..."

# Try while episode isn't available yet
while ((1)); do
  # Download the home page where is the bittorrent link
  #  `lynx --dump` return HTML page from lynx
  #                AND add a section References at the end
  #                with all links " 1. http://..."
  #  A grep allow to get the link with the number of the
  #   episode to download
  link=`lynx --dump "http://www.bakasan.net/" | grep -E '[0-9]+\. .*'$number`

  # Get the bittorent link (2° field of " 1. http://...")
  link=`echo $link | awk '{print $2}'`

  # -z : empty
  # -n : not empty
  if [ -z "$link" ]; then
    # Cf below for explanation of this line
    echo `uptime | cut -d " " -f 2 | cut -d ":" -f "1 2" --output-delimiter "H"`" - :-("
    # The last Naruto isn't out yet :
    #  We wait $time minutes before to retry
    sleep $(($time*60))
  else
    # Get the current time
    #  uptime : " 19:50:30 up  4:23,  1 user,  load average: 0.37, 0.22, 0.15"
    #  1° cut : "19:50:30" (column 2)
    #  2° cut : "19H50"    (column 2 and 3 with "H" as output separator)
    heure=`uptime | cut -d " " -f 2 | cut -d ":" -f "1 2" --output-delimiter "H"`
    # Beep to avert user the begin of the download
    echo $'\a'
    # And display wanted informations
    echo "$heure - The last Naruto is available. Download of :"
    echo "$link"
    # Finaly, begin the download
    btdownloadgui.py $link --saveas $target
    # That's all (we hope) : quit the script
    exit
  fi
done

You also can download the script or download the french version.