<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>DAN FOLKES &#187; search</title>
	<atom:link href="http://danfolkes.com/index.php/tag/search/feed/" rel="self" type="application/rss+xml" />
	<link>http://danfolkes.com</link>
	<description>programmers blog</description>
	<lastBuildDate>Fri, 03 Feb 2012 15:58:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel="next" href="http://danfolkes.com/index.php/tag/search/feed/?page=2" />

		<item>
		<title>Python Torrent Search and Download (TPB)</title>
		<link>http://danfolkes.com/2008/02/06/torrent-search/</link>
		<comments>http://danfolkes.com/2008/02/06/torrent-search/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 04:02:14 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[piratebay]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[torrent]]></category>

		<guid isPermaLink="false">http://danfolkes.com/?p=12</guid>
		<description><![CDATA[This python command line utility will search the pirate bay for a specific search string and pull out the torrent files and download them to your current directory. by: Daniel Folkes This is Licensed under GPLv3. Give Back. Download Source print &#8220;&#8221;"Pirate Bay Torrent Downloader &#8211; Command Line Interface Program Written by: Daniel Folkes website: [...]


Related posts:<ol><li><a href='http://danfolkes.com/2009/04/29/ipmapcom-python/' rel='bookmark' title='Permanent Link: IPMap Python Ip Address Locator Command Line Script'>IPMap Python Ip Address Locator Command Line Script</a></li>
<li><a href='http://danfolkes.com/2008/09/30/python-wunderground-todays-weather-to-email-sms-to-phone/' rel='bookmark' title='Permanent Link: Python: Wunderground Todays Weather to Email SMS to Phone'>Python: Wunderground Todays Weather to Email SMS to Phone</a></li>
<li><a href='http://danfolkes.com/2009/01/22/python-grab-email-from-gmail-and-insert-into-mysql-database/' rel='bookmark' title='Permanent Link: Python: Grab Email from Gmail and Insert into MySql Database'>Python: Grab Email from Gmail and Insert into MySql Database</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>This python command line utility will search the pirate bay for a specific search string and pull out the torrent files and download them to your current directory.</p>
<h3>by: Daniel Folkes</h3>
<h3>This is Licensed under <a href="http://www.gnu.org/licenses/gpl.txt">GPLv3</a>.  Give Back.</h3>
</h3>
<p><a href='http://danfolkes.com/index.php/2008/02/06/torrent-search/attachment/19/' rel='attachment wp-att-19' title='tpb.jpg'><img src='http://danfolkes.com/wp-content/uploads/2008/02/tpb.jpg' alt='tpb.jpg' /></a></p>
<ol><a href='http://danfolkes.com/wp-content/uploads/2008/02/torrentsearch.py' title='Download Source'>Download Source</a>
<li>print &#8220;&#8221;"Pirate Bay Torrent Downloader &#8211; Command Line Interface
</li>
<li>
</li>
<li>        Program Written by: Daniel Folkes
</li>
<li>        website: http://danfolkes.com
</li>
<li>        email: danfolkes @t gmail dot c0m<br />
<span id="more-12"></span>
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8212; Usage  &#8212;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;-a[n]      =  auto downloads first [n] results (default:10)
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;-o[/path/] =  points to the folder where .torrent&#8217;s go
</li>
<li>&#8220;&#8221;"
</li>
<li>
</li>
<li>import urllib2
</li>
<li>import sys
</li>
<li>autoprint = 0
</li>
<li>outgoing = &#8220;./&#8221;
</li>
<li>searchFor = []
</li>
<li>for arg in sys.argv[1:]:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;print &#8220;|&#8221;+arg+&#8221;|&#8221;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;if arg[:2] == &#8220;-a&#8221;:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;autoprint = int(arg[2:len(arg)])
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;elif arg[:2] == &#8220;-o&#8221;:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outgoing = arg[2:len(arg)]
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;else:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searchFor.append(arg)
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;
</li>
<li>print &#8220;Searching The Pirate Bay for: &#8221; + str(searchFor)
</li>
<li>
</li>
<li>url = &#8216;http://thepiratebay.org/search.php?q=&#8217;
</li>
<li>o = 0;
</li>
<li>for ar in searchFor:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;if o != 0:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url+=&#8221;%20&#8243;&nbsp;&nbsp;&nbsp;&nbsp;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;url+=str(ar)
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;o +=1
</li>
<li>print &#8220;URL: &#8221; + url
</li>
<li>req = urllib2.Request(url)
</li>
<li>response = urllib2.urlopen(req)
</li>
<li>the_page = response.read()
</li>
<li>results = 15
</li>
<li>i=0
</li>
<li>listing = []
</li>
<li>for line in the_page.split(&#8220;&lt;td&gt;&#8221;):
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;if i &lt; results:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if line.count(&#8220;.torrent&#8221;):
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strippedLine = line[9:line.find(".torrent")+8]
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if autoprint == 0:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print i, strippedLine[15:]
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;listing.append(strippedLine)
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i+=1
</li>
<li>if autoprint==0:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;download = raw_input(&#8220;Which ones to download?(sep by commas) :&#8221;).split(&#8216;,&#8217;)
</li>
<li>else:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;download = range(0,autoprint)
</li>
<li>print download
</li>
<li>
</li>
<li>for j in download:
</li>
<li>        g = int(j)
</li>
<li>        if (g &lt; results) and (g &gt;=0):
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&#8212; Strip Characters Off
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localPath = listing[g]
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for c in &#8220;.:/%!@#$^&#038;*()_-=+~`[]{}|;&#8217;,.&#8221;:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        localPath = localPath.replace(c,&#8221;")
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localPath = localPath[(len(localPath)/2):]
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localPath += &#8220;.torrent&#8221;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if outgoing:
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;localPath = outgoing+localPath
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&#8212;
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &#8220;Downloading: &#8220;+ listing[g] + &#8221; -&gt; &#8221; + str(localPath)
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;open(localPath, &#8216;wb&#8217;).write(urllib2.urlopen(listing[g]).read())
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#import os &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#if you want to use wget and have progress bar (remove line before)
</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#os.system(&#8220;wget &#8220;+listing[g]) &nbsp;&nbsp;&nbsp;&nbsp;#if you want to use wget and have progress bar
</li>
<li>
</li>
<li>print &#8220;&#8230;Download Complete&#8221;
</li>
</ol>


<p>Related posts:<ol><li><a href='http://danfolkes.com/2009/04/29/ipmapcom-python/' rel='bookmark' title='Permanent Link: IPMap Python Ip Address Locator Command Line Script'>IPMap Python Ip Address Locator Command Line Script</a></li>
<li><a href='http://danfolkes.com/2008/09/30/python-wunderground-todays-weather-to-email-sms-to-phone/' rel='bookmark' title='Permanent Link: Python: Wunderground Todays Weather to Email SMS to Phone'>Python: Wunderground Todays Weather to Email SMS to Phone</a></li>
<li><a href='http://danfolkes.com/2009/01/22/python-grab-email-from-gmail-and-insert-into-mysql-database/' rel='bookmark' title='Permanent Link: Python: Grab Email from Gmail and Insert into MySql Database'>Python: Grab Email from Gmail and Insert into MySql Database</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://danfolkes.com/2008/02/06/torrent-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:thumbnail url="http://danfolkes.com/wp-content/uploads/2008/02/tpb.jpg" />
		<media:content url="http://danfolkes.com/wp-content/uploads/2008/02/tpb.jpg" medium="image">
			<media:title type="html">tpb.jpg</media:title>
		</media:content>
	</item>
	</channel>
</rss>

