mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-25 12:24:20 +01:00
add variable number of pages to fetch option
This commit is contained in:
parent
f5e5a5487a
commit
4606e3a32e
@ -40,6 +40,7 @@ def main():
|
|||||||
parser = argparse.ArgumentParser(description='Finds and downloads torrents from the Pirate Bay')
|
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('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('--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):
|
def local(args):
|
||||||
xml_str = ''
|
xml_str = ''
|
||||||
@ -51,12 +52,20 @@ def main():
|
|||||||
|
|
||||||
#todo: redo this with html parser instead of regex
|
#todo: redo this with html parser instead of regex
|
||||||
def remote(args):
|
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()
|
res = f.read()
|
||||||
found = re.findall(""""(magnet\:\?xt=[^"]*)|<td align="right">([^<]+)</td>""", res)
|
found = re.findall(""""(magnet\:\?xt=[^"]*)|<td align="right">([^<]+)</td>""", res)
|
||||||
state = "seeds"
|
state = "seeds"
|
||||||
curr = ['',0,0] #magnet, seeds, leeches
|
curr = ['',0,0] #magnet, seeds, leeches
|
||||||
res_l = []
|
|
||||||
for f in found:
|
for f in found:
|
||||||
if f[1] == '':
|
if f[1] == '':
|
||||||
curr[0] = f[0]
|
curr[0] = f[0]
|
||||||
@ -77,9 +86,9 @@ def main():
|
|||||||
else:
|
else:
|
||||||
mags = remote(args)
|
mags = remote(args)
|
||||||
|
|
||||||
|
if mags and len(mags) > 0:
|
||||||
print "S=seeders"
|
print "S=seeders"
|
||||||
print "L=leechers"
|
print "L=leechers"
|
||||||
if mags:
|
|
||||||
for m in range(len(mags)):
|
for m in range(len(mags)):
|
||||||
magnet = mags[m]
|
magnet = mags[m]
|
||||||
name = re.search("dn=([^\&]*)", magnet[0])
|
name = re.search("dn=([^\&]*)", magnet[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user