1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-03-12 18:58:39 +01:00

Added support to save magnet URLs to file

You have to create a config file for this to work.

	$ cat .config/pirate-get/pirate.cfg
	[SaveToFile]
	enabled = true
	directory = ~/Dropbox/pirate-get/
This commit is contained in:
Brad Horrocks 2014-04-16 12:24:11 -06:00
parent d9cba85384
commit 7765830490

View File

@ -5,11 +5,14 @@ import webbrowser
import urllib import urllib
import urllib2 import urllib2
import re import re
import os import ConfigParser, os
import string
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):
@ -47,6 +50,18 @@ class MyHTMLParser(HTMLParser):
def main(): def main():
config = ConfigParser.ConfigParser()
# defaults
config.add_section('SaveToFile')
config.set('SaveToFile', 'enabled', False)
config.set('SaveToFile', 'directory', '~/Dropbox/pirate-get/')
# load user settings
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')
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('-t',dest='transmission',action='store_true', help="call transmission-remote to start the download", default=False) parser.add_argument('-t',dest='transmission',action='store_true', help="call transmission-remote to start the download", default=False)
@ -218,15 +233,29 @@ def main():
except Exception: except Exception:
choices = () choices = ()
if config.get('SaveToFile', 'enabled'):
fileName = os.path.expanduser(config.get('SaveToFile', 'directory')) + id_generator() + '.magnet'
print ("Saving to File: " + fileName)
f = open(fileName, 'w')
for choice in choices: for choice in choices:
choice = int(choice) choice = int(choice)
url = mags[choice][0] url = mags[choice][0]
print(url) f.write(url + '\n')
f.close()
else:
if args.transmission: if args.transmission:
os.system("""transmission-remote --add "%s" """ % (url)) os.system("""transmission-remote --add "%s" """ % (url))
os.system("transmission-remote -l") os.system("transmission-remote -l")
else: else:
webbrowser.open(url) webbrowser.open(url)
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
if __name__ == "__main__": if __name__ == "__main__":
main() main()