qBittorrent
nova3.nova2 Namespace Reference

Functions

def initialize_engines ()
 Every engine should have a "search" method taking a space-free string as parameter (ex. More...
 
def engines_to_xml (supported_engines)
 
def displayCapabilities (supported_engines)
 
def run_search (engine_list)
 
def main (args)
 

Variables

bool THREADED = True
 
 MAX_THREADS = cpu_count()
 
dictionary CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}
 

Function Documentation

◆ displayCapabilities()

def nova3.nova2.displayCapabilities (   supported_engines)
Display capabilities in XML format
<capabilities>
  <engine_short_name>
    <name>long name</name>
    <url>http://example.com</url>
    <categories>movies music games</categories>
  </engine_short_name>
</capabilities>

Definition at line 105 of file nova2.py.

105 def displayCapabilities(supported_engines):
106  """
107  Display capabilities in XML format
108  <capabilities>
109  <engine_short_name>
110  <name>long name</name>
111  <url>http://example.com</url>
112  <categories>movies music games</categories>
113  </engine_short_name>
114  </capabilities>
115  """
116  xml = "".join(("<capabilities>\n",
117  "".join(engines_to_xml(supported_engines)),
118  "</capabilities>"))
119  print(xml)
120 
121 
QString join(const QList< QStringView > &strings, QStringView separator)
Definition: string.cpp:102
def engines_to_xml(supported_engines)
Definition: nova2.py:85
def displayCapabilities(supported_engines)
Definition: nova2.py:105

References nova3.nova2.engines_to_xml(), and Utils::String.join().

Referenced by nova3.nova2.main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ engines_to_xml()

def nova3.nova2.engines_to_xml (   supported_engines)
 Generates xml for supported engines 

Definition at line 85 of file nova2.py.

85 def engines_to_xml(supported_engines):
86  """ Generates xml for supported engines """
87  tab = " " * 4
88 
89  for short_name in supported_engines:
90  search_engine = globals()[short_name]()
91 
92  supported_categories = ""
93  if hasattr(search_engine, "supported_categories"):
94  supported_categories = " ".join((key
95  for key in search_engine.supported_categories.keys()
96  if key != "all"))
97 
98  yield "".join((tab, "<", short_name, ">\n",
99  tab, tab, "<name>", search_engine.name, "</name>\n",
100  tab, tab, "<url>", search_engine.url, "</url>\n",
101  tab, tab, "<categories>", supported_categories, "</categories>\n",
102  tab, "</", short_name, ">\n"))
103 
104 

References Utils::String.join().

Referenced by nova3.nova2.displayCapabilities().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize_engines()

def nova3.nova2.initialize_engines ( )

Every engine should have a "search" method taking a space-free string as parameter (ex.

"family+guy") it should call prettyPrinter() with a dict as parameter. The keys in the dict must be: link,name,size,seeds,leech,engine_url As a convention, try to list results by decreasing number of seeds or similar

 Import available engines

    Return list of available engines

Definition at line 59 of file nova2.py.

59 def initialize_engines():
60  """ Import available engines
61 
62  Return list of available engines
63  """
64  supported_engines = []
65 
66  engines = glob(path.join(path.dirname(__file__), 'engines', '*.py'))
67  for engine in engines:
68  engi = path.basename(engine).split('.')[0].strip()
69  if len(engi) == 0 or engi.startswith('_'):
70  continue
71  try:
72  # import engines.[engine]
73  engine_module = __import__(".".join(("engines", engi)))
74  # get low-level module
75  engine_module = getattr(engine_module, engi)
76  # bind class name
77  globals()[engi] = getattr(engine_module, engi)
78  supported_engines.append(engi)
79  except Exception:
80  pass
81 
82  return supported_engines
83 
84 
def initialize_engines()
Every engine should have a "search" method taking a space-free string as parameter (ex.
Definition: nova2.py:59

References Utils::String.join().

Referenced by nova3.nova2.main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

def nova3.nova2.main (   args)

Definition at line 145 of file nova2.py.

145 def main(args):
146  supported_engines = initialize_engines()
147 
148  if not args:
149  raise SystemExit("./nova2.py [all|engine1[,engine2]*] <category> <keywords>\n"
150  "available engines: %s" % (','.join(supported_engines)))
151 
152  elif args[0] == "--capabilities":
153  displayCapabilities(supported_engines)
154  return
155 
156  elif len(args) < 3:
157  raise SystemExit("./nova2.py [all|engine1[,engine2]*] <category> <keywords>\n"
158  "available engines: %s" % (','.join(supported_engines)))
159 
160  # get only unique engines with set
161  engines_list = set(e.lower() for e in args[0].strip().split(','))
162 
163  if 'all' in engines_list:
164  engines_list = supported_engines
165  else:
166  # discard un-supported engines
167  engines_list = [engine for engine in engines_list
168  if engine in supported_engines]
169 
170  if not engines_list:
171  # engine list is empty. Nothing to do here
172  return
173 
174  cat = args[1].lower()
175 
176  if cat not in CATEGORIES:
177  raise SystemExit(" - ".join(('Invalid category', cat)))
178 
179  what = urllib.parse.quote(' '.join(args[2:]))
180  if THREADED:
181  # child process spawning is controlled min(number of searches, number of cpu)
182  with Pool(min(len(engines_list), MAX_THREADS)) as pool:
183  pool.map(run_search, ([globals()[engine], what, cat] for engine in engines_list))
184  else:
185  # py3 note: map is needed to be evaluated for content to be executed
186  all(map(run_search, ([globals()[engine], what, cat] for engine in engines_list)))
187 
188 
int main(int argc, char *argv[])
Definition: main.cpp:128

References nova3.nova2.displayCapabilities(), nova3.nova2.initialize_engines(), and Utils::String.join().

Here is the call graph for this function:

◆ run_search()

def nova3.nova2.run_search (   engine_list)
 Run search in engine

    @param engine_list List with engine, query and category

    @retval False if any exceptions occurred
    @retval True  otherwise

Definition at line 122 of file nova2.py.

122 def run_search(engine_list):
123  """ Run search in engine
124 
125  @param engine_list List with engine, query and category
126 
127  @retval False if any exceptions occurred
128  @retval True otherwise
129  """
130  engine, what, cat = engine_list
131  try:
132  engine = engine()
133  # avoid exceptions due to invalid category
134  if hasattr(engine, 'supported_categories'):
135  if cat in engine.supported_categories:
136  engine.search(what, cat)
137  else:
138  engine.search(what)
139 
140  return True
141  except Exception:
142  return False
143 
144 
def run_search(engine_list)
Definition: nova2.py:122

Variable Documentation

◆ CATEGORIES

dictionary nova3.nova2.CATEGORIES = {'all', 'movies', 'tv', 'music', 'games', 'anime', 'software', 'pictures', 'books'}

Definition at line 48 of file nova2.py.

◆ MAX_THREADS

int nova3.nova2.MAX_THREADS = cpu_count()

Definition at line 44 of file nova2.py.

◆ THREADED

bool nova3.nova2.THREADED = True

Definition at line 42 of file nova2.py.