LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python script download torrents (https://www.linuxquestions.org/questions/programming-9/python-script-download-torrents-368161/)

shanenin 09-29-2005 11:48 AM

python script download torrents
 
I want to make a python script that will automatically download torrent files for me. I am able to use feedparser.py to get a url from a rss feed. here is what the url looks like
http://isohunt.com/btDetails.php?ihq...ens&id=6071088

on this page(the link above) their is a link I click on called "download.torrent". Then that opens up the save dialog in my browser that allows me to download the torrent file. Is there a way to download this torrent file, aoutomatically(not using my web browser) using urllib2 or some other module? Any suggestions would be appreciated. Thanks :-)

Hko 09-29-2005 12:44 PM

Code:

#!/usr/bin/env python

import urllib

def progress(blocks, blocksize, filesize):
        bytes = blocks * blocksize
        if bytes >= filesize: return
        perc = (100.0 * bytes) / filesize
        print '%.1f%% done so far.' % perc

url = 'http://www.nl.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2'
localfile = '/tmp/oldkernel.tar.bz2'
urllib.urlretrieve(url, localfile, progress)
print 'Finished.'


shanenin 09-29-2005 01:03 PM

Thanks :-)

That was to easy. I have used urllib.urlretrieve in the past, but did not think it would work. Here is where I got confused. To test it I tried to use wget like this
this failed(I assumbed urllib would also fail). I thought because the url did not end with a file name, it was going to be more complex(I know next to nothing about web or web programming)

but this works great
Code:

urllib.urlretrieve('http://isohunt.com/download.php?mode=bt&id=6071088', 'king.torent')
I really liked your progress function, I will keep that code saved for a raining day :-)


All times are GMT -5. The time now is 06:05 PM.