Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple adjustments #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
52 changes: 38 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,27 @@ 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)
transparent_ads_fix = 5
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