mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +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:
parent
d9cba85384
commit
12d4d58f1a
@ -6,6 +6,9 @@ import urllib
|
|||||||
import urllib2
|
import urllib2
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import ConfigParser
|
||||||
|
import string
|
||||||
|
import random
|
||||||
from HTMLParser import HTMLParser
|
from HTMLParser import HTMLParser
|
||||||
import argparse
|
import argparse
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
@ -47,6 +50,18 @@ class MyHTMLParser(HTMLParser):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
# new ConfigParser
|
||||||
|
config = ConfigParser.ConfigParser()
|
||||||
|
|
||||||
|
# default options so we dont die later
|
||||||
|
config.add_section('SaveToFile')
|
||||||
|
config.set('SaveToFile', 'enabled', False)
|
||||||
|
config.set('SaveToFile', 'directory', '~/Dropbox/pirate-get/')
|
||||||
|
|
||||||
|
# load user options, to override default ones
|
||||||
|
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,34 @@ def main():
|
|||||||
except Exception:
|
except Exception:
|
||||||
choices = ()
|
choices = ()
|
||||||
|
|
||||||
for choice in choices:
|
if config.get('SaveToFile', 'enabled'):
|
||||||
choice = int(choice)
|
# Save to file is enabled
|
||||||
url = mags[choice][0]
|
fileName = os.path.expanduser(config.get('SaveToFile', 'directory')) + id_generator() + '.magnet'
|
||||||
print(url)
|
print ("Saving to File: " + fileName)
|
||||||
if args.transmission:
|
f = open(fileName, 'w')
|
||||||
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)
|
f.write(url + '\n')
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# use transmission as default
|
||||||
|
for choice in choices:
|
||||||
|
choice = int(choice)
|
||||||
|
url = mags[choice][0]
|
||||||
|
print(url)
|
||||||
|
if args.transmission:
|
||||||
|
os.system("""transmission-remote --add "%s" """ % (url))
|
||||||
|
os.system("transmission-remote -l")
|
||||||
|
else:
|
||||||
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user