1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

add variable number of pages to fetch option

This commit is contained in:
Viktor Stanchev 2013-02-27 12:14:39 -05:00
parent f5e5a5487a
commit 4606e3a32e

View File

@ -40,6 +40,7 @@ def main():
parser = argparse.ArgumentParser(description='Finds and downloads torrents from the Pirate Bay')
parser.add_argument('q', metavar='search_term', help="The term to search for")
parser.add_argument('--local', dest='database', help="An xml file containing the Pirate Bay database")
parser.add_argument('-p', dest='pages', help="The number of pages to fetch (doesn't work with --local)", default=1)
def local(args):
xml_str = ''
@ -51,12 +52,20 @@ def main():
#todo: redo this with html parser instead of regex
def remote(args):
f = urllib2.urlopen('http://thepiratebay.se/search/' + args.q.replace(" ", "+") + '/0/7/0')
res_l = []
try:
pages = int(args.pages)
if pages < 1:
raise Exception('')
except Exception:
raise Exception("Please provide an integer greater than 0 for the number of pages to fetch.")
for page in xrange(pages):
f = urllib2.urlopen('http://thepiratebay.se/search/' + args.q.replace(" ", "+") + '/' + str(page) + '/7/0')
res = f.read()
found = re.findall(""""(magnet\:\?xt=[^"]*)|<td align="right">([^<]+)</td>""", res)
state = "seeds"
curr = ['',0,0] #magnet, seeds, leeches
res_l = []
for f in found:
if f[1] == '':
curr[0] = f[0]
@ -77,9 +86,9 @@ def main():
else:
mags = remote(args)
if mags and len(mags) > 0:
print "S=seeders"
print "L=leechers"
if mags:
for m in range(len(mags)):
magnet = mags[m]
name = re.search("dn=([^\&]*)", magnet[0])