Showing posts with label pirate. Show all posts
Showing posts with label pirate. Show all posts

ThePirateBay.se search script

This ThePirateBay.se torrent search script is based on the quite modular Torrentz.eu one I've made a while ago. You can find it on my GitHub as will be usual for all of my future scripts and stuff, so don't forget to add me to your watch list :).

This deprecates the old TPB search script.

I'll greatly appreciate any feedback, so don't hesitate to leave a comment if you'd like to. Improvement ideas are also welcome ;).

You can also modify and reuse all my scripts listed in the repo if you feel like it as they're licensed under GPLv3.

Torrentz.eu search shell script

Torrentz.eu is a great meta-search engine collecting info from dozens of torrent hosting sites, such as ThePirateBay.se. You can read through the complete list of scraped sites right here (almost 7M of live torrents indexed as of now, ThePirateBay alone has "only" 3.1M).

I've written this /bin/sh compatible script mainly because my previous torrent search script for ThePirateBay stopped to function properly and I was just too lazy to rewrite the code to work with TPB's new way of offering torrent downloads -- via magnet links, which are great by the way ;).


Oh, and just in case you've missed it: you can download an offline copy of TPB's torrent database in format suitable for making and SQLite database and searching torrents completely anonymously. Hell, it's just 90 megs! However, pr0n is not included, so it's only 1,643,194 torrents :P.

OK, so let's go to the point. Here's a screenshot:

As you can see, it has a nice colorized output (um... well, it can be disabled with the -C cmdline switch) and shows first 15 results by default (a max. of 50 due to pagination, sometimes less due to DMCA takedown notices sent to torrentz.eu -- it's quite funny how they just let you know which torrents exactly are they watching :P).

And t3h s0urc3, ofc: see this pastebin, it's more readable and copypastable than listing it here. Be sure to edit the torrent download command at the beginning of the script if you're using client other than Transmission. You can also change the default number of displayed results and output colors if you'd like. Don't forget to leave a comment or drop some spare coin into my PayPal account if you like my works ;).

My shell scripts #4 - ThePirateBay.org search API

NOTE: This script is now deprecated. Continue to the new version.

A command-line interface for ThePirateBay.org! Usage is simple:
./tpb.sh [search string]
You can easily change transmission to any other torrent client (which supports adding torrents by URL via CLI). The dirty sed magic can be optimized, but it works as is, so why bother? ;) Enjoy!

tpb.sh script in action via PuTTY
The code:
#!/bin/ash
search() {
  q="$*"
  q=`echo $q | tr ' ' '+'`
  results=`wget -U Mozilla -qO - "http://thepiratebay.org/search/$q/0/7/0" \
    | egrep -o '(http\:\/\/.*\.torrent)|(Size\ .*B\,)|([[:digit:]]*)' \
    | sed 's///g' \
    | sed 's/<\/td>//g' \
    | sed 's/Size\ //g' \
    | sed 's/\&nbsp\;//g' \
    | sed 's/\,//g' \
    | sed 's!http://torrents.thepiratebay.org!!g' \
    | sed ':a;N;$!ba;s/\n/\ /g' \
    | sed 's!\ \/!\n\/!g' \
    | sed 's/MiB\ /M\ /g' \
    | sed 's/GiB\ /G\ /g' \
    | sed 's/KiB\ /K\ /g' \
    | cat`
  IFS=$'\n'
  longest=0
  for line in $results
  do
    length=`echo "$line" | awk '{print $1}' | wc -L`
    if [ $length -gt $longest ]
    then
      longest=$length
    fi
  done
  nth=0
  for line in $results
  do
    whites=""
    length=`echo $line | awk '{print $1}' | wc -L`
    nth=`echo "$nth + 1" | bc -l`
    spaces=`echo "$longest + 1 - $length" | bc -l`
    for i in `seq 1 $spaces`
    do
      whites=`echo "$whites "`
    done
    torrent=`echo $line | awk '{print $1}' | sed 's!\/[[:digit:]]*\/!!' | sed 's!\.[[:digit:]]*\.TPB\.torrent!!' | sed 's/_/\ /g'`
    size=`echo $line | awk '{print $2}'`
    size=`printf '%10s' "$size"`
    seeds=`echo $line | awk '{print $3}'`
    seeds=`printf '%5s' "$seeds"`
    peers=`echo $line | awk '{print $4}'`
    peers=`printf '%5s' "$peers"`
    if [ $nth -lt 10 ]
    then
      nth=" $nth"
    fi
    echo -e "$nth  $torrent$whites\033[1;34m$size\t\033[1;31m$seeds\t\033[1;32m$peers\033[0m"
  done
}
download() {
  echo -n "Download? "
  read num
  if [ $num -eq 0 ]
  then
    exit 1
  else
    i=0
    for line in $results
    do
      i=`echo "$i + 1" | bc -l`
      if [ $i -eq $num ]
      then
        link=`echo "$line" | awk '{print $1}'`
        echo "Downloading torrent file."
        transmission-remote -a "http://torrents.thepiratebay.org$link"
        echo "Torrent added."
        exit 0
      fi
    done
  fi
}
search $*
download
unset IFS
exit 0