1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-25 12:24:20 +01:00

Made imports consistent, made default work

This commit is contained in:
Brad Horrocks 2014-04-16 12:32:43 -06:00
parent 7765830490
commit 64bce14b21

View File

@ -5,14 +5,14 @@ import webbrowser
import urllib import urllib
import urllib2 import urllib2
import re import re
import ConfigParser, os import os
import ConfigParser
import string import string
import random import random
from HTMLParser import HTMLParser from HTMLParser import HTMLParser
import argparse import argparse
from pprint import pprint from pprint import pprint
class NoRedirection(urllib2.HTTPErrorProcessor): class NoRedirection(urllib2.HTTPErrorProcessor):
def http_response(self, request, response): def http_response(self, request, response):
@ -51,15 +51,15 @@ class MyHTMLParser(HTMLParser):
def main(): def main():
# new ConfigParser
config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
# defaults # default options so we dont die later
config.add_section('SaveToFile') config.add_section('SaveToFile')
config.set('SaveToFile', 'enabled', False) config.set('SaveToFile', 'enabled', False)
config.set('SaveToFile', 'directory', '~/Dropbox/pirate-get/') config.set('SaveToFile', 'directory', '~/Dropbox/pirate-get/')
# load user settings # load user options, to override default ones
config.read([os.path.expanduser('~/.config/pirate-get/pirate.cfg')]) config.read([os.path.expanduser('~/.config/pirate-get/pirate.cfg')])
parser = argparse.ArgumentParser(description='Finds and downloads torrents from the Pirate Bay') parser = argparse.ArgumentParser(description='Finds and downloads torrents from the Pirate Bay')
@ -234,7 +234,7 @@ def main():
choices = () choices = ()
if config.get('SaveToFile', 'enabled'): if config.get('SaveToFile', 'enabled'):
# Save to file is enabled
fileName = os.path.expanduser(config.get('SaveToFile', 'directory')) + id_generator() + '.magnet' fileName = os.path.expanduser(config.get('SaveToFile', 'directory')) + id_generator() + '.magnet'
print ("Saving to File: " + fileName) print ("Saving to File: " + fileName)
f = open(fileName, 'w') f = open(fileName, 'w')
@ -246,11 +246,16 @@ def main():
f.close() f.close()
else: else:
if args.transmission: # use transmission as default
os.system("""transmission-remote --add "%s" """ % (url)) for choice in choices:
os.system("transmission-remote -l") choice = int(choice)
else: url = mags[choice][0]
webbrowser.open(url) print(url)
if args.transmission:
os.system("""transmission-remote --add "%s" """ % (url))
os.system("transmission-remote -l")
else:
webbrowser.open(url)