mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
adding --auto and --download command line options
This commit is contained in:
parent
a515098431
commit
cd849c83eb
@ -5,6 +5,7 @@ import urllib2
|
|||||||
import re
|
import re
|
||||||
from HTMLParser import HTMLParser
|
from HTMLParser import HTMLParser
|
||||||
import argparse
|
import argparse
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
# create a subclass and override the handler methods
|
# create a subclass and override the handler methods
|
||||||
@ -39,9 +40,14 @@ class MyHTMLParser(HTMLParser):
|
|||||||
def main():
|
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('-d', dest='transmission', help="Should add to transmission", default=False)
|
||||||
|
parser.add_argument('--download',dest='transmission',action='store_true', help="call transmission-remote to start the download", default=True)
|
||||||
|
parser.add_argument('--auto',dest='auto',action='store_true', help="auto select the url to download", default=False)
|
||||||
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)
|
parser.add_argument('-p', dest='pages', help="The number of pages to fetch (doesn't work with --local)", default=1)
|
||||||
|
|
||||||
|
def compare(a,b):
|
||||||
|
return -1 * cmp(a['s'], b['s'])
|
||||||
def local(args):
|
def local(args):
|
||||||
xml_str = ''
|
xml_str = ''
|
||||||
with open(args.database, 'r') as f:
|
with open(args.database, 'r') as f:
|
||||||
@ -86,20 +92,41 @@ def main():
|
|||||||
else:
|
else:
|
||||||
mags = remote(args)
|
mags = remote(args)
|
||||||
|
|
||||||
|
L = []
|
||||||
if mags and len(mags) > 0:
|
if mags and len(mags) > 0:
|
||||||
print "S=seeders"
|
print "S=seeders"
|
||||||
print "L=leechers"
|
print "L=leechers"
|
||||||
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])
|
||||||
|
d = dict()
|
||||||
|
d['i'] = m
|
||||||
|
# d['u'] = magnet[0]
|
||||||
|
d['s'] = (int(magnet[1]) + int(magnet[2]))
|
||||||
|
L.append(d)
|
||||||
print str(m) + '. S:' + str(magnet[1]) + ' L:' + str(magnet[2]) + ' ', urllib.unquote(name.group(1).encode('ascii')).decode('utf-8').replace("+", " ")
|
print str(m) + '. S:' + str(magnet[1]) + ' L:' + str(magnet[2]) + ' ', urllib.unquote(name.group(1).encode('ascii')).decode('utf-8').replace("+", " ")
|
||||||
l = raw_input("Select a link: ")
|
L.sort(compare)
|
||||||
try:
|
if not args.auto:
|
||||||
choice = int(l)
|
l = raw_input("Select a link: ")
|
||||||
except Exception:
|
try:
|
||||||
choice = None
|
choice = int(l)
|
||||||
|
except Exception:
|
||||||
|
choice = None
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
choice = int(L[0]['i'])
|
||||||
|
except Exception:
|
||||||
|
choice = None
|
||||||
|
url = mags[choice][0]
|
||||||
|
|
||||||
if not choice == None:
|
if not choice == None:
|
||||||
webbrowser.open(mags[choice][0])
|
print ""
|
||||||
|
print "url:"
|
||||||
|
print url
|
||||||
|
c = """transmission-remote --add "%s" """ % (url)
|
||||||
|
if args.transmission:
|
||||||
|
os.system(c)
|
||||||
|
os.system("transmission-remote -l")
|
||||||
else:
|
else:
|
||||||
print "Cancelled."
|
print "Cancelled."
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user