Skip to content

Commit

Permalink
chore: make the delay parameters for linovelib mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
wdpm committed Nov 17, 2024
1 parent 7d0f055 commit aaf8984
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ if __name__ == '__main__':
linovelib_epub.run()
```

- Tune delay-related parameters[**optional** but **recommend**]
- Set delay-related parameters[**mandatory**]

```python
from linovelib2epub import Linovelib2Epub
Expand All @@ -182,17 +182,16 @@ if __name__ == '__main__':
linovelib_epub.run()
```

The default value of `chapter_crawl_delay` is 3(s) and `page_crawl_delay` is 2(s). You can tune them to other values as
needed.
The default value of `chapter_crawl_delay` and `page_crawl_delay` are None. You MUST set them to reasonable values.

The example code is as follows to increase the value of all delay parameters.
The example code is as follows to set the value of all delay parameters.

```python
from linovelib2epub import Linovelib2Epub, TargetSite

if __name__ == '__main__':
linovelib_epub = Linovelib2Epub(book_id=3721, target_site=TargetSite.LINOVELIB_PC,
chapter_crawl_delay=5, page_crawl_delay=3)
chapter_crawl_delay=5, page_crawl_delay=5)
linovelib_epub.run()
```

Expand Down Expand Up @@ -249,7 +248,7 @@ from linovelib2epub import Linovelib2Epub, TargetSite

if __name__ == "__main__":
linovelib_epub = Linovelib2Epub(book_id=2356, target_site=TargetSite.LINOVELIB_PC,
chapter_crawl_delay=5, page_crawl_delay=3,
chapter_crawl_delay=5, page_crawl_delay=5,
select_volume_mode=True,
# disable_proxy=False,
# log_level="DEBUG",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ dependencies = [
'brotli>=1.1.0',
'lxml>=5.3.0',
'tabulate>=0.9.0',
'DrissionPage>=4.0.4.5',
'DrissionPage>=4.0.4.23',
'selenium>=4.17.2',
'esprima>=4.0.1',
'pytesseract>=0.3.10'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ aiohttp==3.10.2
brotli==1.1.0
bs4==0.0.1
demjson3==3.0.5
DrissionPage==4.0.4.5
DrissionPage==4.0.4.23
dynaconf==3.2.3
EbookLib==0.17.1
esprima==4.0.1
Expand Down
27 changes: 24 additions & 3 deletions src/linovelib2epub/linovel.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ class TargetSite(Enum):
MASIRO = 'masiro'
WENKU8 = 'wenku8'

def is_linovelib(target: TargetSite):
return target in [
TargetSite.LINOVELIB_MOBILE,
TargetSite.LINOVELIB_MOBILE_TRADITIONAL,
TargetSite.LINOVELIB_PC,
TargetSite.LINOVELIB_PC_TRADITIONAL
]

def check_if_non_negative_number(number):
return isinstance(number, (int, float)) and number >= 0

class Linovelib2Epub:

Expand All @@ -343,13 +353,24 @@ def __init__(self,
log_level: str = "INFO",
browser_path: str | None = None,
browser_driver_path: str | None = None,
chapter_crawl_delay: int | None = 3,
page_crawl_delay: int | None = 2,
chapter_crawl_delay: int | None = None,
page_crawl_delay: int | None = None,
headless: bool = False,
image_download_max_epochs: int | None = None
):
# common mandatory parameters check
if book_id is None:
raise LinovelibException('book_id parameter must be set.')
raise ValueError('The book_id parameter must be set.')

# specified parameters check for linovelib target
if is_linovelib(target_site):
if chapter_crawl_delay is None or page_crawl_delay is None:
raise ValueError('The chapter_crawl_delay and page_crawl_delay parameters must be set for any LINOVELIB target.')
if not check_if_non_negative_number(chapter_crawl_delay):
raise ValueError(f'The chapter_crawl_delay should be a non negative number but got {chapter_crawl_delay}.')
if not check_if_non_negative_number(page_crawl_delay):
raise ValueError(f'The page_crawl_delay should be a non negative number but got {page_crawl_delay}.')


self.target_site = target_site

Expand Down

0 comments on commit aaf8984

Please sign in to comment.