Our main entry where we now handle our args with argparse and can now enter a query and select site to index using our -s option.
This commit is contained in:
@@ -1,14 +1,17 @@
|
|||||||
#!/usr/bin/env python3.6
|
#!/usr/bin/env python3.6
|
||||||
import configparser
|
import configparser
|
||||||
|
import sys, argparse, json
|
||||||
|
|
||||||
def create_jackett_client():
|
from jackett import Jackett
|
||||||
|
from piratebay import Piratebay
|
||||||
|
|
||||||
|
def getConfig():
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('config.example.ini')
|
config.read('config.example.ini')
|
||||||
jackett_host = config['JACKETT']['JACKETT_HOST']
|
jackett_host = config['JACKETT']['HOST']
|
||||||
jackett_port = config['JACKETT']['JACKETT_PORT']
|
jackett_use_ssl = config['JACKETT']['SSL']
|
||||||
jackett_use_ssl = config['JACKETT']['JACKETT_SSL']
|
|
||||||
|
|
||||||
return [jackett_host, jackett_port, jackett_use_ssl]
|
return config
|
||||||
|
|
||||||
def search(term='', user=None, sort='date', order='desc', category='0_0',
|
def search(term='', user=None, sort='date', order='desc', category='0_0',
|
||||||
quality_filter='0', page='1', per_page=75):
|
quality_filter='0', page='1', per_page=75):
|
||||||
@@ -48,18 +51,22 @@ def chooseCandidate(torrent_list):
|
|||||||
return interesting_torrents
|
return interesting_torrents
|
||||||
|
|
||||||
|
|
||||||
def searchTorrentSite(query, site='piratebay'):
|
def searchTorrentSite(config, query, site):
|
||||||
if site is 'piratebay':
|
if site == 'piratebay':
|
||||||
pirate = piratebay()
|
pirate = Piratebay(config['PIRATEBAY']['HOST'], config['PIRATEBAY']['PATH'],
|
||||||
torrents_found = pirate.search(query, page=0, multiple_pages=5, sort='size')
|
config['PIRATEBAY']['LIMIT'], config['PIRATEBAY']['SSL'])
|
||||||
elif site is 'jackett':
|
|
||||||
jackett = jackett()
|
|
||||||
torrents_found = pirate.search(query)
|
torrents_found = pirate.search(query)
|
||||||
|
elif site == 'jackett':
|
||||||
|
jackett = Jackett(config['JACKETT']['apikey'], config['JACKETT']['HOST'],
|
||||||
|
config['JACKETT']['PATH'], config['JACKETT']['LIMIT'], config.getboolean('JACKETT', 'SSL'))
|
||||||
|
torrents_found = jackett.search(query)
|
||||||
|
|
||||||
|
print(json.dumps(torrents_found))
|
||||||
|
exit(0)
|
||||||
|
|
||||||
pprint(torrents_found)
|
pprint(torrents_found)
|
||||||
candidates = chooseCandidate(torrents_found)
|
candidates = chooseCandidate(torrents_found)
|
||||||
pprint(candidates)
|
pprint(candidates)
|
||||||
exit(0)
|
|
||||||
torrents_found = pirate.search(query, page=0, multiple_pages=0, sort='size', category='movies')
|
torrents_found = pirate.search(query, page=0, multiple_pages=0, sort='size', category='movies')
|
||||||
movie_candidates = chooseCandidate(torrents_found)
|
movie_candidates = chooseCandidate(torrents_found)
|
||||||
|
|
||||||
@@ -74,8 +81,26 @@ def searchTorrentSite(query, site='piratebay'):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
query = sys.argv[1]
|
site_options = ['jackett', 'piratebay']
|
||||||
searchTorrentSite(query)
|
parser = argparse.ArgumentParser(prog='Torrent Search', description='Search different torrent sites by query.')
|
||||||
|
parser.add_argument('query',
|
||||||
|
nargs='+',
|
||||||
|
help='query for searching torrents.')
|
||||||
|
parser.add_argument('-s', '--site',
|
||||||
|
nargs='?',
|
||||||
|
default='jackett',
|
||||||
|
const='jackett',
|
||||||
|
type=str,
|
||||||
|
choices=site_options,
|
||||||
|
help='the site to index (default: %(default)s)')
|
||||||
|
parser.add_argument('-v',
|
||||||
|
action='store_true',
|
||||||
|
help='verbose output.')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
config = getConfig()
|
||||||
|
searchTorrentSite(config, args.query, args.site)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user