diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba31760 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pirate-get-* diff --git a/install.sh b/install.sh index e8becba..ed31e16 100755 --- a/install.sh +++ b/install.sh @@ -1,22 +1,24 @@ #!/usr/bin/env sh + if [ "$UID" -ne 0 ] then echo "Please run as root" exit fi -TMP=`mktemp pirate-get-XXX` -if [ `which python2.7` ] +TMP=$(mktemp pirate-get-XXX) +if [ $(which python2.7) ] then - echo "#!/usr/bin/env python2.7" > $TMP + echo "#!/usr/bin/env python2.7" > "$TMP" elif [ `which python2` ] then - echo "#!/usr/bin/env python2" > $TMP + echo "#!/usr/bin/env python2" > "$TMP" else - echo "#!/usr/bin/env python" > $TMP + echo "#!/usr/bin/env python" > "$TMP" fi -sed 1d `dirname $0`/pirate-get.py >> $TMP +sed 1d $(dirname $0)/pirate-get.py >> "$TMP" -cp $TMP /usr/bin/pirate-get +cp "$TMP" /usr/bin/pirate-get chmod +x /usr/bin/pirate-get chmod 755 /usr/bin/pirate-get +rm "$TMP" diff --git a/pirate-get.py b/pirate-get.py index bb8c75f..d1d7926 100755 --- a/pirate-get.py +++ b/pirate-get.py @@ -44,6 +44,7 @@ def main(): parser.add_argument('-t',dest='transmission',action='store_true', help="call transmission-remote to start the download", default=False) 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('-0', dest='first', action='store_true', help="choose the top result", default=False) def local(args): xml_str = '' @@ -119,16 +120,21 @@ def main(): # enhanced print output with justified columns print "%-5s %-6s %-6s %5.1f %-11s %-11s %s" % (m, magnet[1], magnet[2], ratio ,sizes[m], uploaded[m],urllib.unquote(name.group(1).encode('ascii')).decode('utf-8').replace("+", " ") ) - try: - l = raw_input("Select a link: ") - except KeyboardInterrupt : - print "\nCancelled." - exit() + if args.first: + print "Choosing first result"; + choice = 0 - try: - choice = int(l) - except Exception: - choice = None + else: + try: + l = raw_input("Select a link: ") + except KeyboardInterrupt : + print "\nCancelled." + exit() + + try: + choice = int(l) + except Exception: + choice = None if not choice == None: url = mags[choice][0]