Skip to content

Commit

Permalink
Merge pull request #17 from rix1337/dev
Browse files Browse the repository at this point in the history
Use multithreading for searches
  • Loading branch information
rix1337 authored Oct 3, 2024
2 parents 520dc7b + 84e1436 commit 8bce0fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion quasarr/providers/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def get_version():
return "0.1.7"
return "0.1.8"


def create_version_file():
Expand Down
24 changes: 18 additions & 6 deletions quasarr/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Quasarr
# Project by https://github.com/rix1337

from concurrent.futures import ThreadPoolExecutor, as_completed

from quasarr.search.sources.dw import dw_feed, dw_search
from quasarr.search.sources.fx import fx_feed, fx_search
from quasarr.search.sources.nx import nx_feed, nx_search
Expand All @@ -14,20 +16,30 @@ def get_search_results(shared_state, request_from, imdb_id=None):
fx = shared_state.values["config"]("Hostnames").get("fx")
nx = shared_state.values["config"]("Hostnames").get("nx")

functions = []
if imdb_id:
if dw:
results.extend(dw_search(shared_state, request_from, imdb_id))
functions.append(lambda: dw_search(shared_state, request_from, imdb_id))
if fx:
results.extend(fx_search(shared_state, imdb_id))
functions.append(lambda: fx_search(shared_state, imdb_id))
if nx:
results.extend(nx_search(shared_state, request_from, imdb_id))
functions.append(lambda: nx_search(shared_state, request_from, imdb_id))
else:
if dw:
results.extend(dw_feed(shared_state, request_from))
functions.append(lambda: dw_feed(shared_state, request_from))
if fx:
results.extend(fx_feed(shared_state))
functions.append(lambda: fx_feed(shared_state))
if nx:
results.extend(nx_feed(shared_state, request_from))
functions.append(lambda: nx_feed(shared_state, request_from))

with ThreadPoolExecutor() as executor:
futures = [executor.submit(func) for func in functions]
for future in as_completed(futures):
try:
result = future.result()
results.extend(result)
except Exception as e:
print(f"An error occurred: {e}")

print(f"Providing {len(results)} releases to {request_from}")
return results

0 comments on commit 8bce0fe

Please sign in to comment.