r/Python • • Dec 29 '12

Simple script to download TPB torrent files

https://github.com/santiagobasulto/tpb-download/blob/master/README.md
3 Upvotes

14 comments sorted by

4

u/tty2 Dec 29 '12

11 sloc

1

u/Adys HearthSim Dec 29 '12

Yeah; I love Python but this is the kind of stuff that belongs in a shell script, to be honest.

3

u/name_censored_ Dec 30 '12 edited Dec 30 '12

Bash:

tpb-download()
{
    # Downloads one or more torrent files from ThePirateBay.org

    TPB_URL='http://torrents.thepiratebay.se'

    [[ -z "$@" ]] && { echo 'One or more Torrent IDs to download' ; return 1 ; }
    which wget 2>&1 >/dev/null || { echo 'ImportError: No binary named `wget`' >&2 ; return 2 ; }        

    echo 'Starting to download torrent files.'
    
    for torrent_id in $@
    do
        [[ $torrent_id =~ ^[0-9]+$ ]] || { echo 'TypeError: Expected `int`, received `'"$torrent_id\`" >&2 ; return 4 ; }
        echo "Downloading $torrent_id.torrent"
        wget -O $torrent_id.torrent "$TPB_URL/$torrent_id/$torrent_id.torrent"
    done

    echo 'Done downloading torrents.'
}

1

u/jameswf Dec 30 '12

or you could just libtorrent?

1

u/[deleted] Jan 01 '13

can someone please explain the usage of name and main???

i see these all over the place but for the life of me i have no clue what it means or where to find it in the python docs.

2 weeks into python.

thanks!

1

u/DiThi Jan 02 '13

When you do

import something

the contents of the file something.py is executed. Say you want to use that file as a stand-alone executable but also as a module, and you don't want the stand-alone code to be executed when imported as a module.

Well... there's a special variable called __name__ which holds the module name... if imported as a module, otherwise it's "__main__".

Type "__this__" in reddit comments to write "__this__" instead of "this".

1

u/[deleted] Jan 02 '13

ahhh I see! thank you very much. I just found the documentation on importing modules now that I know where to look, so I'll figure out to implement this.

yeah, I noticed my error in posting but figured it wouldn't be worthing editing because the thread was getting old and had little attention.

-1

u/AndrewCoja Dec 29 '12

There is a link to download the torrent file on TPB.

3

u/Han-ChewieSexyFanfic Dec 29 '12

Not for newer torrents, only the magnet link is visible.

3

u/qnrq Dec 29 '12 edited Dec 29 '12

Magnet links can keep BitTorrent hosts out of jail; the TPB founders were convicted for hosting torrent files. Why not just use a client that supports them?

EDIT: By the way your link goes to README.md. README.md is displayed directly on the project page here, and if you link there people don't have to click twice to find the script src: https://github.com/santiagobasulto/tpb-download

EDIT2: Also, wouldn't it be better to parse the magnet link or the link to the torrent page on TPB instead? IDs suck.

1

u/mgrandi Dec 29 '12

yep. the magnet link makes it so that they arnt hosting the torrent files, that way you download the torrent files from other people.

1

u/Han-ChewieSexyFanfic Dec 29 '12 edited Dec 29 '12

It's not my link and it's not my project. I was just answering AndrewCoja's comment.

0

u/qnrq Dec 29 '12

Sorry, lost track of the nicknames. My answer remains the same though :)

0

u/[deleted] Dec 29 '12

[deleted]

2

u/[deleted] Dec 29 '12

It does. For instance http://torrents.thepiratebay.se/7968597/7968597.torrent links to the torrent here.