LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-29-2005, 11:48 AM   #1
shanenin
Member
 
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 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 :-)
 
Old 09-29-2005, 12:44 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
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.'
 
Old 09-29-2005, 01:03 PM   #3
shanenin
Member
 
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
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 :-)

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


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:56 AM.

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