Skip to content

Commit

Permalink
* Added help messages
Browse files Browse the repository at this point in the history
* Added scrolling functionality that works after couple of failed attempts
* Added scrolling after a 5 consecutive successful matches, to fix
  transparent ads problem
* Fixed error, which prevented showing info about templates folder
  • Loading branch information
Zairtalk committed Aug 18, 2024
1 parent 00c66f3 commit a436df5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 14 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ This spawns a terminal window which you can close when you are done downloading

Users on other platforms can download the source code on GitHub.

## Usage

```text
nexus_autodl.py [OPTIONS]
Options:
--confidence FLOAT Specifies the accuracy with which the script
should find the screenshot button [default:0.7]
--grayscale / --color Try to locate button using only desaturated
images, can speed up the locating action
[default: grayscale]
--min-sleep-interval INTEGER Minumal amount of time to wait between every
click attempt [default: 1]
--max-sleep-interval INTEGER Minumal amount of time to wait between every
click attempt [default: 5]
--retries-before-scroll INTEGER
Amount of failed attemps before trying to
scroll down [default: 3]
--disable-transparent-ads-fix BOOLEAN
Disable the functionality that can
potentially locate transparent ads which
prevent clicking [default: False]
--templates-path TEXT Set a path to the folder with button screenshots
[default: <current dir>\templates]
--help Show this message and exit.
```

## Caution

Using a bot to download from Nexus is in direct violation of their TOS:
Expand Down
51 changes: 37 additions & 14 deletions nexus_autodl.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,35 @@ def key(key: Path) -> tuple[int | str, ...]:


@click.command()
@click.option("--confidence", default=0.7, show_default=True)
@click.option("--grayscale/--color", default=True, show_default=True)
@click.option("--min-sleep-interval", default=1, show_default=True)
@click.option("--max-sleep-interval", default=5, show_default=True)
@click.option("--templates-path", default=Path.cwd() / "templates", show_default=True)
@click.option("--confidence", default=0.7, show_default=True, help="Specifies the accuracy with which the script should find the screenshot button")
@click.option("--grayscale/--color", default=True, show_default=True, help="Try to locate button using only desaturated images, can speed up the locating action")
@click.option("--min-sleep-interval", default=1, show_default=True, help="Minumal amount of time to wait between every click attempt")
@click.option("--max-sleep-interval", default=5, show_default=True, help="Minumal amount of time to wait between every click attempt")
@click.option("--retries-before-scroll", default=3, show_default=True, help="Amount of failed attemps before trying to scroll down")
@click.option("--disable-transparent-ads-fix", default=False, show_default=True, help="Disable the functionality that can potentially locate transparent ads which prevent clicking")
@click.option("--templates-path", default=Path.cwd() / "templates", show_default=True, help="Set a path to the folder with button screenshots")
def main(
confidence: float,
grayscale: bool,
min_sleep_interval: int,
max_sleep_interval: int,
templates_path: str,
) -> None:
retries_before_scroll: int,
disable_transparent_ads_fix: bool,
) -> None:
transparent_ads_fix = 5
matched = False
templates_path_ = Path(templates_path)
retries_before_scroll_ = retries_before_scroll
templates: dict[Path, Image] = {}
for template_path in human_sorted(templates_path_.iterdir()):
try:
templates[template_path] = open_image(template_path)
logging.info(f"Loaded {template_path}")
except UnidentifiedImageError:
logging.info(f"{template_path} is not a valid image; skipping")

if len(templates) == 0:
try:
for template_path in human_sorted(templates_path_.iterdir()):
templates[template_path] = open_image(template_path)
logging.info(f"Loaded {template_path}")
except UnidentifiedImageError:
logging.info(f"{template_path} is not a valid image; skipping")
except FileNotFoundError:
logging.error(
f"No images found in {templates_path_.absolute()}. "
f"If this is your first time running, take a screenshot and crop "
Expand All @@ -75,10 +82,26 @@ def main(
except ImageNotFoundException:
pass
if not isinstance(box, Box):
if not retries_before_scroll_:
logging.info(f"Picture matching failed, attempting to scroll.")
pyautogui.scroll(-40)
else:
retries_before_scroll_ -= 1
matched = False
continue
if matched:
transparent_ads_fix -= 1
else:
transparent_ads_fix = 5
if not transparent_ads_fix and not disable_transparent_ads_fix:
logging.info(f"Potential transparent ad encountered, attempting to scroll.")
pyautogui.scroll(-40)
matched = True
retries_before_scroll_ = retries_before_scroll
match_x, match_y = pyautogui.center(box)
pyautogui.click(match_x, match_y)
logging.info(f"Matched at ({match_x}, {match_y}).")
pyautogui.moveTo(400, 400)
break

sleep_interval = random.uniform(min_sleep_interval, max_sleep_interval)
Expand Down

0 comments on commit a436df5

Please sign in to comment.