Skip to content

Commit

Permalink
feature(spider/nhentai): add favors login nhentai command
Browse files Browse the repository at this point in the history
  • Loading branch information
RyouMon committed Dec 2, 2024
1 parent faba7d5 commit 72174b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ favors login yandere -u {username}
```

## Login NHentai
1. Open nhentai on browser and login.
2. Use "Get cookies.txt" browser extension download cookie file.
3. Copy cookie file to {user_home}/.favorites_crawler.
1. Get User-Agent and Cookie File
1. Open nhentai and login.
2. Open dev console (F12) and switch to network tab.
3. Open any comic.
4. Copy user-agent from any request.
5. Use "Get cookies.txt" browser extension download cookie file.
2. Execute command:
```commandline
favors login nhentai -u "{User-Agent}" -c "{Cookie File}"
```

## Login Twitter

Expand Down
32 changes: 32 additions & 0 deletions src/favorites_crawler/commands/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,35 @@ def login_twitter(
return
dump_config(config)
print("Login successful.")


@app.command("nhentai")
def login_nhentai(
user_agent: str = typer.Option(
..., '-u', '--user-agent',
help='User Agent'
),
cookie_file: str = typer.Option(
..., '-c', '--cookie-file',
help='Netscape HTTP Cookie File, you can download it by "Get cookies.txt" browser extension.'
)
):
"""
Login to nhentai.
1. Open nhentai and login.\n
2. Open dev console (F12) and switch to network tab.\n
3. Open any comic.\n
4. Copy user-agent from any request.\n
5. Use "Get cookies.txt" browser extension download cookie file.
"""
config = load_config()
nhentai_config = config.setdefault('nhentai', {})
try:
nhentai_config['USER_AGENT'] = user_agent
shutil.copy(cookie_file, DEFAULT_FAVORS_HOME)
except Exception as e:
print(f"Failed to login: {e!r}")
return
dump_config(config)
print("Login successful.")

Check warning on line 148 in src/favorites_crawler/commands/login.py

View check run for this annotation

Codecov / codecov/patch

src/favorites_crawler/commands/login.py#L139-L148

Added lines #L139 - L148 were not covered by tests

0 comments on commit 72174b7

Please sign in to comment.