|
|
@ -1,4 +1,4 @@ |
|
|
|
#VERSION: 1.41 |
|
|
|
#VERSION: 1.42 |
|
|
|
|
|
|
|
|
|
|
|
# Author: |
|
|
|
# Author: |
|
|
|
# Fabien Devaux <fab AT gnux DOT info> |
|
|
|
# Fabien Devaux <fab AT gnux DOT info> |
|
|
@ -55,6 +55,7 @@ CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pic |
|
|
|
# As a convention, try to list results by decreasing number of seeds or similar |
|
|
|
# As a convention, try to list results by decreasing number of seeds or similar |
|
|
|
################################################################################ |
|
|
|
################################################################################ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initialize_engines(): |
|
|
|
def initialize_engines(): |
|
|
|
""" Import available engines |
|
|
|
""" Import available engines |
|
|
|
|
|
|
|
|
|
|
@ -68,11 +69,11 @@ def initialize_engines(): |
|
|
|
if len(engi) == 0 or engi.startswith('_'): |
|
|
|
if len(engi) == 0 or engi.startswith('_'): |
|
|
|
continue |
|
|
|
continue |
|
|
|
try: |
|
|
|
try: |
|
|
|
#import engines.[engine] |
|
|
|
# import engines.[engine] |
|
|
|
engine_module = __import__(".".join(("engines", engi))) |
|
|
|
engine_module = __import__(".".join(("engines", engi))) |
|
|
|
#get low-level module |
|
|
|
# get low-level module |
|
|
|
engine_module = getattr(engine_module, engi) |
|
|
|
engine_module = getattr(engine_module, engi) |
|
|
|
#bind class name |
|
|
|
# bind class name |
|
|
|
globals()[engi] = getattr(engine_module, engi) |
|
|
|
globals()[engi] = getattr(engine_module, engi) |
|
|
|
supported_engines.append(engi) |
|
|
|
supported_engines.append(engi) |
|
|
|
except: |
|
|
|
except: |
|
|
@ -80,6 +81,7 @@ def initialize_engines(): |
|
|
|
|
|
|
|
|
|
|
|
return supported_engines |
|
|
|
return supported_engines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def engines_to_xml(supported_engines): |
|
|
|
def engines_to_xml(supported_engines): |
|
|
|
""" Generates xml for supported engines """ |
|
|
|
""" Generates xml for supported engines """ |
|
|
|
tab = " " * 4 |
|
|
|
tab = " " * 4 |
|
|
@ -89,7 +91,8 @@ def engines_to_xml(supported_engines): |
|
|
|
|
|
|
|
|
|
|
|
supported_categories = "" |
|
|
|
supported_categories = "" |
|
|
|
if hasattr(search_engine, "supported_categories"): |
|
|
|
if hasattr(search_engine, "supported_categories"): |
|
|
|
supported_categories = " ".join((key for key in search_engine.supported_categories.keys() |
|
|
|
supported_categories = " ".join((key |
|
|
|
|
|
|
|
for key in search_engine.supported_categories.keys() |
|
|
|
if key is not "all")) |
|
|
|
if key is not "all")) |
|
|
|
|
|
|
|
|
|
|
|
yield "".join((tab, "<", short_name, ">\n", |
|
|
|
yield "".join((tab, "<", short_name, ">\n", |
|
|
@ -98,6 +101,7 @@ def engines_to_xml(supported_engines): |
|
|
|
tab, tab, "<categories>", supported_categories, "</categories>\n", |
|
|
|
tab, tab, "<categories>", supported_categories, "</categories>\n", |
|
|
|
tab, "</", short_name, ">\n")) |
|
|
|
tab, "</", short_name, ">\n")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def displayCapabilities(supported_engines): |
|
|
|
def displayCapabilities(supported_engines): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Display capabilities in XML format |
|
|
|
Display capabilities in XML format |
|
|
@ -114,6 +118,7 @@ def displayCapabilities(supported_engines): |
|
|
|
"</capabilities>")) |
|
|
|
"</capabilities>")) |
|
|
|
print(xml) |
|
|
|
print(xml) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_search(engine_list): |
|
|
|
def run_search(engine_list): |
|
|
|
""" Run search in engine |
|
|
|
""" Run search in engine |
|
|
|
|
|
|
|
|
|
|
@ -125,7 +130,7 @@ def run_search(engine_list): |
|
|
|
engine, what, cat = engine_list |
|
|
|
engine, what, cat = engine_list |
|
|
|
try: |
|
|
|
try: |
|
|
|
engine = engine() |
|
|
|
engine = engine() |
|
|
|
#avoid exceptions due to invalid category |
|
|
|
# avoid exceptions due to invalid category |
|
|
|
if hasattr(engine, 'supported_categories'): |
|
|
|
if hasattr(engine, 'supported_categories'): |
|
|
|
if cat in engine.supported_categories: |
|
|
|
if cat in engine.supported_categories: |
|
|
|
engine.search(what, cat) |
|
|
|
engine.search(what, cat) |
|
|
@ -136,6 +141,7 @@ def run_search(engine_list): |
|
|
|
except: |
|
|
|
except: |
|
|
|
return False |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(args): |
|
|
|
def main(args): |
|
|
|
supported_engines = initialize_engines() |
|
|
|
supported_engines = initialize_engines() |
|
|
|
|
|
|
|
|
|
|
@ -151,18 +157,18 @@ def main(args): |
|
|
|
raise SystemExit("./nova2.py [all|engine1[,engine2]*] <category> <keywords>\n" |
|
|
|
raise SystemExit("./nova2.py [all|engine1[,engine2]*] <category> <keywords>\n" |
|
|
|
"available engines: %s" % (','.join(supported_engines))) |
|
|
|
"available engines: %s" % (','.join(supported_engines))) |
|
|
|
|
|
|
|
|
|
|
|
#get only unique engines with set |
|
|
|
# get only unique engines with set |
|
|
|
engines_list = set(e.lower() for e in args[0].strip().split(',')) |
|
|
|
engines_list = set(e.lower() for e in args[0].strip().split(',')) |
|
|
|
|
|
|
|
|
|
|
|
if 'all' in engines_list: |
|
|
|
if 'all' in engines_list: |
|
|
|
engines_list = supported_engines |
|
|
|
engines_list = supported_engines |
|
|
|
else: |
|
|
|
else: |
|
|
|
#discard un-supported engines |
|
|
|
# discard un-supported engines |
|
|
|
engines_list = [engine for engine in engines_list |
|
|
|
engines_list = [engine for engine in engines_list |
|
|
|
if engine in supported_engines] |
|
|
|
if engine in supported_engines] |
|
|
|
|
|
|
|
|
|
|
|
if not engines_list: |
|
|
|
if not engines_list: |
|
|
|
#engine list is empty. Nothing to do here |
|
|
|
# engine list is empty. Nothing to do here |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
cat = args[1].lower() |
|
|
|
cat = args[1].lower() |
|
|
@ -172,12 +178,13 @@ def main(args): |
|
|
|
|
|
|
|
|
|
|
|
what = urllib.parse.quote(' '.join(args[2:])) |
|
|
|
what = urllib.parse.quote(' '.join(args[2:])) |
|
|
|
if THREADED: |
|
|
|
if THREADED: |
|
|
|
#child process spawning is controlled min(number of searches, number of cpu) |
|
|
|
# child process spawning is controlled min(number of searches, number of cpu) |
|
|
|
with Pool(min(len(engines_list), MAX_THREADS)) as pool: |
|
|
|
with Pool(min(len(engines_list), MAX_THREADS)) as pool: |
|
|
|
pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list)) |
|
|
|
pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list)) |
|
|
|
else: |
|
|
|
else: |
|
|
|
#py3 note: map is needed to be evaluated for content to be executed |
|
|
|
# py3 note: map is needed to be evaluated for content to be executed |
|
|
|
all(map(run_search, ([globals()[engine], what, cat] for engine in engines_list))) |
|
|
|
all(map(run_search, ([globals()[engine], what, cat] for engine in engines_list))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
main(argv[1:]) |
|
|
|
main(argv[1:]) |
|
|
|