Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-29-2005, 11:48 AM   #1
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Rep: Reputation: 30
python script download torrents

I want to make a python script that will automatically download torrent files for me. I am able to use to get a url from a rss feed. here is what the url looks like

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 :-)
Old 09-29-2005, 12:44 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
#!/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 = ''
localfile = '/tmp/oldkernel.tar.bz2'
urllib.urlretrieve(url, localfile, progress)
print 'Finished.'
Old 09-29-2005, 01:03 PM   #3
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
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
urllib.urlretrieve('', 'king.torent')
I really liked your progress function, I will keep that code saved for a raining day :-)

Last edited by shanenin; 09-29-2005 at 01:08 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
download torrents automatically shanenin Programming 0 10-03-2005 06:51 PM
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
which script stuff to use? --Python ruwach Programming 4 05-27-2005 10:49 AM
Anyone have a HelloWorld Python Qt script? SheldonPlankton Programming 1 07-22-2004 02:52 PM
python script LinuxLala Programming 14 04-07-2004 06:19 AM > Forums > Non-*NIX Forums > Programming

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration