Compare commits
378 Commits
Author | SHA1 | Date | |
---|---|---|---|
473f948565 | |||
f701485840 | |||
d8e4f50609 | |||
a893f54da1 | |||
4e307911ce | |||
f9b7f828a5 | |||
092df9e539 | |||
8d74866abf | |||
bc5b7f982d | |||
e54f3cbd06 | |||
a31c615259 | |||
cf0b76204d | |||
17402623c4 | |||
a1a310f06b | |||
57673da762 | |||
dab61291cb | |||
67cb88dbbd | |||
9ed4e04241 | |||
0b0f9bd7e8 | |||
f1cc63a591 | |||
aa77cb1c7c | |||
f9878d080b | |||
f534b0b47f | |||
6b675fd9ba | |||
458c68d5e6 | |||
2eed0a7463 | |||
fc507d246a | |||
3ed84c5a67 | |||
61f4a43081 | |||
4179947f16 | |||
9f55223e28 | |||
b56e5b63a9 | |||
6dc1e0ef5a | |||
fefdd3858a | |||
f66653c55e | |||
179852a343 | |||
8972026456 | |||
cbff6496c3 | |||
5a08981e89 | |||
6c5b83d5be | |||
3de4159a39 | |||
c66fa5f816 | |||
66d0d91eae | |||
0aa8e1d358 | |||
0f54762229 | |||
93c3a77a57 | |||
f411b7cfea | |||
ed1686bb9c | |||
f44b9e9911 | |||
1d20a82e3d | |||
e3a6d67560 | |||
c7c3572811 | |||
421e8bce64 | |||
25e0d80024 | |||
a10510b12d | |||
2c20d19621 | |||
c4313e59f1 | |||
c06f3225a3 | |||
1fac55137a | |||
22412eb904 | |||
8ccfedbfc8 | |||
483bef2207 | |||
730daec1ab | |||
5778d7a6e5 | |||
c48a25bd4e | |||
f5c4bf4dd1 | |||
9f17ee3f6e | |||
290f03d05e | |||
fe443a4229 | |||
2fe5536950 | |||
7a7f2559ff | |||
444efcbee5 | |||
08d812c614 | |||
cb691c782c | |||
927d5b1b39 | |||
a8566482aa | |||
8c900a833d | |||
466fa4c094 | |||
2adf8ccc9d | |||
06fdf0dade | |||
a609243794 | |||
e89c2c0860 | |||
e08b0659e5 | |||
221ff6b32c | |||
bc6ef0cf5d | |||
c8c63cbc11 | |||
a63856d076 | |||
aa4986189f | |||
0fb81599dc | |||
e9f9651d07 | |||
1860b5f0cf | |||
eff4f3bf9b | |||
501840172e | |||
e5ed6d098a | |||
98606202fb | |||
5a3f1009c9 | |||
61945a6e97 | |||
443fcdc7da | |||
31b95fe2dd | |||
be8c97f8d4 | |||
348e51676e | |||
ea356a1ca2 | |||
5a4dfb8a76 | |||
4b15744ceb | |||
b05fa16286 | |||
0879486881 | |||
c66ba730d3 | |||
606c5e0ffd | |||
ba04f81a6f | |||
6519e6f221 | |||
7594625d72 | |||
4948c8f0c5 | |||
e22a99fa8c | |||
19a1d5c404 | |||
ad1e876611 | |||
1de7e1f998 | |||
b97e707817 | |||
6ef2189bfe | |||
24be2d37d4 | |||
d9d2a6fb91 | |||
bd38294bb7 | |||
2cf4e6718e | |||
8cd4b948e7 | |||
f884384eb3 | |||
87afab46c4 | |||
c7b1d7e6a8 | |||
ad02371158 | |||
7c9d55e0ee | |||
00aad774ae | |||
373086b459 | |||
3a83f99771 | |||
00627ab36a | |||
592e163891 | |||
84523475b0 | |||
5f5461c902 | |||
05e6ceb3cd | |||
db59426503 | |||
74197f8f90 | |||
6d91a39533 | |||
e181e0b9dd | |||
6fed1f94cb | |||
9cfb23c8ec | |||
fc347cdadf | |||
1cdebaab61 | |||
9513141ccf | |||
bdc9fa113e | |||
36946111db | |||
ce8ae54536 | |||
7aedb905d6 | |||
8b8b5f193e | |||
fc99d91ac1 | |||
ba141efba7 | |||
f78d8750f3 | |||
08bb8ffda4 | |||
af379c825c | |||
2f9386f22c | |||
3667bc34b7 | |||
84749c56bd | |||
24f79e0945 | |||
edc46a9531 | |||
72035a14e6 | |||
472528e464 | |||
3f5915fd2a | |||
0cd2576dab | |||
445a8c052e | |||
7a75afef0a | |||
a5813e19b1 | |||
8462d2f2aa | |||
51074ee948 | |||
9c7354be32 | |||
7f48b3edd1 | |||
d84b827241 | |||
4ac161a38c | |||
648b6f87bf | |||
2ec1283ba8 | |||
a9bd46b426 | |||
c52bc271fc | |||
f2d22f8e7d | |||
ea6089ff31 | |||
670d14c3f3 | |||
b46106a5bc | |||
f04359e486 | |||
6861cbcbc1 | |||
e0938c5a0e | |||
641f8e4c51 | |||
b2fae226f9 | |||
4aa34c668a | |||
f157ac3246 | |||
139e01d3ca | |||
4d870e36a1 | |||
74b0df26a9 | |||
1746e731ec | |||
8ad60d9838 | |||
be05b9c0eb | |||
9054b98934 | |||
b82201ff27 | |||
532c74e075 | |||
5a50a5b1ba | |||
b5fe48746e | |||
94d8da655a | |||
6ff2816d95 | |||
4d89b80e67 | |||
0a94ef9cf1 | |||
4cc4f35a0d | |||
ad86c49de9 | |||
5a538fe82f | |||
eb35ba9848 | |||
14a53a0953 | |||
c5e4b5ffa8 | |||
b3f25875d0 | |||
91053b98af | |||
7570b6ae7d | |||
d2e68c6c45 | |||
b0902c2d58 | |||
320f36c264 | |||
1dae63be39 | |||
78429423d9 | |||
38ff69d99d | |||
2ce36204fe | |||
8ed1b89277 | |||
e9864d158f | |||
43013badd4 | |||
7508a2010d | |||
946761477d | |||
db80408024 | |||
4c85cebb78 | |||
e982a8170c | |||
0b62f0ebd9 | |||
37b4ee7d00 | |||
84cad0d475 | |||
bf03881ed6 | |||
f97b814b45 | |||
7323eae99b | |||
6e07f0426b | |||
44c424a321 | |||
3db77e0ce3 | |||
22dbb4dd0d | |||
2be4bd71ce | |||
fc39aeb49e | |||
be2ec3f452 | |||
0c23f64356 | |||
7e4dff8fec | |||
e2a1d79b1b | |||
8183f3a7a9 | |||
80713d2e00 | |||
a2cd025027 | |||
2f7bb59e58 | |||
e94685d9c5 | |||
07d804b047 | |||
5552d39337 | |||
d35190f9d0 | |||
c8bca4240a | |||
130386054f | |||
df16109788 | |||
c18cd2aaa5 | |||
197b5e4923 | |||
9f747dad7e | |||
ca713197cc | |||
49f07de95d | |||
5c7bdae0d7 | |||
d5f41bf37c | |||
56153015b1 | |||
140249217a | |||
9e537e60f2 | |||
4df8e1bae0 | |||
c250d9c787 | |||
a5547696eb | |||
49ac1d035d | |||
f234b7234e | |||
43a9b981dd | |||
bc29869a8b | |||
53e1923e67 | |||
ba6d4047e2 | |||
dcf22b30a5 | |||
0208d9b9e6 | |||
0115285e10 | |||
ea8a576f7e | |||
05eaa9eebc | |||
ab2dff4859 | |||
9592870d85 | |||
c1a82635bd | |||
1974644513 | |||
fe4fb46e30 | |||
6156cf5914 | |||
75b00fc523 | |||
ff8af8279f | |||
e1556b09cc | |||
110a2acb7c | |||
c60f1f34d5 | |||
4f2db83a13 | |||
bd8bb42ecd | |||
0abcb048b4 | |||
411d6c2f30 | |||
88c0c1e021 | |||
86c43e5d8c | |||
39f8729d51 | |||
d6461335f8 | |||
c0c7b33909 | |||
893a8c194e | |||
e6d2eb554d | |||
25e5acf671 | |||
4f33228cec | |||
f227c9e897 | |||
9f2f57248b | |||
024f08ca97 | |||
3017fff823 | |||
070e8917f4 | |||
01caa8d4e5 | |||
35e724e206 | |||
d045adfd6a | |||
62e3552c84 | |||
6e2a25cf55 | |||
44178a8cfb | |||
4ca582c104 | |||
97857b8dc6 | |||
23774d9526 | |||
8dc7a1f40b | |||
349e21193b | |||
7e826c5255 | |||
bc70a2071b | |||
1b49911166 | |||
7eeed17ea5 | |||
f4afcd549e | |||
4fc6303db2 | |||
f2aa65b64b | |||
0a343935ab | |||
03f1aeada7 | |||
94395d9165 | |||
bacaa096e0 | |||
3e420f05fa | |||
158b15bda8 | |||
92640d9767 | |||
6b97777b7d | |||
1af195d727 | |||
58b2b644c1 | |||
0cfec34e9e | |||
1172282362 | |||
a909ad6d92 | |||
440bb0dc38 | |||
f5b7d89fb0 | |||
535b804ef6 | |||
9b65544942 | |||
0935d609c3 | |||
f10ae3cf58 | |||
86b3a092c7 | |||
710cc86eaf | |||
2d327359aa | |||
f78b8bc2cd | |||
a95396033b | |||
01c0e73849 | |||
57e9305849 | |||
6bd37f384c | |||
2c61fd3a3f | |||
cf4291d3c2 | |||
450e3689a0 | |||
b5deca2704 | |||
57dc4a58b9 | |||
1e1d03064b | |||
40a98881c6 | |||
a7848c3cd0 | |||
5df58780d9 | |||
56dace81f1 | |||
086e469275 | |||
1f76a8a70e | |||
5d294212e6 | |||
ef274a672b | |||
795f80752f | |||
53c23bb6dc | |||
8d5f12292c | |||
f3141d5726 | |||
475e4db9af | |||
a5eba94064 | |||
6053e302ee | |||
c32b516575 | |||
0150e79c49 | |||
0cda30385b | |||
18bdab1962 | |||
8e8f935a9b |
10
.dockerignore
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
venv
|
||||||
|
*.egg-info
|
||||||
|
build
|
||||||
|
dist
|
||||||
|
images
|
||||||
|
LICENSE
|
||||||
|
.travis.yml
|
||||||
|
.idea
|
27
.github/workflows/docker-image.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
name: Docker Image CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
-
|
||||||
|
name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Build the Docker image
|
||||||
|
uses: docker/build-push-action@v4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ricterz/nhentai:latest
|
2
.gitignore
vendored
@ -6,3 +6,5 @@ dist/
|
|||||||
.python-version
|
.python-version
|
||||||
.DS_Store
|
.DS_Store
|
||||||
output/
|
output/
|
||||||
|
venv/
|
||||||
|
.vscode/
|
||||||
|
21
.travis.yml
@ -1,21 +0,0 @@
|
|||||||
os:
|
|
||||||
- linux
|
|
||||||
|
|
||||||
language: python
|
|
||||||
python:
|
|
||||||
- 2.7
|
|
||||||
- 3.6
|
|
||||||
- 3.5
|
|
||||||
- 3.4
|
|
||||||
|
|
||||||
install:
|
|
||||||
- python setup.py install
|
|
||||||
|
|
||||||
script:
|
|
||||||
- echo 268642 > /tmp/test.txt
|
|
||||||
- NHENTAI=https://nhentai.net nhentai --cookie '__cfduid=da09f237ceb0f51c75980b0b3fda3ce571558179357; _ga=GA1.2.2000087053.1558179358; _gid=GA1.2.717818542.1558179358; csrftoken=iSxrTFOjrujJqauhAqWvTTI9dl3sfWnxdEFoMuqgmlBrbMin5Gj9wJW4r61cmH1X; sessionid=ewuaayfewbzpiukrarx9d52oxwlz2esd'
|
|
||||||
- NHENTAI=https://nhentai.net nhentai --search umaru
|
|
||||||
- NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/ --cbz
|
|
||||||
- NHENTAI=https://nhentai.net nhentai --tag lolicon
|
|
||||||
- NHENTAI=https://nhentai.net nhentai -F
|
|
||||||
- NHENTAI=https://nhentai.net nhentai --file /tmp/test.txt
|
|
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
FROM python:3
|
||||||
|
|
||||||
|
WORKDIR /usr/src/nhentai
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN python setup.py install
|
||||||
|
|
||||||
|
WORKDIR /output
|
||||||
|
ENTRYPOINT ["nhentai"]
|
@ -1,5 +1,5 @@
|
|||||||
include README.md
|
include README.rst
|
||||||
include requirements.txt
|
include requirements.txt
|
||||||
include nhentai/viewer/index.html
|
include nhentai/viewer/*
|
||||||
include nhentai/viewer/styles.css
|
include nhentai/viewer/default/*
|
||||||
include nhentai/viewer/scripts.js
|
include nhentai/viewer/minimal/*
|
||||||
|
84
README.md
@ -1,84 +0,0 @@
|
|||||||
nhentai
|
|
||||||
=======
|
|
||||||
_ _ _ _
|
|
||||||
_ __ | | | | ___ _ __ | |_ __ _(_)
|
|
||||||
| '_ \| |_| |/ _ \ '_ \| __/ _` | |
|
|
||||||
| | | | _ | __/ | | | || (_| | |
|
|
||||||
|_| |_|_| |_|\___|_| |_|\__\__,_|_|
|
|
||||||
|
|
||||||
あなたも変態。 いいね?
|
|
||||||
[](https://travis-ci.org/RicterZ/nhentai)  [](https://github.com/RicterZ/nhentai/blob/master/LICENSE)
|
|
||||||
|
|
||||||
|
|
||||||
nHentai is a CLI tool for downloading doujinshi from [nhentai.net](http://nhentai.net).
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
git clone https://github.com/RicterZ/nhentai
|
|
||||||
cd nhentai
|
|
||||||
python setup.py install
|
|
||||||
|
|
||||||
### Installation (Gentoo)
|
|
||||||
|
|
||||||
layman -fa glicOne
|
|
||||||
sudo emerge net-misc/nhentai
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
**IMPORTANT**: To bypass the nhentai frequency limit, you should use `--login` option to log into nhentai.net.
|
|
||||||
|
|
||||||
*The default download folder will be the path where you run the command (CLI path).*
|
|
||||||
|
|
||||||
Download specified doujinshi:
|
|
||||||
```bash
|
|
||||||
nhentai --id=123855,123866
|
|
||||||
```
|
|
||||||
|
|
||||||
Download doujinshi with ids specified in a file:
|
|
||||||
```bash
|
|
||||||
nhentai --file=doujinshi.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
Search a keyword and download the first page:
|
|
||||||
```bash
|
|
||||||
nhentai --search="tomori" --page=1 --download
|
|
||||||
```
|
|
||||||
|
|
||||||
Download your favourite doujinshi (login required):
|
|
||||||
```bash
|
|
||||||
nhentai --login "username:password" --download
|
|
||||||
```
|
|
||||||
|
|
||||||
Download by tag name:
|
|
||||||
```bash
|
|
||||||
nhentai --tag lolicon --download
|
|
||||||
```
|
|
||||||
|
|
||||||
### Options
|
|
||||||
|
|
||||||
+ `-t, --thread`: Download threads, max: 10
|
|
||||||
+ `--output`:Output dir of saving doujinshi
|
|
||||||
+ `--tag`:Download by tag name
|
|
||||||
+ `--timeout`: Timeout of downloading each image
|
|
||||||
+ `--proxy`: Use proxy, example: http://127.0.0.1:8080/
|
|
||||||
+ `--login`: username:password pair of your nhentai account
|
|
||||||
+ `--nohtml`: Do not generate HTML
|
|
||||||
+ `--cbz`: Generate Comic Book CBZ File
|
|
||||||
|
|
||||||
### nHentai Mirror
|
|
||||||
If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
|
|
||||||
For example:
|
|
||||||
|
|
||||||
i.h.loli.club -> i.nhentai.net
|
|
||||||
h.loli.club -> nhentai.net
|
|
||||||
|
|
||||||
Set `NHENTAI` env var to your nhentai mirror.
|
|
||||||
```bash
|
|
||||||
NHENTAI=http://h.loli.club nhentai --id 123456
|
|
||||||
```
|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
### あなたも変態
|
|
||||||

|
|
264
README.rst
Normal file
@ -0,0 +1,264 @@
|
|||||||
|
nhentai
|
||||||
|
=======
|
||||||
|
|
||||||
|
あなたも変態。 いいね?
|
||||||
|
|
||||||
|
|travis|
|
||||||
|
|pypi|
|
||||||
|
|version|
|
||||||
|
|license|
|
||||||
|
|
||||||
|
|
||||||
|
nhentai is a CLI tool for downloading doujinshi from `nhentai.net <https://nhentai.net>`_
|
||||||
|
|
||||||
|
GUI version: `https://github.com/edgar1016/nhentai-GUI <https://github.com/edgar1016/nhentai-GUI>`_
|
||||||
|
|
||||||
|
===================
|
||||||
|
Manual Installation
|
||||||
|
===================
|
||||||
|
From Github:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
git clone https://github.com/RicterZ/nhentai
|
||||||
|
cd nhentai
|
||||||
|
python setup.py install
|
||||||
|
|
||||||
|
Build Docker container:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
git clone https://github.com/RicterZ/nhentai
|
||||||
|
cd nhentai
|
||||||
|
docker build -t nhentai:latest .
|
||||||
|
docker run --rm -it -v ~/Downloads/doujinshi:/output -v ~/.nhentai/:/root/.nhentai nhentai --id 123855
|
||||||
|
|
||||||
|
==================
|
||||||
|
Installation
|
||||||
|
==================
|
||||||
|
From PyPI with pip:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
pip install nhentai
|
||||||
|
|
||||||
|
For a self-contained installation, use `pipx <https://github.com/pipxproject/pipx/>`_:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
pipx install nhentai
|
||||||
|
|
||||||
|
Pull from Dockerhub:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
docker pull ricterz/nhentai
|
||||||
|
docker run --rm -it -v ~/Downloads/doujinshi:/output -v ~/.nhentai/:/root/.nhentai ricterz/nhentai --id 123855
|
||||||
|
|
||||||
|
On Gentoo Linux:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
layman -fa glicOne
|
||||||
|
sudo emerge net-misc/nhentai
|
||||||
|
|
||||||
|
On NixOS:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
nix-env -iA nixos.nhentai
|
||||||
|
|
||||||
|
=====
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
**⚠️IMPORTANT⚠️**: To bypass the nhentai frequency limit, you should use `--cookie` and `--useragent` options to store your cookie and your user-agent.
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --useragent "USER AGENT of YOUR BROWSER"
|
||||||
|
nhentai --cookie "YOUR COOKIE FROM nhentai.net"
|
||||||
|
|
||||||
|
**NOTE:**
|
||||||
|
|
||||||
|
- The format of the cookie is `"csrftoken=TOKEN; sessionid=ID; cf_clearance=CLOUDFLARE"`
|
||||||
|
- `cf_clearance` cookie and useragent must be set if you encounter "blocked by cloudflare captcha" error. Make sure you use the same IP and useragent as when you got it
|
||||||
|
|
||||||
|
| To get csrftoken and sessionid, first login to your nhentai account in web browser, then:
|
||||||
|
| (Chrome) |ve| |ld| More tools |ld| Developer tools |ld| Application |ld| Storage |ld| Cookies |ld| https://nhentai.net
|
||||||
|
| (Firefox) |hv| |ld| Web Developer |ld| Web Developer Tools |ld| Storage |ld| Cookies |ld| https://nhentai.net
|
||||||
|
|
|
||||||
|
|
||||||
|
.. |hv| unicode:: U+2630 .. https://www.compart.com/en/unicode/U+2630
|
||||||
|
.. |ve| unicode:: U+22EE .. https://www.compart.com/en/unicode/U+22EE
|
||||||
|
.. |ld| unicode:: U+2014 .. https://www.compart.com/en/unicode/U+2014
|
||||||
|
|
||||||
|
.. image:: https://github.com/RicterZ/nhentai/raw/master/images/usage.png
|
||||||
|
:alt: nhentai
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
*The default download folder will be the path where you run the command (%cd% or $PWD).*
|
||||||
|
|
||||||
|
Download specified doujinshi:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --id 123855 123866 123877
|
||||||
|
|
||||||
|
Download doujinshi with ids specified in a file (doujinshi ids split by line):
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --file=doujinshi.txt
|
||||||
|
|
||||||
|
Set search default language
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --language=english
|
||||||
|
|
||||||
|
Search a keyword and download the first page:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --search="tomori" --page=1 --download
|
||||||
|
# you also can download by tags and multiple keywords
|
||||||
|
nhentai --search="tag:lolicon, artist:henreader, tag:full color"
|
||||||
|
nhentai --search="lolicon, henreader, full color"
|
||||||
|
|
||||||
|
Download your favorites with delay:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --favorites --download --delay 1
|
||||||
|
|
||||||
|
Format output doujinshi folder name:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
nhentai --id 261100 --format '[%i]%s'
|
||||||
|
|
||||||
|
Supported doujinshi folder formatter:
|
||||||
|
|
||||||
|
- %i: Doujinshi id
|
||||||
|
- %t: Doujinshi name
|
||||||
|
- %s: Doujinshi subtitle (translated name)
|
||||||
|
- %a: Doujinshi authors' name
|
||||||
|
- %g: Doujinshi groups name
|
||||||
|
- %p: Doujinshi pretty name
|
||||||
|
- %ag: Doujinshi authors name or groups name
|
||||||
|
|
||||||
|
|
||||||
|
Other options:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
nhentai --search [keyword] --download
|
||||||
|
NHENTAI=https://nhentai-mirror-url/ nhentai --id [ID ...]
|
||||||
|
nhentai --file [filename]
|
||||||
|
|
||||||
|
Environment Variable:
|
||||||
|
NHENTAI nhentai mirror url
|
||||||
|
|
||||||
|
Options:
|
||||||
|
# Operation options, control the program behaviors
|
||||||
|
-h, --help show this help message and exit
|
||||||
|
-D, --download download doujinshi (for search results)
|
||||||
|
-S, --show just show the doujinshi information
|
||||||
|
|
||||||
|
# Doujinshi options, specify id, keyword, etc.
|
||||||
|
--id doujinshi ids set, e.g. 167680 167681 167682
|
||||||
|
-s KEYWORD, --search=KEYWORD
|
||||||
|
search doujinshi by keyword
|
||||||
|
-F, --favorites list or download your favorites
|
||||||
|
|
||||||
|
# Page options, control the page to fetch / download
|
||||||
|
--page-all all search results
|
||||||
|
--page=PAGE, --page-range=PAGE
|
||||||
|
page number of search results. e.g. 1,2-5,14
|
||||||
|
--sorting=SORTING sorting of doujinshi (recent / popular /
|
||||||
|
popular-[today|week])
|
||||||
|
|
||||||
|
# Download options, the output directory, threads, timeout, delay, etc.
|
||||||
|
-o OUTPUT_DIR, --output=OUTPUT_DIR
|
||||||
|
output dir
|
||||||
|
-t THREADS, --threads=THREADS
|
||||||
|
thread count for downloading doujinshi
|
||||||
|
-T TIMEOUT, --timeout=TIMEOUT
|
||||||
|
timeout for downloading doujinshi
|
||||||
|
-d DELAY, --delay=DELAY
|
||||||
|
slow down between downloading every doujinshi
|
||||||
|
--proxy=PROXY store a proxy, for example: -p "http://127.0.0.1:1080"
|
||||||
|
-f FILE, --file=FILE read gallery IDs from file.
|
||||||
|
--format=NAME_FORMAT format the saved folder name
|
||||||
|
--dry-run Dry run, skip file download
|
||||||
|
|
||||||
|
# Generate options, for generate html viewer, cbz file, pdf file, etc
|
||||||
|
--html generate a html viewer at current directory
|
||||||
|
--no-html don't generate HTML after downloading
|
||||||
|
--gen-main generate a main viewer contain all the doujin in the
|
||||||
|
folder
|
||||||
|
-C, --cbz generate Comic Book CBZ File
|
||||||
|
-P, --pdf generate PDF file
|
||||||
|
--rm-origin-dir remove downloaded doujinshi dir when generated CBZ or
|
||||||
|
PDF file
|
||||||
|
--move-to-folder remove files in doujinshi dir then move new file to folder
|
||||||
|
when generated CBZ or PDF file
|
||||||
|
--meta generate a metadata file in doujinshi format
|
||||||
|
--regenerate-cbz regenerate the cbz file if exists
|
||||||
|
|
||||||
|
# nhentai options, set cookie, user-agent, language, remove caches, histories, etc
|
||||||
|
--cookie=COOKIE set cookie of nhentai to bypass Cloudflare captcha
|
||||||
|
--useragent=USERAGENT, --user-agent=USERAGENT
|
||||||
|
set useragent to bypass Cloudflare captcha
|
||||||
|
--language=LANGUAGE set default language to parse doujinshis
|
||||||
|
--clean-language set DEFAULT as language to parse doujinshis
|
||||||
|
--save-download-history
|
||||||
|
save downloaded doujinshis, whose will be skipped if
|
||||||
|
you re-download them
|
||||||
|
--clean-download-history
|
||||||
|
clean download history
|
||||||
|
--template=VIEWER_TEMPLATE
|
||||||
|
set viewer template
|
||||||
|
--legacy use legacy searching method
|
||||||
|
|
||||||
|
==============
|
||||||
|
nHentai Mirror
|
||||||
|
==============
|
||||||
|
If you want to use a mirror, you should set up a reverse proxy of `nhentai.net` and `i.nhentai.net`.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
.. code-block::
|
||||||
|
|
||||||
|
i.h.loli.club -> i.nhentai.net
|
||||||
|
h.loli.club -> nhentai.net
|
||||||
|
|
||||||
|
Set `NHENTAI` env var to your nhentai mirror.
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
NHENTAI=https://h.loli.club nhentai --id 123456
|
||||||
|
|
||||||
|
|
||||||
|
.. image:: https://github.com/RicterZ/nhentai/raw/master/images/search.png
|
||||||
|
:alt: nhentai
|
||||||
|
:align: center
|
||||||
|
.. image:: https://github.com/RicterZ/nhentai/raw/master/images/download.png
|
||||||
|
:alt: nhentai
|
||||||
|
:align: center
|
||||||
|
.. image:: https://github.com/RicterZ/nhentai/raw/master/images/viewer.png
|
||||||
|
:alt: nhentai
|
||||||
|
:align: center
|
||||||
|
|
||||||
|
|
||||||
|
.. |travis| image:: https://travis-ci.org/RicterZ/nhentai.svg?branch=master
|
||||||
|
:target: https://travis-ci.org/RicterZ/nhentai
|
||||||
|
|
||||||
|
.. |pypi| image:: https://img.shields.io/pypi/dm/nhentai.svg
|
||||||
|
:target: https://pypi.org/project/nhentai/
|
||||||
|
|
||||||
|
.. |version| image:: https://img.shields.io/pypi/v/nhentai
|
||||||
|
:target: https://pypi.org/project/nhentai/
|
||||||
|
|
||||||
|
.. |license| image:: https://img.shields.io/github/license/ricterz/nhentai.svg
|
||||||
|
:target: https://github.com/RicterZ/nhentai/blob/master/LICENSE
|
@ -1,5 +0,0 @@
|
|||||||
184212
|
|
||||||
204944
|
|
||||||
222460
|
|
||||||
244502
|
|
||||||
261909
|
|
Before Width: | Height: | Size: 189 KiB After Width: | Height: | Size: 1.0 MiB |
BIN
images/image.jpg
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 991 KiB |
BIN
images/usage.png
Normal file
After Width: | Height: | Size: 679 KiB |
Before Width: | Height: | Size: 311 KiB After Width: | Height: | Size: 1.9 MiB |
@ -1,3 +1,3 @@
|
|||||||
__version__ = '0.3.1'
|
__version__ = '0.5.5'
|
||||||
__author__ = 'RicterZ'
|
__author__ = 'RicterZ'
|
||||||
__email__ = 'ricterzheng@gmail.com'
|
__email__ = 'ricterzheng@gmail.com'
|
||||||
|
@ -1,168 +1,236 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import print_function
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
import json
|
||||||
try:
|
|
||||||
from itertools import ifilter as filter
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
import nhentai.constant as constant
|
import nhentai.constant as constant
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
from nhentai import __version__
|
from nhentai import __version__
|
||||||
from nhentai.utils import urlparse, generate_html
|
from nhentai.utils import generate_html, generate_main_html, DB
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
|
|
||||||
try:
|
|
||||||
if sys.version_info < (3, 0, 0):
|
|
||||||
import codecs
|
|
||||||
import locale
|
|
||||||
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
|
|
||||||
sys.stderr = codecs.getwriter(locale.getpreferredencoding())(sys.stderr)
|
|
||||||
|
|
||||||
except NameError:
|
|
||||||
# python3
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def banner():
|
def banner():
|
||||||
logger.info(u'''nHentai ver %s: あなたも変態。 いいね?
|
logger.debug(f'nHentai ver {__version__}: あなたも変態。 いいね?')
|
||||||
_ _ _ _
|
|
||||||
_ __ | | | | ___ _ __ | |_ __ _(_)
|
|
||||||
| '_ \| |_| |/ _ \ '_ \| __/ _` | |
|
def load_config():
|
||||||
| | | | _ | __/ | | | || (_| | |
|
if not os.path.exists(constant.NHENTAI_CONFIG_FILE):
|
||||||
|_| |_|_| |_|\___|_| |_|\__\__,_|_|
|
return
|
||||||
''' % __version__)
|
|
||||||
|
try:
|
||||||
|
with open(constant.NHENTAI_CONFIG_FILE, 'r') as f:
|
||||||
|
constant.CONFIG.update(json.load(f))
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
logger.error('Failed to load config file.')
|
||||||
|
write_config()
|
||||||
|
|
||||||
|
|
||||||
|
def write_config():
|
||||||
|
if not os.path.exists(constant.NHENTAI_HOME):
|
||||||
|
os.mkdir(constant.NHENTAI_HOME)
|
||||||
|
|
||||||
|
with open(constant.NHENTAI_CONFIG_FILE, 'w') as f:
|
||||||
|
f.write(json.dumps(constant.CONFIG))
|
||||||
|
|
||||||
|
|
||||||
|
def callback(option, opt_str, value, parser):
|
||||||
|
if option == '--id':
|
||||||
|
pass
|
||||||
|
value = []
|
||||||
|
|
||||||
|
for arg in parser.rargs:
|
||||||
|
if arg.isdigit():
|
||||||
|
value.append(int(arg))
|
||||||
|
elif arg.startswith('-'):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
logger.warning(f'Ignore invalid id {arg}')
|
||||||
|
|
||||||
|
setattr(parser.values, option.dest, value)
|
||||||
|
|
||||||
|
|
||||||
def cmd_parser():
|
def cmd_parser():
|
||||||
|
load_config()
|
||||||
|
|
||||||
parser = OptionParser('\n nhentai --search [keyword] --download'
|
parser = OptionParser('\n nhentai --search [keyword] --download'
|
||||||
'\n NHENTAI=http://h.loli.club nhentai --id [ID ...]'
|
'\n NHENTAI=https://nhentai-mirror-url/ nhentai --id [ID ...]'
|
||||||
'\n nhentai --file [filename]'
|
'\n nhentai --file [filename]'
|
||||||
'\n\nEnvironment Variable:\n'
|
'\n\nEnvironment Variable:\n'
|
||||||
' NHENTAI nhentai mirror url')
|
' NHENTAI nhentai mirror url')
|
||||||
# operation options
|
# operation options
|
||||||
parser.add_option('--download', dest='is_download', action='store_true',
|
parser.add_option('--download', '-D', dest='is_download', action='store_true',
|
||||||
help='download doujinshi (for search results)')
|
help='download doujinshi (for search results)')
|
||||||
parser.add_option('--show', dest='is_show', action='store_true', help='just show the doujinshi information')
|
parser.add_option('--show', '-S', dest='is_show', action='store_true', help='just show the doujinshi information')
|
||||||
|
|
||||||
# doujinshi options
|
# doujinshi options
|
||||||
parser.add_option('--id', type='string', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3')
|
parser.add_option('--id', dest='id', action='callback', callback=callback,
|
||||||
parser.add_option('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword')
|
help='doujinshi ids set, e.g. 167680 167681 167682')
|
||||||
parser.add_option('--tag', type='string', dest='tag', action='store', help='download doujinshi by tag')
|
parser.add_option('--search', '-s', type='string', dest='keyword', action='store',
|
||||||
|
help='search doujinshi by keyword')
|
||||||
parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
|
parser.add_option('--favorites', '-F', action='store_true', dest='favorites',
|
||||||
help='list or download your favorites.')
|
help='list or download your favorites')
|
||||||
|
parser.add_option('--artist', '-a', action='store', dest='artist',
|
||||||
|
help='list doujinshi by artist name')
|
||||||
|
|
||||||
# page options
|
# page options
|
||||||
parser.add_option('--page', type='int', dest='page', action='store', default=1,
|
parser.add_option('--page-all', dest='page_all', action='store_true', default=False,
|
||||||
help='page number of search results')
|
help='all search results')
|
||||||
parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1,
|
parser.add_option('--page', '--page-range', type='string', dest='page', action='store', default='1',
|
||||||
help='The max page when recursive download tagged doujinshi')
|
help='page number of search results. e.g. 1,2-5,14')
|
||||||
|
parser.add_option('--sorting', '--sort', dest='sorting', action='store', default='popular',
|
||||||
|
help='sorting of doujinshi (recent / popular / popular-[today|week])',
|
||||||
|
choices=['recent', 'popular', 'popular-today', 'popular-week', 'date'])
|
||||||
|
|
||||||
# download options
|
# download options
|
||||||
parser.add_option('--output', type='string', dest='output_dir', action='store', default='',
|
parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='./',
|
||||||
help='output dir')
|
help='output dir')
|
||||||
parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
|
parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
|
||||||
help='thread count for downloading doujinshi')
|
help='thread count for downloading doujinshi')
|
||||||
parser.add_option('--timeout', type='int', dest='timeout', action='store', default=30,
|
parser.add_option('--timeout', '-T', type='int', dest='timeout', action='store', default=30,
|
||||||
help='timeout for downloading doujinshi')
|
help='timeout for downloading doujinshi')
|
||||||
parser.add_option('--proxy', type='string', dest='proxy', action='store', default='',
|
parser.add_option('--delay', '-d', type='int', dest='delay', action='store', default=0,
|
||||||
help='uses a proxy, for example: http://127.0.0.1:1080')
|
help='slow down between downloading every doujinshi')
|
||||||
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
|
parser.add_option('--proxy', type='string', dest='proxy', action='store',
|
||||||
|
help='store a proxy, for example: -p "http://127.0.0.1:1080"')
|
||||||
|
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
|
||||||
|
parser.add_option('--format', type='string', dest='name_format', action='store',
|
||||||
|
help='format the saved folder name', default='[%i][%a][%t]')
|
||||||
|
parser.add_option('--dry-run', action='store_true', dest='dryrun', help='Dry run, skip file download')
|
||||||
|
|
||||||
# generate options
|
# generate options
|
||||||
parser.add_option('--html', dest='html_viewer', action='store_true',
|
parser.add_option('--html', dest='html_viewer', action='store_true',
|
||||||
help='generate a html viewer at current directory')
|
help='generate a html viewer at current directory')
|
||||||
parser.add_option('--nohtml', dest='is_nohtml', action='store_true',
|
parser.add_option('--no-html', dest='is_nohtml', action='store_true',
|
||||||
help='don\'t generate HTML')
|
help='don\'t generate HTML after downloading')
|
||||||
parser.add_option('--cbz', dest='is_cbz', action='store_true',
|
parser.add_option('--gen-main', dest='main_viewer', action='store_true',
|
||||||
|
help='generate a main viewer contain all the doujin in the folder')
|
||||||
|
parser.add_option('--cbz', '-C', dest='is_cbz', action='store_true',
|
||||||
help='generate Comic Book CBZ File')
|
help='generate Comic Book CBZ File')
|
||||||
|
parser.add_option('--pdf', '-P', dest='is_pdf', action='store_true',
|
||||||
|
help='generate PDF file')
|
||||||
parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
|
parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
|
||||||
help='remove downloaded doujinshi dir when generated CBZ file.')
|
help='remove downloaded doujinshi dir when generated CBZ or PDF file')
|
||||||
|
parser.add_option('--move-to-folder', dest='move_to_folder', action='store_true', default=False,
|
||||||
|
help='remove files in doujinshi dir then move new file to folder when generated CBZ or PDF file')
|
||||||
|
parser.add_option('--meta', dest='generate_metadata', action='store_true',
|
||||||
|
help='generate a metadata file in doujinshi format')
|
||||||
|
parser.add_option('--regenerate-cbz', dest='regenerate_cbz', action='store_true', default=False,
|
||||||
|
help='regenerate the cbz file if exists')
|
||||||
|
|
||||||
# nhentai options
|
# nhentai options
|
||||||
parser.add_option('--cookie', type='str', dest='cookie', action='store',
|
parser.add_option('--cookie', type='str', dest='cookie', action='store',
|
||||||
help='set cookie of nhentai to bypass Google recaptcha')
|
help='set cookie of nhentai to bypass Cloudflare captcha')
|
||||||
|
parser.add_option('--useragent', '--user-agent', type='str', dest='useragent', action='store',
|
||||||
try:
|
help='set useragent to bypass Cloudflare captcha')
|
||||||
sys.argv = list(map(lambda x: unicode(x.decode(sys.stdin.encoding)), sys.argv))
|
parser.add_option('--language', type='str', dest='language', action='store',
|
||||||
except (NameError, TypeError):
|
help='set default language to parse doujinshis')
|
||||||
pass
|
parser.add_option('--clean-language', dest='clean_language', action='store_true', default=False,
|
||||||
except UnicodeDecodeError:
|
help='set DEFAULT as language to parse doujinshis')
|
||||||
exit(0)
|
parser.add_option('--save-download-history', dest='is_save_download_history', action='store_true',
|
||||||
|
default=False, help='save downloaded doujinshis, whose will be skipped if you re-download them')
|
||||||
|
parser.add_option('--clean-download-history', action='store_true', default=False, dest='clean_download_history',
|
||||||
|
help='clean download history')
|
||||||
|
parser.add_option('--template', dest='viewer_template', action='store',
|
||||||
|
help='set viewer template', default='')
|
||||||
|
parser.add_option('--legacy', dest='legacy', action='store_true', default=False,
|
||||||
|
help='use legacy searching method')
|
||||||
|
|
||||||
args, _ = parser.parse_args(sys.argv[1:])
|
args, _ = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
if args.html_viewer:
|
if args.html_viewer:
|
||||||
generate_html()
|
generate_html(template=constant.CONFIG['template'])
|
||||||
exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if os.path.exists(os.path.join(constant.NHENTAI_HOME, 'cookie')):
|
if args.main_viewer and not args.id and not args.keyword and not args.favorites:
|
||||||
with open(os.path.join(constant.NHENTAI_HOME, 'cookie'), 'r') as f:
|
generate_main_html()
|
||||||
constant.COOKIE = f.read()
|
sys.exit(0)
|
||||||
|
|
||||||
if args.cookie:
|
if args.clean_download_history:
|
||||||
try:
|
with DB() as db:
|
||||||
if not os.path.exists(constant.NHENTAI_HOME):
|
db.clean_all()
|
||||||
os.mkdir(constant.NHENTAI_HOME)
|
|
||||||
|
|
||||||
with open(os.path.join(constant.NHENTAI_HOME, 'cookie'), 'w') as f:
|
logger.info('Download history cleaned.')
|
||||||
f.write(args.cookie)
|
sys.exit(0)
|
||||||
except Exception as e:
|
|
||||||
logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
# --- set config ---
|
||||||
|
if args.cookie is not None:
|
||||||
|
constant.CONFIG['cookie'] = args.cookie
|
||||||
|
write_config()
|
||||||
logger.info('Cookie saved.')
|
logger.info('Cookie saved.')
|
||||||
exit(0)
|
sys.exit(0)
|
||||||
|
elif args.useragent is not None:
|
||||||
|
constant.CONFIG['useragent'] = args.useragent
|
||||||
|
write_config()
|
||||||
|
logger.info('User-Agent saved.')
|
||||||
|
sys.exit(0)
|
||||||
|
elif args.language is not None:
|
||||||
|
constant.CONFIG['language'] = args.language
|
||||||
|
write_config()
|
||||||
|
logger.info(f'Default language now set to "{args.language}"')
|
||||||
|
sys.exit(0)
|
||||||
|
# TODO: search without language
|
||||||
|
|
||||||
'''
|
if args.proxy is not None:
|
||||||
if args.login:
|
proxy_url = urlparse(args.proxy)
|
||||||
try:
|
if not args.proxy == '' and proxy_url.scheme not in ('http', 'https', 'socks5', 'socks5h',
|
||||||
_, _ = args.login.split(':', 1)
|
'socks4', 'socks4a'):
|
||||||
except ValueError:
|
logger.error(f'Invalid protocol "{proxy_url.scheme}" of proxy, ignored')
|
||||||
logger.error('Invalid `username:password` pair.')
|
sys.exit(0)
|
||||||
exit(1)
|
else:
|
||||||
|
constant.CONFIG['proxy'] = {
|
||||||
|
'http': args.proxy,
|
||||||
|
'https': args.proxy,
|
||||||
|
}
|
||||||
|
logger.info(f'Proxy now set to "{args.proxy}"')
|
||||||
|
write_config()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if not args.is_download:
|
if args.viewer_template is not None:
|
||||||
logger.warning('YOU DO NOT SPECIFY `--download` OPTION !!!')
|
if not args.viewer_template:
|
||||||
'''
|
args.viewer_template = 'default'
|
||||||
|
|
||||||
|
if not os.path.exists(os.path.join(os.path.dirname(__file__),
|
||||||
|
f'viewer/{args.viewer_template}/index.html')):
|
||||||
|
logger.error(f'Template "{args.viewer_template}" does not exists')
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
constant.CONFIG['template'] = args.viewer_template
|
||||||
|
write_config()
|
||||||
|
|
||||||
|
# --- end set config ---
|
||||||
|
|
||||||
if args.favorites:
|
if args.favorites:
|
||||||
if not constant.COOKIE:
|
if not constant.CONFIG['cookie']:
|
||||||
logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
|
logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.id:
|
|
||||||
_ = map(lambda id_: id_.strip(), args.id.split(','))
|
|
||||||
args.id = set(map(int, filter(lambda id_: id_.isdigit(), _)))
|
|
||||||
|
|
||||||
if args.file:
|
if args.file:
|
||||||
with open(args.file, 'r') as f:
|
with open(args.file, 'r') as f:
|
||||||
_ = map(lambda id: id.strip(), f.readlines())
|
_ = [i.strip() for i in f.readlines()]
|
||||||
args.id = set(map(int, filter(lambda id_: id_.isdigit(), _)))
|
args.id = set(int(i) for i in _ if i.isdigit())
|
||||||
|
|
||||||
if (args.is_download or args.is_show) and not args.id and not args.keyword and \
|
if (args.is_download or args.is_show) and not args.id and not args.keyword and not args.favorites:
|
||||||
not args.tag and not args.favorites:
|
|
||||||
logger.critical('Doujinshi id(s) are required for downloading')
|
logger.critical('Doujinshi id(s) are required for downloading')
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not args.keyword and not args.id and not args.tag and not args.favorites:
|
if not args.keyword and not args.id and not args.favorites and not args.artist:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.threads <= 0:
|
if args.threads <= 0:
|
||||||
args.threads = 1
|
args.threads = 1
|
||||||
|
|
||||||
elif args.threads > 15:
|
elif args.threads > 15:
|
||||||
logger.critical('Maximum number of used threads is 15')
|
logger.critical('Maximum number of used threads is 15')
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if args.proxy:
|
if args.dryrun and (args.is_cbz or args.is_pdf):
|
||||||
proxy_url = urlparse(args.proxy)
|
logger.critical('Cannot generate PDF or CBZ during dry-run')
|
||||||
if proxy_url.scheme not in ('http', 'https'):
|
sys.exit(1)
|
||||||
logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
|
|
||||||
else:
|
|
||||||
constant.PROXY = {'http': args.proxy, 'https': args.proxy}
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
@ -1,83 +1,128 @@
|
|||||||
#!/usr/bin/env python2.7
|
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import platform
|
import platform
|
||||||
|
import urllib3.exceptions
|
||||||
|
|
||||||
|
from nhentai import constant
|
||||||
from nhentai.cmdline import cmd_parser, banner
|
from nhentai.cmdline import cmd_parser, banner
|
||||||
from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser, tag_parser, login
|
from nhentai.parser import doujinshi_parser, search_parser, legacy_search_parser, print_doujinshi, favorites_parser
|
||||||
from nhentai.doujinshi import Doujinshi
|
from nhentai.doujinshi import Doujinshi
|
||||||
from nhentai.downloader import Downloader
|
from nhentai.downloader import Downloader
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
from nhentai.constant import BASE_URL
|
from nhentai.constant import BASE_URL
|
||||||
from nhentai.utils import generate_html, generate_cbz
|
from nhentai.utils import generate_html, generate_cbz, generate_main_html, generate_pdf, generate_metadata_file, \
|
||||||
|
paging, check_cookie, signal_handler, DB
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
banner()
|
banner()
|
||||||
logger.info('Using mirror: {0}'.format(BASE_URL))
|
|
||||||
options = cmd_parser()
|
|
||||||
|
|
||||||
|
if sys.version_info < (3, 0, 0):
|
||||||
|
logger.error('nhentai now only support Python 3.x')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
options = cmd_parser()
|
||||||
|
logger.info(f'Using mirror: {BASE_URL}')
|
||||||
|
|
||||||
|
# CONFIG['proxy'] will be changed after cmd_parser()
|
||||||
|
if constant.CONFIG['proxy']['http']:
|
||||||
|
logger.info(f'Using proxy: {constant.CONFIG["proxy"]["http"]}')
|
||||||
|
|
||||||
|
if not constant.CONFIG['template']:
|
||||||
|
constant.CONFIG['template'] = 'default'
|
||||||
|
|
||||||
|
logger.info(f'Using viewer template "{constant.CONFIG["template"]}"')
|
||||||
|
|
||||||
|
# check your cookie
|
||||||
|
check_cookie()
|
||||||
|
|
||||||
|
doujinshis = []
|
||||||
doujinshi_ids = []
|
doujinshi_ids = []
|
||||||
doujinshi_list = []
|
|
||||||
|
page_list = paging(options.page)
|
||||||
|
|
||||||
if options.favorites:
|
if options.favorites:
|
||||||
if not options.is_download:
|
if not options.is_download:
|
||||||
logger.warning('You do not specify --download option')
|
logger.warning('You do not specify --download option')
|
||||||
|
|
||||||
for doujinshi_info in favorites_parser():
|
doujinshis = favorites_parser() if options.page_all else favorites_parser(page=page_list)
|
||||||
doujinshi_list.append(Doujinshi(**doujinshi_info))
|
|
||||||
|
|
||||||
if not options.is_download:
|
elif options.keyword:
|
||||||
print_doujinshi([{'id': i.id, 'title': i.name} for i in doujinshi_list])
|
if constant.CONFIG['language']:
|
||||||
exit(0)
|
logger.info(f'Using default language: {constant.CONFIG["language"]}')
|
||||||
|
options.keyword += f' language:{constant.CONFIG["language"]}'
|
||||||
|
|
||||||
if options.tag:
|
_search_parser = legacy_search_parser if options.legacy else search_parser
|
||||||
doujinshis = tag_parser(options.tag, max_page=options.max_page)
|
doujinshis = _search_parser(options.keyword, sorting=options.sorting, page=page_list,
|
||||||
print_doujinshi(doujinshis)
|
is_page_all=options.page_all)
|
||||||
if options.is_download and doujinshis:
|
|
||||||
doujinshi_ids = map(lambda d: d['id'], doujinshis)
|
|
||||||
|
|
||||||
if options.keyword:
|
elif options.artist:
|
||||||
doujinshis = search_parser(options.keyword, options.page)
|
doujinshis = legacy_search_parser(options.artist, sorting=options.sorting, page=page_list,
|
||||||
print_doujinshi(doujinshis)
|
is_page_all=options.page_all, type_='ARTIST')
|
||||||
if options.is_download:
|
|
||||||
doujinshi_ids = map(lambda d: d['id'], doujinshis)
|
|
||||||
|
|
||||||
if not doujinshi_ids:
|
elif not doujinshi_ids:
|
||||||
doujinshi_ids = options.id
|
doujinshi_ids = options.id
|
||||||
|
|
||||||
if doujinshi_ids:
|
print_doujinshi(doujinshis)
|
||||||
for id_ in doujinshi_ids:
|
if options.is_download and doujinshis:
|
||||||
doujinshi_info = doujinshi_parser(id_)
|
doujinshi_ids = [i['id'] for i in doujinshis]
|
||||||
doujinshi_list.append(Doujinshi(**doujinshi_info))
|
|
||||||
|
if options.is_save_download_history:
|
||||||
|
with DB() as db:
|
||||||
|
data = map(int, db.get_all())
|
||||||
|
|
||||||
|
doujinshi_ids = list(set(map(int, doujinshi_ids)) - set(data))
|
||||||
|
|
||||||
if not options.is_show:
|
if not options.is_show:
|
||||||
downloader = Downloader(path=options.output_dir,
|
downloader = Downloader(path=options.output_dir, size=options.threads,
|
||||||
thread=options.threads, timeout=options.timeout)
|
timeout=options.timeout, delay=options.delay)
|
||||||
|
|
||||||
for doujinshi in doujinshi_list:
|
for doujinshi_id in doujinshi_ids:
|
||||||
doujinshi.downloader = downloader
|
doujinshi_info = doujinshi_parser(doujinshi_id)
|
||||||
doujinshi.download()
|
if doujinshi_info:
|
||||||
if not options.is_nohtml and not options.is_cbz:
|
doujinshi = Doujinshi(name_format=options.name_format, **doujinshi_info)
|
||||||
generate_html(options.output_dir, doujinshi)
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not options.dryrun:
|
||||||
|
doujinshi.downloader = downloader
|
||||||
|
doujinshi.download(regenerate_cbz=options.regenerate_cbz)
|
||||||
|
|
||||||
|
if options.generate_metadata:
|
||||||
|
table = doujinshi.table
|
||||||
|
generate_metadata_file(options.output_dir, table, doujinshi)
|
||||||
|
|
||||||
|
if options.is_save_download_history:
|
||||||
|
with DB() as db:
|
||||||
|
db.add_one(doujinshi.id)
|
||||||
|
|
||||||
|
if not options.is_nohtml and not options.is_cbz and not options.is_pdf:
|
||||||
|
generate_html(options.output_dir, doujinshi, template=constant.CONFIG['template'])
|
||||||
elif options.is_cbz:
|
elif options.is_cbz:
|
||||||
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir, True, options.move_to_folder)
|
||||||
|
elif options.is_pdf:
|
||||||
|
generate_pdf(options.output_dir, doujinshi, options.rm_origin_dir, options.move_to_folder)
|
||||||
|
|
||||||
|
if options.main_viewer:
|
||||||
|
generate_main_html(options.output_dir)
|
||||||
|
|
||||||
if not platform.system() == 'Windows':
|
if not platform.system() == 'Windows':
|
||||||
logger.log(15, '🍻 All done.')
|
logger.log(16, '🍻 All done.')
|
||||||
else:
|
else:
|
||||||
logger.log(15, 'All done.')
|
logger.log(16, 'All done.')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
[doujinshi.show() for doujinshi in doujinshi_list]
|
for doujinshi_id in doujinshi_ids:
|
||||||
|
doujinshi_info = doujinshi_parser(doujinshi_id)
|
||||||
|
if doujinshi_info:
|
||||||
def signal_handler(signal, frame):
|
doujinshi = Doujinshi(name_format=options.name_format, **doujinshi_info)
|
||||||
logger.error('Ctrl-C signal received. Stopping...')
|
else:
|
||||||
exit(1)
|
continue
|
||||||
|
doujinshi.show()
|
||||||
|
|
||||||
|
|
||||||
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,28 +1,43 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from nhentai.utils import urlparse
|
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG = os.getenv('DEBUG', False)
|
||||||
BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
|
BASE_URL = os.getenv('NHENTAI', 'https://nhentai.net')
|
||||||
|
|
||||||
__api_suspended_DETAIL_URL = '%s/api/gallery' % BASE_URL
|
DETAIL_URL = f'{BASE_URL}/g'
|
||||||
__api_suspended_SEARCH_URL = '%s/api/galleries/search' % BASE_URL
|
LEGACY_SEARCH_URL = f'{BASE_URL}/search/'
|
||||||
|
SEARCH_URL = f'{BASE_URL}/api/galleries/search'
|
||||||
|
ARTIST_URL = f'{BASE_URL}/artist/'
|
||||||
|
|
||||||
DETAIL_URL = '%s/g' % BASE_URL
|
TAG_API_URL = f'{BASE_URL}/api/galleries/tagged'
|
||||||
SEARCH_URL = '%s/search/' % BASE_URL
|
LOGIN_URL = f'{BASE_URL}/login/'
|
||||||
|
CHALLENGE_URL = f'{BASE_URL}/challenge'
|
||||||
|
FAV_URL = f'{BASE_URL}/favorites/'
|
||||||
|
|
||||||
TAG_URL = '%s/tag' % BASE_URL
|
|
||||||
TAG_API_URL = '%s/api/galleries/tagged' % BASE_URL
|
|
||||||
LOGIN_URL = '%s/login/' % BASE_URL
|
|
||||||
CHALLENGE_URL = '%s/challenge' % BASE_URL
|
|
||||||
FAV_URL = '%s/favorites/' % BASE_URL
|
|
||||||
|
|
||||||
u = urlparse(BASE_URL)
|
IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
|
||||||
IMAGE_URL = '%s://i.%s/galleries' % (u.scheme, u.hostname)
|
|
||||||
|
|
||||||
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
|
NHENTAI_HOME = os.path.join(os.getenv('HOME', tempfile.gettempdir()), '.nhentai')
|
||||||
|
NHENTAI_HISTORY = os.path.join(NHENTAI_HOME, 'history.sqlite3')
|
||||||
|
NHENTAI_CONFIG_FILE = os.path.join(NHENTAI_HOME, 'config.json')
|
||||||
|
|
||||||
PROXY = {}
|
__api_suspended_DETAIL_URL = f'{BASE_URL}/api/gallery'
|
||||||
|
|
||||||
COOKIE = ''
|
CONFIG = {
|
||||||
|
'proxy': {'http': '', 'https': ''},
|
||||||
|
'cookie': '',
|
||||||
|
'language': '',
|
||||||
|
'template': '',
|
||||||
|
'useragent': 'nhentai command line client (https://github.com/RicterZ/nhentai)'
|
||||||
|
}
|
||||||
|
|
||||||
|
LANGUAGE_ISO = {
|
||||||
|
'english': 'en',
|
||||||
|
'chinese': 'zh',
|
||||||
|
'japanese': 'ja',
|
||||||
|
'translated': 'translated'
|
||||||
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import print_function, unicode_literals
|
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
from future.builtins import range
|
|
||||||
|
|
||||||
from nhentai.constant import DETAIL_URL, IMAGE_URL
|
from nhentai.constant import DETAIL_URL, IMAGE_URL
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
@ -21,57 +20,67 @@ class DoujinshiInfo(dict):
|
|||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
try:
|
try:
|
||||||
return dict.__getitem__(self, item)
|
ret = dict.__getitem__(self, item)
|
||||||
|
return ret if ret else 'Unknown'
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return ''
|
return 'Unknown'
|
||||||
|
|
||||||
|
|
||||||
class Doujinshi(object):
|
class Doujinshi(object):
|
||||||
def __init__(self, name=None, id=None, img_id=None, ext='', pages=0, **kwargs):
|
def __init__(self, name=None, pretty_name=None, id=None, img_id=None,
|
||||||
|
ext='', pages=0, name_format='[%i][%a][%t]', **kwargs):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.pretty_name = pretty_name
|
||||||
self.id = id
|
self.id = id
|
||||||
self.img_id = img_id
|
self.img_id = img_id
|
||||||
self.ext = ext
|
self.ext = ext
|
||||||
self.pages = pages
|
self.pages = pages
|
||||||
self.downloader = None
|
self.downloader = None
|
||||||
self.url = '%s/%d' % (DETAIL_URL, self.id)
|
self.url = f'{DETAIL_URL}/{self.id}'
|
||||||
self.info = DoujinshiInfo(**kwargs)
|
self.info = DoujinshiInfo(**kwargs)
|
||||||
self.filename = format_filename('[%s][%s][%s]' % (self.id, self.info.artist, self.name))
|
|
||||||
|
ag_value = self.info.groups if self.info.artists == 'Unknown' else self.info.artists
|
||||||
|
name_format = name_format.replace('%ag', format_filename(ag_value))
|
||||||
|
|
||||||
|
name_format = name_format.replace('%i', format_filename(str(self.id)))
|
||||||
|
name_format = name_format.replace('%a', format_filename(self.info.artists))
|
||||||
|
name_format = name_format.replace('%g', format_filename(self.info.groups))
|
||||||
|
|
||||||
|
name_format = name_format.replace('%t', format_filename(self.name))
|
||||||
|
name_format = name_format.replace('%p', format_filename(self.pretty_name))
|
||||||
|
name_format = name_format.replace('%s', format_filename(self.info.subtitle))
|
||||||
|
self.filename = format_filename(name_format, 255, True)
|
||||||
|
|
||||||
|
self.table = [
|
||||||
|
['Parodies', self.info.parodies],
|
||||||
|
['Doujinshi', self.name],
|
||||||
|
['Subtitle', self.info.subtitle],
|
||||||
|
['Characters', self.info.characters],
|
||||||
|
['Authors', self.info.artists],
|
||||||
|
['Groups', self.info.groups],
|
||||||
|
['Languages', self.info.languages],
|
||||||
|
['Tags', self.info.tags],
|
||||||
|
['URL', self.url],
|
||||||
|
['Pages', self.pages],
|
||||||
|
]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Doujinshi: {0}>'.format(self.name)
|
return f'<Doujinshi: {self.name}>'
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
table = [
|
logger.info(f'Print doujinshi information of {self.id}\n{tabulate(self.table)}')
|
||||||
["Doujinshi", self.name],
|
|
||||||
["Subtitle", self.info.subtitle],
|
|
||||||
["Characters", self.info.character],
|
|
||||||
["Authors", self.info.artist],
|
|
||||||
["Language", self.info.language],
|
|
||||||
["Tags", self.info.tags],
|
|
||||||
["URL", self.url],
|
|
||||||
["Pages", self.pages],
|
|
||||||
]
|
|
||||||
logger.info(u'Print doujinshi information of {0}\n{1}'.format(self.id, tabulate(table)))
|
|
||||||
|
|
||||||
def download(self):
|
def download(self, regenerate_cbz=False):
|
||||||
logger.info('Starting to download doujinshi: %s' % self.name)
|
logger.info(f'Starting to download doujinshi: {self.name}')
|
||||||
if self.downloader:
|
if self.downloader:
|
||||||
download_queue = []
|
download_queue = []
|
||||||
|
|
||||||
if len(self.ext) != self.pages:
|
if len(self.ext) != self.pages:
|
||||||
logger.warning('Page count and ext count do not equal')
|
logger.warning('Page count and ext count do not equal')
|
||||||
|
|
||||||
for i in range(1, min(self.pages, len(self.ext)) + 1):
|
for i in range(1, min(self.pages, len(self.ext)) + 1):
|
||||||
download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext[i-1]))
|
download_queue.append(f'{IMAGE_URL}/{self.img_id}/{i}.{self.ext[i-1]}')
|
||||||
|
|
||||||
self.downloader.download(download_queue, self.filename)
|
|
||||||
|
|
||||||
'''
|
|
||||||
for i in range(len(self.ext)):
|
|
||||||
download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i+1, EXT_MAP[self.ext[i]]))
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
self.downloader.start_download(download_queue, self.filename, regenerate_cbz=regenerate_cbz)
|
||||||
else:
|
else:
|
||||||
logger.critical('Downloader has not been loaded')
|
logger.critical('Downloader has not been loaded')
|
||||||
|
|
||||||
@ -83,4 +92,4 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
test.download()
|
test.download()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('Exception: %s' % str(e))
|
print(f'Exception: {e}')
|
||||||
|
@ -1,57 +1,75 @@
|
|||||||
# coding: utf-
|
# coding: utf-
|
||||||
from __future__ import unicode_literals, print_function
|
|
||||||
from future.builtins import str as text
|
import multiprocessing
|
||||||
|
import signal
|
||||||
|
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import threadpool
|
import time
|
||||||
try:
|
import urllib3.exceptions
|
||||||
from urllib.parse import urlparse
|
|
||||||
except ImportError:
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
from nhentai import constant
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
from nhentai.parser import request
|
from nhentai.parser import request
|
||||||
from nhentai.utils import Singleton
|
from nhentai.utils import Singleton
|
||||||
|
|
||||||
|
|
||||||
requests.packages.urllib3.disable_warnings()
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
semaphore = multiprocessing.Semaphore(1)
|
||||||
|
|
||||||
|
|
||||||
class NhentaiImageNotExistException(Exception):
|
class NHentaiImageNotExistException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def download_callback(result):
|
||||||
|
result, data = result
|
||||||
|
if result == 0:
|
||||||
|
logger.warning('fatal errors occurred, ignored')
|
||||||
|
elif result == -1:
|
||||||
|
logger.warning(f'url {data} return status code 404')
|
||||||
|
elif result == -2:
|
||||||
|
logger.warning('Ctrl-C pressed, exiting sub processes ...')
|
||||||
|
elif result == -3:
|
||||||
|
# workers won't be run, just pass
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
logger.log(16, f'{data} downloaded successfully')
|
||||||
|
|
||||||
|
|
||||||
class Downloader(Singleton):
|
class Downloader(Singleton):
|
||||||
|
|
||||||
def __init__(self, path='', thread=1, timeout=30):
|
def __init__(self, path='', size=5, timeout=30, delay=0):
|
||||||
if not isinstance(thread, (int, )) or thread < 1 or thread > 15:
|
self.size = size
|
||||||
raise ValueError('Invalid threads count')
|
|
||||||
self.path = str(path)
|
self.path = str(path)
|
||||||
self.thread_count = thread
|
|
||||||
self.threads = []
|
|
||||||
self.thread_pool = None
|
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
self.delay = delay
|
||||||
|
|
||||||
def _download(self, url, folder='', filename='', retried=0):
|
def download(self, url, folder='', filename='', retried=0, proxy=None):
|
||||||
logger.info('Starting to download {0} ...'.format(url))
|
if self.delay:
|
||||||
|
time.sleep(self.delay)
|
||||||
|
logger.info(f'Starting to download {url} ...')
|
||||||
filename = filename if filename else os.path.basename(urlparse(url).path)
|
filename = filename if filename else os.path.basename(urlparse(url).path)
|
||||||
base_filename, extension = os.path.splitext(filename)
|
base_filename, extension = os.path.splitext(filename)
|
||||||
|
|
||||||
|
save_file_path = os.path.join(folder, base_filename.zfill(3) + extension)
|
||||||
try:
|
try:
|
||||||
if os.path.exists(os.path.join(folder, base_filename.zfill(3) + extension)):
|
if os.path.exists(save_file_path):
|
||||||
logger.warning('File: {0} exists, ignoring'.format(os.path.join(folder, base_filename.zfill(3) +
|
logger.warning(f'Ignored exists file: {save_file_path}')
|
||||||
extension)))
|
|
||||||
return 1, url
|
return 1, url
|
||||||
|
|
||||||
response = None
|
response = None
|
||||||
with open(os.path.join(folder, base_filename.zfill(3) + extension), "wb") as f:
|
with open(save_file_path, "wb") as f:
|
||||||
i = 0
|
i = 0
|
||||||
while i < 10:
|
while i < 10:
|
||||||
try:
|
try:
|
||||||
response = request('get', url, stream=True, timeout=self.timeout)
|
response = request('get', url, stream=True, timeout=self.timeout, proxies=proxy)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise NhentaiImageNotExistException
|
raise NHentaiImageNotExistException
|
||||||
|
|
||||||
except NhentaiImageNotExistException as e:
|
except NHentaiImageNotExistException as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -72,52 +90,71 @@ class Downloader(Singleton):
|
|||||||
|
|
||||||
except (requests.HTTPError, requests.Timeout) as e:
|
except (requests.HTTPError, requests.Timeout) as e:
|
||||||
if retried < 3:
|
if retried < 3:
|
||||||
logger.warning('Warning: {0}, retrying({1}) ...'.format(str(e), retried))
|
logger.warning(f'Warning: {e}, retrying({retried}) ...')
|
||||||
return 0, self._download(url=url, folder=folder, filename=filename, retried=retried+1)
|
return 0, self.download(url=url, folder=folder, filename=filename,
|
||||||
|
retried=retried+1, proxy=proxy)
|
||||||
else:
|
else:
|
||||||
return 0, None
|
return 0, None
|
||||||
|
|
||||||
except NhentaiImageNotExistException as e:
|
except NHentaiImageNotExistException as e:
|
||||||
os.remove(os.path.join(folder, base_filename.zfill(3) + extension))
|
os.remove(save_file_path)
|
||||||
return -1, url
|
return -1, url
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
import traceback
|
||||||
|
traceback.print_stack()
|
||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
return 0, None
|
return 0, None
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
return -3, None
|
||||||
|
|
||||||
return 1, url
|
return 1, url
|
||||||
|
|
||||||
def _download_callback(self, request, result):
|
def start_download(self, queue, folder='', regenerate_cbz=False):
|
||||||
result, data = result
|
if not isinstance(folder, (str, )):
|
||||||
if result == 0:
|
|
||||||
logger.warning('fatal errors occurred, ignored')
|
|
||||||
# exit(1)
|
|
||||||
elif result == -1:
|
|
||||||
logger.warning('url {} return status code 404'.format(data))
|
|
||||||
else:
|
|
||||||
logger.log(15, '{0} downloaded successfully'.format(data))
|
|
||||||
|
|
||||||
def download(self, queue, folder=''):
|
|
||||||
if not isinstance(folder, text):
|
|
||||||
folder = str(folder)
|
folder = str(folder)
|
||||||
|
|
||||||
if self.path:
|
if self.path:
|
||||||
folder = os.path.join(self.path, folder)
|
folder = os.path.join(self.path, folder)
|
||||||
|
|
||||||
|
if os.path.exists(folder + '.cbz'):
|
||||||
|
if not regenerate_cbz:
|
||||||
|
logger.warning(f'CBZ file "{folder}.cbz" exists, ignored download request')
|
||||||
|
return
|
||||||
|
|
||||||
|
logger.info(f'Doujinshi will be saved at "{folder}"')
|
||||||
if not os.path.exists(folder):
|
if not os.path.exists(folder):
|
||||||
logger.warn('Path \'{0}\' does not exist, creating.'.format(folder))
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(folder)
|
os.makedirs(folder)
|
||||||
except EnvironmentError as e:
|
except EnvironmentError as e:
|
||||||
logger.critical('{0}'.format(str(e)))
|
logger.critical(str(e))
|
||||||
exit(1)
|
|
||||||
else:
|
else:
|
||||||
logger.warn('Path \'{0}\' already exist.'.format(folder))
|
logger.warning(f'Path "{folder}" already exist.')
|
||||||
|
|
||||||
queue = [([url], {'folder': folder}) for url in queue]
|
queue = [(self, url, folder, constant.CONFIG['proxy']) for url in queue]
|
||||||
|
|
||||||
self.thread_pool = threadpool.ThreadPool(self.thread_count)
|
pool = multiprocessing.Pool(self.size, init_worker)
|
||||||
requests_ = threadpool.makeRequests(self._download, queue, self._download_callback)
|
[pool.apply_async(download_wrapper, args=item) for item in queue]
|
||||||
[self.thread_pool.putRequest(req) for req in requests_]
|
|
||||||
|
|
||||||
self.thread_pool.wait()
|
pool.close()
|
||||||
|
pool.join()
|
||||||
|
|
||||||
|
|
||||||
|
def download_wrapper(obj, url, folder='', proxy=None):
|
||||||
|
if sys.platform == 'darwin' or semaphore.get_value():
|
||||||
|
return Downloader.download(obj, url=url, folder=folder, proxy=proxy)
|
||||||
|
else:
|
||||||
|
return -3, None
|
||||||
|
|
||||||
|
|
||||||
|
def init_worker():
|
||||||
|
signal.signal(signal.SIGINT, subprocess_signal)
|
||||||
|
|
||||||
|
|
||||||
|
def subprocess_signal(sig, frame):
|
||||||
|
if semaphore.acquire(timeout=1):
|
||||||
|
logger.warning('Ctrl-C pressed, exiting sub processes ...')
|
||||||
|
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
|
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
|
||||||
#
|
#
|
||||||
from __future__ import print_function, unicode_literals
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import platform
|
import platform
|
||||||
@ -35,7 +34,7 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
# levels to (background, foreground, bold/intense)
|
# levels to (background, foreground, bold/intense)
|
||||||
level_map = {
|
level_map = {
|
||||||
logging.DEBUG: (None, 'blue', False),
|
logging.DEBUG: (None, 'blue', False),
|
||||||
logging.INFO: (None, 'green', False),
|
logging.INFO: (None, 'white', False),
|
||||||
logging.WARNING: (None, 'yellow', False),
|
logging.WARNING: (None, 'yellow', False),
|
||||||
logging.ERROR: (None, 'red', False),
|
logging.ERROR: (None, 'red', False),
|
||||||
logging.CRITICAL: ('red', 'white', False)
|
logging.CRITICAL: ('red', 'white', False)
|
||||||
@ -161,20 +160,20 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
return self.colorize(message, record)
|
return self.colorize(message, record)
|
||||||
|
|
||||||
|
|
||||||
logging.addLevelName(15, "INFO")
|
logging.addLevelName(16, "SUCCESS")
|
||||||
logger = logging.getLogger('nhentai')
|
logger = logging.getLogger('nhentai')
|
||||||
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
|
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
|
||||||
FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", "%H:%M:%S")
|
FORMATTER = logging.Formatter("\r[%(asctime)s] %(funcName)s: %(message)s", "%H:%M:%S")
|
||||||
LOGGER_HANDLER.setFormatter(FORMATTER)
|
LOGGER_HANDLER.setFormatter(FORMATTER)
|
||||||
LOGGER_HANDLER.level_map[logging.getLevelName("INFO")] = (None, "cyan", False)
|
LOGGER_HANDLER.level_map[logging.getLevelName("SUCCESS")] = (None, "green", False)
|
||||||
logger.addHandler(LOGGER_HANDLER)
|
logger.addHandler(LOGGER_HANDLER)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger.log(15, 'nhentai')
|
logger.log(16, 'nhentai')
|
||||||
logger.info('info')
|
logger.info('info')
|
||||||
logger.warn('warn')
|
logger.warning('warning')
|
||||||
logger.debug('debug')
|
logger.debug('debug')
|
||||||
logger.error('error')
|
logger.error('error')
|
||||||
logger.critical('critical')
|
logger.critical('critical')
|
||||||
|
@ -1,34 +1,16 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
import sys
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import threadpool
|
|
||||||
import requests
|
|
||||||
import time
|
import time
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
import nhentai.constant as constant
|
import nhentai.constant as constant
|
||||||
|
from nhentai.utils import request
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
|
|
||||||
|
|
||||||
session = requests.Session()
|
|
||||||
session.headers.update({
|
|
||||||
'Referer': constant.LOGIN_URL,
|
|
||||||
'User-Agent': 'nhentai command line client (https://github.com/RicterZ/nhentai)',
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def request(method, url, **kwargs):
|
|
||||||
global session
|
|
||||||
if not hasattr(session, method):
|
|
||||||
raise AttributeError('\'requests.Session\' object has no attribute \'{0}\''.format(method))
|
|
||||||
|
|
||||||
session.headers.update({'Cookie': constant.COOKIE})
|
|
||||||
return getattr(session, method)(url, proxies=constant.PROXY, verify=False, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_csrf_token(content):
|
def _get_csrf_token(content):
|
||||||
html = BeautifulSoup(content, 'html.parser')
|
html = BeautifulSoup(content, 'html.parser')
|
||||||
csrf_token_elem = html.find('input', attrs={'name': 'csrfmiddlewaretoken'})
|
csrf_token_elem = html.find('input', attrs={'name': 'csrfmiddlewaretoken'})
|
||||||
@ -44,7 +26,7 @@ def login(username, password):
|
|||||||
logger.info('Getting CSRF token ...')
|
logger.info('Getting CSRF token ...')
|
||||||
|
|
||||||
if os.getenv('DEBUG'):
|
if os.getenv('DEBUG'):
|
||||||
logger.info('CSRF token is {}'.format(csrf_token))
|
logger.info(f'CSRF token is {csrf_token}')
|
||||||
|
|
||||||
login_dict = {
|
login_dict = {
|
||||||
'csrfmiddlewaretoken': csrf_token,
|
'csrfmiddlewaretoken': csrf_token,
|
||||||
@ -59,18 +41,33 @@ def login(username, password):
|
|||||||
|
|
||||||
if 'Invalid username/email or password' in resp.text:
|
if 'Invalid username/email or password' in resp.text:
|
||||||
logger.error('Login failed, please check your username and password')
|
logger.error('Login failed, please check your username and password')
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
|
if 'You\'re loading pages way too quickly.' in resp.text or 'Really, slow down' in resp.text:
|
||||||
logger.error('Using nhentai --cookie \'YOUR_COOKIE_HERE\' to save your Cookie.')
|
logger.error('Using nhentai --cookie \'YOUR_COOKIE_HERE\' to save your Cookie.')
|
||||||
exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
def favorites_parser():
|
def _get_title_and_id(response):
|
||||||
|
result = []
|
||||||
|
html = BeautifulSoup(response, 'html.parser')
|
||||||
|
doujinshi_search_result = html.find_all('div', attrs={'class': 'gallery'})
|
||||||
|
for doujinshi in doujinshi_search_result:
|
||||||
|
doujinshi_container = doujinshi.find('div', attrs={'class': 'caption'})
|
||||||
|
title = doujinshi_container.text.strip()
|
||||||
|
title = title if len(title) < 85 else title[:82] + '...'
|
||||||
|
id_ = re.search('/g/([0-9]+)/', doujinshi.a['href']).group(1)
|
||||||
|
result.append({'id': id_, 'title': title})
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def favorites_parser(page=None):
|
||||||
|
result = []
|
||||||
html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
|
html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
|
||||||
count = html.find('span', attrs={'class': 'count'})
|
count = html.find('span', attrs={'class': 'count'})
|
||||||
if not count:
|
if not count:
|
||||||
logger.error("Can't get your number of favorited doujins. Did the login failed?")
|
logger.error("Can't get your number of favorite doujinshis. Did the login failed?")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
count = int(count.text.strip('(').strip(')').replace(',', ''))
|
count = int(count.text.strip('(').strip(')').replace(',', ''))
|
||||||
@ -79,68 +76,80 @@ def favorites_parser():
|
|||||||
return []
|
return []
|
||||||
pages = int(count / 25)
|
pages = int(count / 25)
|
||||||
|
|
||||||
if pages:
|
if page:
|
||||||
pages += 1 if count % (25 * pages) else 0
|
page_range_list = page
|
||||||
else:
|
else:
|
||||||
pages = 1
|
if pages:
|
||||||
|
pages += 1 if count % (25 * pages) else 0
|
||||||
|
else:
|
||||||
|
pages = 1
|
||||||
|
|
||||||
logger.info('You have %d favorites in %d pages.' % (count, pages))
|
logger.info(f'You have {count} favorites in {pages} pages.')
|
||||||
|
|
||||||
if os.getenv('DEBUG'):
|
if os.getenv('DEBUG'):
|
||||||
pages = 1
|
pages = 1
|
||||||
|
|
||||||
ret = []
|
page_range_list = range(1, pages + 1)
|
||||||
doujinshi_id = re.compile('data-id="([\d]+)"')
|
|
||||||
|
|
||||||
for page in range(1, pages + 1):
|
for page in page_range_list:
|
||||||
try:
|
try:
|
||||||
logger.info('Getting doujinshi ids of page %d' % page)
|
logger.info(f'Getting doujinshi ids of page {page}')
|
||||||
resp = request('get', constant.FAV_URL + '?page=%d' % page).text
|
resp = request('get', f'{constant.FAV_URL}?page={page}').content
|
||||||
ids = doujinshi_id.findall(resp)
|
|
||||||
|
|
||||||
for i in ids:
|
|
||||||
ret.append(doujinshi_parser(i))
|
|
||||||
|
|
||||||
|
result.extend(_get_title_and_id(resp))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Error: %s, continue', str(e))
|
logger.error(f'Error: {e}, continue')
|
||||||
|
|
||||||
return ret
|
return result
|
||||||
|
|
||||||
|
|
||||||
def doujinshi_parser(id_):
|
def doujinshi_parser(id_, counter=0):
|
||||||
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
|
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
|
||||||
raise Exception('Doujinshi id({0}) is not valid'.format(id_))
|
raise Exception(f'Doujinshi id({id_}) is not valid')
|
||||||
|
|
||||||
id_ = int(id_)
|
id_ = int(id_)
|
||||||
logger.log(15, 'Fetching doujinshi information of id {0}'.format(id_))
|
logger.info(f'Fetching doujinshi information of id {id_}')
|
||||||
doujinshi = dict()
|
doujinshi = dict()
|
||||||
doujinshi['id'] = id_
|
doujinshi['id'] = id_
|
||||||
url = '{0}/{1}/'.format(constant.DETAIL_URL, id_)
|
url = f'{constant.DETAIL_URL}/{id_}/'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = request('get', url)
|
response = request('get', url)
|
||||||
if response.status_code in (200, ):
|
if response.status_code in (200, ):
|
||||||
response = response.content
|
response = response.content
|
||||||
|
elif response.status_code in (404,):
|
||||||
|
logger.error(f'Doujinshi with id {id_} cannot be found')
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
logger.debug('Slow down and retry ({}) ...'.format(id_))
|
counter += 1
|
||||||
|
|
||||||
|
if counter == 10:
|
||||||
|
logger.critical(f'Failed to fetch doujinshi information of id {id_}')
|
||||||
|
return None
|
||||||
|
|
||||||
|
logger.debug(f'Slow down and retry ({id_}) ...')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
return doujinshi_parser(str(id_))
|
return doujinshi_parser(str(id_), counter)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(str(e))
|
logger.warning(f'Error: {e}, ignored')
|
||||||
raise SystemExit
|
return None
|
||||||
|
|
||||||
|
print(response)
|
||||||
html = BeautifulSoup(response, 'html.parser')
|
html = BeautifulSoup(response, 'html.parser')
|
||||||
doujinshi_info = html.find('div', attrs={'id': 'info'})
|
doujinshi_info = html.find('div', attrs={'id': 'info'})
|
||||||
|
|
||||||
title = doujinshi_info.find('h1').text
|
title = doujinshi_info.find('h1').text
|
||||||
|
pretty_name = doujinshi_info.find('h1').find('span', attrs={'class': 'pretty'}).text
|
||||||
subtitle = doujinshi_info.find('h2')
|
subtitle = doujinshi_info.find('h2')
|
||||||
|
|
||||||
doujinshi['name'] = title
|
doujinshi['name'] = title
|
||||||
|
doujinshi['pretty_name'] = pretty_name
|
||||||
doujinshi['subtitle'] = subtitle.text if subtitle else ''
|
doujinshi['subtitle'] = subtitle.text if subtitle else ''
|
||||||
|
|
||||||
doujinshi_cover = html.find('div', attrs={'id': 'cover'})
|
doujinshi_cover = html.find('div', attrs={'id': 'cover'})
|
||||||
img_id = re.search('/galleries/([\d]+)/cover\.(jpg|png)$', doujinshi_cover.a.img.attrs['data-src'])
|
img_id = re.search('/galleries/([0-9]+)/cover.(jpg|png|gif)$',
|
||||||
|
doujinshi_cover.a.img.attrs['data-src'])
|
||||||
|
|
||||||
ext = []
|
ext = []
|
||||||
for i in html.find_all('div', attrs={'class': 'thumb-container'}):
|
for i in html.find_all('div', attrs={'class': 'thumb-container'}):
|
||||||
@ -149,65 +158,42 @@ def doujinshi_parser(id_):
|
|||||||
|
|
||||||
if not img_id:
|
if not img_id:
|
||||||
logger.critical('Tried yo get image id failed')
|
logger.critical('Tried yo get image id failed')
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
doujinshi['img_id'] = img_id.group(1)
|
doujinshi['img_id'] = img_id.group(1)
|
||||||
doujinshi['ext'] = ext
|
doujinshi['ext'] = ext
|
||||||
|
|
||||||
pages = 0
|
pages = 0
|
||||||
for _ in doujinshi_info.find_all('div', class_=''):
|
for _ in doujinshi_info.find_all('div', class_='tag-container field-name'):
|
||||||
pages = re.search('([\d]+) pages', _.text)
|
if re.search('Pages:', _.text):
|
||||||
if pages:
|
pages = _.find('span', class_='name').string
|
||||||
pages = pages.group(1)
|
|
||||||
break
|
|
||||||
doujinshi['pages'] = int(pages)
|
doujinshi['pages'] = int(pages)
|
||||||
|
|
||||||
# gain information of the doujinshi
|
# gain information of the doujinshi
|
||||||
information_fields = doujinshi_info.find_all('div', attrs={'class': 'field-name'})
|
information_fields = doujinshi_info.find_all('div', attrs={'class': 'field-name'})
|
||||||
needed_fields = ['Characters', 'Artists', 'Language', 'Tags']
|
needed_fields = ['Characters', 'Artists', 'Languages', 'Tags', 'Parodies', 'Groups', 'Categories']
|
||||||
for field in information_fields:
|
for field in information_fields:
|
||||||
field_name = field.contents[0].strip().strip(':')
|
field_name = field.contents[0].strip().strip(':')
|
||||||
if field_name in needed_fields:
|
if field_name in needed_fields:
|
||||||
data = [sub_field.contents[0].strip() for sub_field in
|
data = [sub_field.find('span', attrs={'class': 'name'}).contents[0].strip() for sub_field in
|
||||||
field.find_all('a', attrs={'class': 'tag'})]
|
field.find_all('a', attrs={'class': 'tag'})]
|
||||||
doujinshi[field_name.lower()] = ', '.join(data)
|
doujinshi[field_name.lower()] = ', '.join(data)
|
||||||
|
|
||||||
|
time_field = doujinshi_info.find('time')
|
||||||
|
if time_field.has_attr('datetime'):
|
||||||
|
doujinshi['date'] = time_field['datetime']
|
||||||
return doujinshi
|
return doujinshi
|
||||||
|
|
||||||
|
|
||||||
def search_parser(keyword, page):
|
def legacy_doujinshi_parser(id_):
|
||||||
logger.debug('Searching doujinshis of keyword {0}'.format(keyword))
|
|
||||||
result = []
|
|
||||||
try:
|
|
||||||
response = request('get', url=constant.SEARCH_URL, params={'q': keyword, 'page': page}).content
|
|
||||||
except requests.ConnectionError as e:
|
|
||||||
logger.critical(e)
|
|
||||||
logger.warn('If you are in China, please configure the proxy to fu*k GFW.')
|
|
||||||
raise SystemExit
|
|
||||||
|
|
||||||
html = BeautifulSoup(response, 'html.parser')
|
|
||||||
doujinshi_search_result = html.find_all('div', attrs={'class': 'gallery'})
|
|
||||||
for doujinshi in doujinshi_search_result:
|
|
||||||
doujinshi_container = doujinshi.find('div', attrs={'class': 'caption'})
|
|
||||||
title = doujinshi_container.text.strip()
|
|
||||||
title = title if len(title) < 85 else title[:82] + '...'
|
|
||||||
id_ = re.search('/g/(\d+)/', doujinshi.a['href']).group(1)
|
|
||||||
result.append({'id': id_, 'title': title})
|
|
||||||
if not result:
|
|
||||||
logger.warn('Not found anything of keyword {}'.format(keyword))
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def __api_suspended_doujinshi_parser(id_):
|
|
||||||
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
|
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):
|
||||||
raise Exception('Doujinshi id({0}) is not valid'.format(id_))
|
raise Exception(f'Doujinshi id({id_}) is not valid')
|
||||||
|
|
||||||
id_ = int(id_)
|
id_ = int(id_)
|
||||||
logger.log(15, 'Fetching information of doujinshi id {0}'.format(id_))
|
logger.info(f'Fetching information of doujinshi id {id_}')
|
||||||
doujinshi = dict()
|
doujinshi = dict()
|
||||||
doujinshi['id'] = id_
|
doujinshi['id'] = id_
|
||||||
url = '{0}/{1}'.format(constant.DETAIL_URL, id_)
|
url = f'{constant.DETAIL_URL}/{id_}'
|
||||||
i = 0
|
i = 0
|
||||||
while 5 > i:
|
while 5 > i:
|
||||||
try:
|
try:
|
||||||
@ -216,18 +202,18 @@ def __api_suspended_doujinshi_parser(id_):
|
|||||||
i += 1
|
i += 1
|
||||||
if not i < 5:
|
if not i < 5:
|
||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
exit(1)
|
sys.exit(1)
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
|
|
||||||
doujinshi['name'] = response['title']['english']
|
doujinshi['name'] = response['title']['english']
|
||||||
doujinshi['subtitle'] = response['title']['japanese']
|
doujinshi['subtitle'] = response['title']['japanese']
|
||||||
doujinshi['img_id'] = response['media_id']
|
doujinshi['img_id'] = response['media_id']
|
||||||
doujinshi['ext'] = ''.join(map(lambda s: s['t'], response['images']['pages']))
|
doujinshi['ext'] = ''.join([i['t'] for i in response['images']['pages']])
|
||||||
doujinshi['pages'] = len(response['images']['pages'])
|
doujinshi['pages'] = len(response['images']['pages'])
|
||||||
|
|
||||||
# gain information of the doujinshi
|
# gain information of the doujinshi
|
||||||
needed_fields = ['character', 'artist', 'language', 'tag']
|
needed_fields = ['character', 'artist', 'language', 'tag', 'parody', 'group', 'category']
|
||||||
for tag in response['tags']:
|
for tag in response['tags']:
|
||||||
tag_type = tag['type']
|
tag_type = tag['type']
|
||||||
if tag_type in needed_fields:
|
if tag_type in needed_fields:
|
||||||
@ -246,91 +232,107 @@ def __api_suspended_doujinshi_parser(id_):
|
|||||||
return doujinshi
|
return doujinshi
|
||||||
|
|
||||||
|
|
||||||
def __api_suspended_search_parser(keyword, page):
|
|
||||||
logger.debug('Searching doujinshis using keywords {0}'.format(keyword))
|
|
||||||
result = []
|
|
||||||
i = 0
|
|
||||||
while i < 5:
|
|
||||||
try:
|
|
||||||
response = request('get', url=constant.SEARCH_URL, params={'query': keyword, 'page': page}).json()
|
|
||||||
except Exception as e:
|
|
||||||
i += 1
|
|
||||||
if not i < 5:
|
|
||||||
logger.critical(str(e))
|
|
||||||
logger.warn('If you are in China, please configure the proxy to fu*k GFW.')
|
|
||||||
exit(1)
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
|
|
||||||
if 'result' not in response:
|
|
||||||
raise Exception('No result in response')
|
|
||||||
|
|
||||||
for row in response['result']:
|
|
||||||
title = row['title']['english']
|
|
||||||
title = title[:85] + '..' if len(title) > 85 else title
|
|
||||||
result.append({'id': row['id'], 'title': title})
|
|
||||||
|
|
||||||
if not result:
|
|
||||||
logger.warn('No results for keywords {}'.format(keyword))
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def print_doujinshi(doujinshi_list):
|
def print_doujinshi(doujinshi_list):
|
||||||
if not doujinshi_list:
|
if not doujinshi_list:
|
||||||
return
|
return
|
||||||
doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list]
|
doujinshi_list = [(i['id'], i['title']) for i in doujinshi_list]
|
||||||
headers = ['id', 'doujinshi']
|
headers = ['id', 'doujinshi']
|
||||||
logger.info('Search Result\n' +
|
logger.info(f'Search Result || Found {doujinshi_list.__len__()} doujinshis')
|
||||||
tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
print(tabulate(tabular_data=doujinshi_list, headers=headers, tablefmt='rst'))
|
||||||
|
|
||||||
|
|
||||||
def __api_suspended_tag_parser(tag_id, max_page=1):
|
def legacy_search_parser(keyword, sorting, page, is_page_all=False, type_='SEARCH'):
|
||||||
logger.info('Searching for doujinshi with tag id {0}'.format(tag_id))
|
logger.info(f'Searching doujinshis of keyword {keyword}')
|
||||||
result = []
|
result = []
|
||||||
response = request('get', url=constant.TAG_API_URL, params={'sort': 'popular', 'tag_id': tag_id}).json()
|
|
||||||
page = max_page if max_page <= response['num_pages'] else int(response['num_pages'])
|
|
||||||
|
|
||||||
for i in range(1, page + 1):
|
if type_ not in ('SEARCH', 'ARTIST', ):
|
||||||
logger.info('Getting page {} ...'.format(i))
|
raise ValueError('Invalid type')
|
||||||
|
|
||||||
if page != 1:
|
if is_page_all:
|
||||||
response = request('get', url=constant.TAG_API_URL,
|
if type_ == 'SEARCH':
|
||||||
params={'sort': 'popular', 'tag_id': tag_id}).json()
|
response = request('get', url=constant.LEGACY_SEARCH_URL,
|
||||||
for row in response['result']:
|
params={'q': keyword, 'page': 1, 'sort': sorting}).content
|
||||||
title = row['title']['english']
|
else:
|
||||||
title = title[:85] + '..' if len(title) > 85 else title
|
url = constant.ARTIST_URL + keyword + '/' + ('' if sorting == 'recent' else sorting)
|
||||||
result.append({'id': row['id'], 'title': title})
|
response = request('get', url=url, params={'page': 1}).content
|
||||||
|
|
||||||
|
html = BeautifulSoup(response, 'lxml')
|
||||||
|
pagination = html.find(attrs={'class': 'pagination'})
|
||||||
|
last_page = pagination.find(attrs={'class': 'last'})
|
||||||
|
last_page = re.findall('page=([0-9]+)', last_page.attrs['href'])[0]
|
||||||
|
logger.info(f'Getting doujinshi ids of {last_page} pages')
|
||||||
|
pages = range(1, int(last_page))
|
||||||
|
else:
|
||||||
|
pages = page
|
||||||
|
|
||||||
|
for p in pages:
|
||||||
|
logger.info(f'Fetching page {p} ...')
|
||||||
|
if type_ == 'SEARCH':
|
||||||
|
response = request('get', url=constant.LEGACY_SEARCH_URL,
|
||||||
|
params={'q': keyword, 'page': p, 'sort': sorting}).content
|
||||||
|
else:
|
||||||
|
url = constant.ARTIST_URL + keyword + '/' + ('' if sorting == 'recent' else sorting)
|
||||||
|
response = request('get', url=url, params={'page': p}).content
|
||||||
|
|
||||||
|
if response is None:
|
||||||
|
logger.warning(f'No result in response in page {p}')
|
||||||
|
continue
|
||||||
|
result.extend(_get_title_and_id(response))
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
logger.warn('No results for tag id {}'.format(tag_id))
|
logger.warning(f'No results for keywords {keyword}')
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def tag_parser(tag_name, max_page=1):
|
def search_parser(keyword, sorting, page, is_page_all=False):
|
||||||
result = []
|
result = []
|
||||||
tag_name = tag_name.lower()
|
response = None
|
||||||
tag_name = tag_name.replace(' ', '-')
|
if not page:
|
||||||
|
page = [1]
|
||||||
|
|
||||||
for p in range(1, max_page + 1):
|
if is_page_all:
|
||||||
logger.debug('Fetching page {0} for doujinshi with tag \'{1}\''.format(p, tag_name))
|
url = request('get', url=constant.SEARCH_URL, params={'query': keyword}).url
|
||||||
response = request('get', url='%s/%s?page=%d' % (constant.TAG_URL, tag_name, p)).content
|
init_response = request('get', url.replace('%2B', '+')).json()
|
||||||
|
page = range(1, init_response['num_pages']+1)
|
||||||
|
|
||||||
html = BeautifulSoup(response, 'html.parser')
|
total = f'/{page[-1]}' if is_page_all else ''
|
||||||
doujinshi_items = html.find_all('div', attrs={'class': 'gallery'})
|
not_exists_persist = False
|
||||||
if not doujinshi_items:
|
for p in page:
|
||||||
logger.error('Cannot find doujinshi id of tag \'{0}\''.format(tag_name))
|
i = 0
|
||||||
return
|
|
||||||
|
|
||||||
for i in doujinshi_items:
|
logger.info(f'Searching doujinshis using keywords "{keyword}" on page {p}{total}')
|
||||||
doujinshi_id = i.a.attrs['href'].strip('/g')
|
while i < 3:
|
||||||
doujinshi_title = i.a.text.strip()
|
try:
|
||||||
doujinshi_title = doujinshi_title if len(doujinshi_title) < 85 else doujinshi_title[:82] + '...'
|
url = request('get', url=constant.SEARCH_URL, params={'query': keyword,
|
||||||
result.append({'title': doujinshi_title, 'id': doujinshi_id})
|
'page': p, 'sort': sorting}).url
|
||||||
|
|
||||||
if not result:
|
if constant.DEBUG:
|
||||||
logger.warn('No results for tag \'{}\''.format(tag_name))
|
logger.debug(f'Request URL: {url}')
|
||||||
|
|
||||||
|
response = request('get', url.replace('%2B', '+')).json()
|
||||||
|
except Exception as e:
|
||||||
|
logger.critical(str(e))
|
||||||
|
response = None
|
||||||
|
break
|
||||||
|
|
||||||
|
if constant.DEBUG:
|
||||||
|
logger.debug(f'Response: {response}')
|
||||||
|
|
||||||
|
if response is None or 'result' not in response:
|
||||||
|
logger.warning(f'No result in response in page {p}')
|
||||||
|
if not_exists_persist is True:
|
||||||
|
break
|
||||||
|
continue
|
||||||
|
|
||||||
|
for row in response['result']:
|
||||||
|
title = row['title']['english']
|
||||||
|
title = title[:85] + '..' if len(title) > 85 else title
|
||||||
|
result.append({'id': row['id'], 'title': title})
|
||||||
|
|
||||||
|
not_exists_persist = False
|
||||||
|
if not result:
|
||||||
|
logger.warning(f'No results for keywords {keyword}')
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
129
nhentai/serializer.py
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from xml.sax.saxutils import escape
|
||||||
|
from nhentai.constant import LANGUAGE_ISO
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_json(doujinshi, output_dir):
|
||||||
|
metadata = {'title': doujinshi.name,
|
||||||
|
'subtitle': doujinshi.info.subtitle}
|
||||||
|
if doujinshi.info.date:
|
||||||
|
metadata['upload_date'] = doujinshi.info.date
|
||||||
|
if doujinshi.info.parodies:
|
||||||
|
metadata['parody'] = [i.strip() for i in doujinshi.info.parodies.split(',')]
|
||||||
|
if doujinshi.info.characters:
|
||||||
|
metadata['character'] = [i.strip() for i in doujinshi.info.characters.split(',')]
|
||||||
|
if doujinshi.info.tags:
|
||||||
|
metadata['tag'] = [i.strip() for i in doujinshi.info.tags.split(',')]
|
||||||
|
if doujinshi.info.artists:
|
||||||
|
metadata['artist'] = [i.strip() for i in doujinshi.info.artists.split(',')]
|
||||||
|
if doujinshi.info.groups:
|
||||||
|
metadata['group'] = [i.strip() for i in doujinshi.info.groups.split(',')]
|
||||||
|
if doujinshi.info.languages:
|
||||||
|
metadata['language'] = [i.strip() for i in doujinshi.info.languages.split(',')]
|
||||||
|
metadata['category'] = doujinshi.info.categories
|
||||||
|
metadata['URL'] = doujinshi.url
|
||||||
|
metadata['Pages'] = doujinshi.pages
|
||||||
|
|
||||||
|
with open(os.path.join(output_dir, 'metadata.json'), 'w') as f:
|
||||||
|
json.dump(metadata, f, separators=(',', ':'))
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_comic_xml(doujinshi, output_dir):
|
||||||
|
from iso8601 import parse_date
|
||||||
|
with open(os.path.join(output_dir, 'ComicInfo.xml'), 'w', encoding="utf-8") as f:
|
||||||
|
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||||
|
f.write('<ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
|
||||||
|
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\n')
|
||||||
|
|
||||||
|
xml_write_simple_tag(f, 'Manga', 'Yes')
|
||||||
|
|
||||||
|
xml_write_simple_tag(f, 'Title', doujinshi.name)
|
||||||
|
xml_write_simple_tag(f, 'Summary', doujinshi.info.subtitle)
|
||||||
|
xml_write_simple_tag(f, 'PageCount', doujinshi.pages)
|
||||||
|
xml_write_simple_tag(f, 'URL', doujinshi.url)
|
||||||
|
xml_write_simple_tag(f, 'NhentaiId', doujinshi.id)
|
||||||
|
xml_write_simple_tag(f, 'Genre', doujinshi.info.categories)
|
||||||
|
|
||||||
|
xml_write_simple_tag(f, 'BlackAndWhite', 'No' if doujinshi.info.tags and
|
||||||
|
'full color' in doujinshi.info.tags else 'Yes')
|
||||||
|
|
||||||
|
if doujinshi.info.date:
|
||||||
|
dt = parse_date(doujinshi.info.date)
|
||||||
|
xml_write_simple_tag(f, 'Year', dt.year)
|
||||||
|
xml_write_simple_tag(f, 'Month', dt.month)
|
||||||
|
xml_write_simple_tag(f, 'Day', dt.day)
|
||||||
|
if doujinshi.info.parodies:
|
||||||
|
xml_write_simple_tag(f, 'Series', doujinshi.info.parodies)
|
||||||
|
if doujinshi.info.characters:
|
||||||
|
xml_write_simple_tag(f, 'Characters', doujinshi.info.characters)
|
||||||
|
if doujinshi.info.tags:
|
||||||
|
xml_write_simple_tag(f, 'Tags', doujinshi.info.tags)
|
||||||
|
if doujinshi.info.artists:
|
||||||
|
xml_write_simple_tag(f, 'Writer', ' & '.join([i.strip() for i in
|
||||||
|
doujinshi.info.artists.split(',')]))
|
||||||
|
|
||||||
|
if doujinshi.info.languages:
|
||||||
|
languages = [i.strip() for i in doujinshi.info.languages.split(',')]
|
||||||
|
xml_write_simple_tag(f, 'Translated', 'Yes' if 'translated' in languages else 'No')
|
||||||
|
[xml_write_simple_tag(f, 'LanguageISO', LANGUAGE_ISO[i]) for i in languages
|
||||||
|
if (i != 'translated' and i in LANGUAGE_ISO)]
|
||||||
|
|
||||||
|
f.write('</ComicInfo>')
|
||||||
|
|
||||||
|
|
||||||
|
def xml_write_simple_tag(f, name, val, indent=1):
|
||||||
|
f.write(f'{" "*indent}<{name}>{escape(str(val))}</{name}>\n')
|
||||||
|
|
||||||
|
|
||||||
|
def merge_json():
|
||||||
|
lst = []
|
||||||
|
output_dir = "./"
|
||||||
|
os.chdir(output_dir)
|
||||||
|
doujinshi_dirs = next(os.walk('.'))[1]
|
||||||
|
for folder in doujinshi_dirs:
|
||||||
|
files = os.listdir(folder)
|
||||||
|
if 'metadata.json' not in files:
|
||||||
|
continue
|
||||||
|
data_folder = output_dir + folder + '/' + 'metadata.json'
|
||||||
|
json_file = open(data_folder, 'r')
|
||||||
|
json_dict = json.load(json_file)
|
||||||
|
json_dict['Folder'] = folder
|
||||||
|
lst.append(json_dict)
|
||||||
|
return lst
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_unique(lst):
|
||||||
|
dictionary = {}
|
||||||
|
parody = []
|
||||||
|
character = []
|
||||||
|
tag = []
|
||||||
|
artist = []
|
||||||
|
group = []
|
||||||
|
for dic in lst:
|
||||||
|
if 'parody' in dic:
|
||||||
|
parody.extend([i for i in dic['parody']])
|
||||||
|
if 'character' in dic:
|
||||||
|
character.extend([i for i in dic['character']])
|
||||||
|
if 'tag' in dic:
|
||||||
|
tag.extend([i for i in dic['tag']])
|
||||||
|
if 'artist' in dic:
|
||||||
|
artist.extend([i for i in dic['artist']])
|
||||||
|
if 'group' in dic:
|
||||||
|
group.extend([i for i in dic['group']])
|
||||||
|
dictionary['parody'] = list(set(parody))
|
||||||
|
dictionary['character'] = list(set(character))
|
||||||
|
dictionary['tag'] = list(set(tag))
|
||||||
|
dictionary['artist'] = list(set(artist))
|
||||||
|
dictionary['group'] = list(set(group))
|
||||||
|
return dictionary
|
||||||
|
|
||||||
|
|
||||||
|
def set_js_database():
|
||||||
|
with open('data.js', 'w') as f:
|
||||||
|
indexed_json = merge_json()
|
||||||
|
unique_json = json.dumps(serialize_unique(indexed_json), separators=(',', ':'))
|
||||||
|
indexed_json = json.dumps(indexed_json, separators=(',', ':'))
|
||||||
|
f.write('var data = ' + indexed_json)
|
||||||
|
f.write(';\nvar tags = ' + unique_json)
|
325
nhentai/utils.py
@ -1,12 +1,46 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals, print_function
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
import os
|
import os
|
||||||
import string
|
|
||||||
import zipfile
|
import zipfile
|
||||||
import shutil
|
import shutil
|
||||||
|
import requests
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
from nhentai import constant
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
|
from nhentai.serializer import serialize_json, serialize_comic_xml, set_js_database
|
||||||
|
|
||||||
|
|
||||||
|
MAX_FIELD_LENGTH = 100
|
||||||
|
|
||||||
|
|
||||||
|
def request(method, url, **kwargs):
|
||||||
|
session = requests.Session()
|
||||||
|
session.headers.update({
|
||||||
|
'Referer': constant.LOGIN_URL,
|
||||||
|
'User-Agent': constant.CONFIG['useragent'],
|
||||||
|
'Cookie': constant.CONFIG['cookie']
|
||||||
|
})
|
||||||
|
|
||||||
|
if not kwargs.get('proxies', None):
|
||||||
|
kwargs['proxies'] = constant.CONFIG['proxy']
|
||||||
|
|
||||||
|
return getattr(session, method)(url, verify=False, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def check_cookie():
|
||||||
|
response = request('get', constant.BASE_URL)
|
||||||
|
if response.status_code == 403 and 'Just a moment...' in response.text:
|
||||||
|
logger.error('Blocked by Cloudflare captcha, please set your cookie and useragent')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
username = re.findall('"/users/[0-9]+/(.*?)"', response.text)
|
||||||
|
if not username:
|
||||||
|
logger.warning('Cannot get your username, please check your cookie or use `nhentai --cookie` to set your cookie')
|
||||||
|
else:
|
||||||
|
logger.log(16, f'Login successfully! Your username: {username[0]}')
|
||||||
|
|
||||||
|
|
||||||
class _Singleton(type):
|
class _Singleton(type):
|
||||||
@ -23,15 +57,6 @@ class Singleton(_Singleton(str('SingletonMeta'), (object,), {})):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def urlparse(url):
|
|
||||||
try:
|
|
||||||
from urlparse import urlparse
|
|
||||||
except ImportError:
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
return urlparse(url)
|
|
||||||
|
|
||||||
|
|
||||||
def readfile(path):
|
def readfile(path):
|
||||||
loc = os.path.dirname(__file__)
|
loc = os.path.dirname(__file__)
|
||||||
|
|
||||||
@ -39,7 +64,7 @@ def readfile(path):
|
|||||||
return file.read()
|
return file.read()
|
||||||
|
|
||||||
|
|
||||||
def generate_html(output_dir='.', doujinshi_obj=None):
|
def generate_html(output_dir='.', doujinshi_obj=None, template='default'):
|
||||||
image_html = ''
|
image_html = ''
|
||||||
|
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
@ -47,45 +72,103 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
|||||||
else:
|
else:
|
||||||
doujinshi_dir = '.'
|
doujinshi_dir = '.'
|
||||||
|
|
||||||
|
if not os.path.exists(doujinshi_dir):
|
||||||
|
logger.warning(f'Path "{doujinshi_dir}" does not exist, creating.')
|
||||||
|
try:
|
||||||
|
os.makedirs(doujinshi_dir)
|
||||||
|
except EnvironmentError as e:
|
||||||
|
logger.critical(e)
|
||||||
|
|
||||||
file_list = os.listdir(doujinshi_dir)
|
file_list = os.listdir(doujinshi_dir)
|
||||||
file_list.sort()
|
file_list.sort()
|
||||||
|
|
||||||
for image in file_list:
|
for image in file_list:
|
||||||
if not os.path.splitext(image)[1] in ('.jpg', '.png'):
|
if not os.path.splitext(image)[1] in ('.jpg', '.png'):
|
||||||
continue
|
continue
|
||||||
|
image_html += f'<img src="{image}" class="image-item"/>\n'
|
||||||
|
|
||||||
image_html += '<img src="{0}" class="image-item"/>\n'\
|
html = readfile(f'viewer/{template}/index.html')
|
||||||
.format(image)
|
css = readfile(f'viewer/{template}/styles.css')
|
||||||
|
js = readfile(f'viewer/{template}/scripts.js')
|
||||||
html = readfile('viewer/index.html')
|
|
||||||
css = readfile('viewer/styles.css')
|
|
||||||
js = readfile('viewer/scripts.js')
|
|
||||||
|
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
title = doujinshi_obj.name
|
serialize_json(doujinshi_obj, doujinshi_dir)
|
||||||
if sys.version_info < (3, 0):
|
name = doujinshi_obj.name
|
||||||
title = title.encode('utf-8')
|
|
||||||
else:
|
else:
|
||||||
title = 'nHentai HTML Viewer'
|
name = {'title': 'nHentai HTML Viewer'}
|
||||||
|
|
||||||
data = html.format(TITLE=title, IMAGES=image_html, SCRIPTS=js, STYLES=css)
|
data = html.format(TITLE=name, IMAGES=image_html, SCRIPTS=js, STYLES=css)
|
||||||
try:
|
try:
|
||||||
if sys.version_info < (3, 0):
|
with open(os.path.join(doujinshi_dir, 'index.html'), 'wb') as f:
|
||||||
with open(os.path.join(doujinshi_dir, 'index.html'), 'w') as f:
|
f.write(data.encode('utf-8'))
|
||||||
f.write(data)
|
|
||||||
else:
|
|
||||||
with open(os.path.join(doujinshi_dir, 'index.html'), 'wb') as f:
|
|
||||||
f.write(data.encode('utf-8'))
|
|
||||||
|
|
||||||
logger.log(15, 'HTML Viewer has been write to \'{0}\''.format(os.path.join(doujinshi_dir, 'index.html')))
|
logger.log(16, f'HTML Viewer has been written to "{os.path.join(doujinshi_dir, "index.html")}"')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning('Writen HTML Viewer failed ({})'.format(str(e)))
|
logger.warning(f'Writing HTML Viewer failed ({e})')
|
||||||
|
|
||||||
|
|
||||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
def generate_main_html(output_dir='./'):
|
||||||
|
"""
|
||||||
|
Generate a main html to show all the contains doujinshi.
|
||||||
|
With a link to their `index.html`.
|
||||||
|
Default output folder will be the CLI path.
|
||||||
|
"""
|
||||||
|
|
||||||
|
image_html = ''
|
||||||
|
|
||||||
|
main = readfile('viewer/main.html')
|
||||||
|
css = readfile('viewer/main.css')
|
||||||
|
js = readfile('viewer/main.js')
|
||||||
|
|
||||||
|
element = '\n\
|
||||||
|
<div class="gallery-favorite">\n\
|
||||||
|
<div class="gallery">\n\
|
||||||
|
<a href="./{FOLDER}/index.html" class="cover" style="padding:0 0 141.6% 0"><img\n\
|
||||||
|
src="./{FOLDER}/{IMAGE}" />\n\
|
||||||
|
<div class="caption">{TITLE}</div>\n\
|
||||||
|
</a>\n\
|
||||||
|
</div>\n\
|
||||||
|
</div>\n'
|
||||||
|
|
||||||
|
os.chdir(output_dir)
|
||||||
|
doujinshi_dirs = next(os.walk('.'))[1]
|
||||||
|
|
||||||
|
for folder in doujinshi_dirs:
|
||||||
|
files = os.listdir(folder)
|
||||||
|
files.sort()
|
||||||
|
|
||||||
|
if 'index.html' in files:
|
||||||
|
logger.info(f'Add doujinshi "{folder}"')
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
image = files[0] # 001.jpg or 001.png
|
||||||
|
if folder is not None:
|
||||||
|
title = folder.replace('_', ' ')
|
||||||
|
else:
|
||||||
|
title = 'nHentai HTML Viewer'
|
||||||
|
|
||||||
|
image_html += element.format(FOLDER=folder, IMAGE=image, TITLE=title)
|
||||||
|
if image_html == '':
|
||||||
|
logger.warning('No index.html found, --gen-main paused.')
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
data = main.format(STYLES=css, SCRIPTS=js, PICTURE=image_html)
|
||||||
|
with open('./main.html', 'wb') as f:
|
||||||
|
f.write(data.encode('utf-8'))
|
||||||
|
shutil.copy(os.path.dirname(__file__) + '/viewer/logo.png', './')
|
||||||
|
set_js_database()
|
||||||
|
logger.log(16, f'Main Viewer has been written to "{output_dir}main.html"')
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f'Writing Main Viewer failed ({e})')
|
||||||
|
|
||||||
|
|
||||||
|
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=True, move_to_folder=False):
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id)
|
if write_comic_info:
|
||||||
|
serialize_comic_xml(doujinshi_obj, doujinshi_dir)
|
||||||
|
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), f'{doujinshi_obj.filename}.cbz')
|
||||||
else:
|
else:
|
||||||
cbz_filename = './doujinshi.cbz'
|
cbz_filename = './doujinshi.cbz'
|
||||||
doujinshi_dir = '.'
|
doujinshi_dir = '.'
|
||||||
@ -93,7 +176,7 @@ def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
|||||||
file_list = os.listdir(doujinshi_dir)
|
file_list = os.listdir(doujinshi_dir)
|
||||||
file_list.sort()
|
file_list.sort()
|
||||||
|
|
||||||
logger.info('Writing CBZ file to path: {}'.format(cbz_filename))
|
logger.info(f'Writing CBZ file to path: {cbz_filename}')
|
||||||
with zipfile.ZipFile(cbz_filename, 'w') as cbz_pf:
|
with zipfile.ZipFile(cbz_filename, 'w') as cbz_pf:
|
||||||
for image in file_list:
|
for image in file_list:
|
||||||
image_path = os.path.join(doujinshi_dir, image)
|
image_path = os.path.join(doujinshi_dir, image)
|
||||||
@ -102,26 +185,168 @@ def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
|||||||
if rm_origin_dir:
|
if rm_origin_dir:
|
||||||
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
||||||
|
|
||||||
logger.log(15, 'Comic Book CBZ file has been write to \'{0}\''.format(doujinshi_dir))
|
if move_to_folder:
|
||||||
|
for filename in os.listdir(doujinshi_dir):
|
||||||
|
file_path = os.path.join(doujinshi_dir, filename)
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
try:
|
||||||
|
os.remove(file_path)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error deleting file: {e}")
|
||||||
|
|
||||||
|
shutil.move(cbz_filename, doujinshi_dir)
|
||||||
|
|
||||||
|
logger.log(16, f'Comic Book CBZ file has been written to "{doujinshi_dir}"')
|
||||||
|
|
||||||
|
|
||||||
def format_filename(s):
|
def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, move_to_folder=False):
|
||||||
"""Take a string and return a valid filename constructed from the string.
|
try:
|
||||||
Uses a whitelist approach: any characters not present in valid_chars are
|
import img2pdf
|
||||||
removed. Also spaces are replaced with underscores.
|
|
||||||
|
|
||||||
Note: this method may produce invalid filenames such as ``, `.` or `..`
|
"""Write images to a PDF file using img2pdf."""
|
||||||
When I use this method I prepend a date string like '2009_01_15_19_46_32_'
|
if doujinshi_obj is not None:
|
||||||
and append a file extension like '.txt', so I avoid the potential of using
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
an invalid filename.
|
pdf_filename = os.path.join(
|
||||||
|
os.path.join(doujinshi_dir, '..'),
|
||||||
|
f'{doujinshi_obj.filename}.pdf'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
pdf_filename = './doujinshi.pdf'
|
||||||
|
doujinshi_dir = '.'
|
||||||
|
|
||||||
"""
|
file_list = os.listdir(doujinshi_dir)
|
||||||
valid_chars = "-_.()[] %s%s" % (string.ascii_letters, string.digits)
|
file_list.sort()
|
||||||
filename = ''.join(c for c in s if c in valid_chars)
|
|
||||||
filename = filename.replace(' ', '_') # I don't like spaces in filenames.
|
logger.info(f'Writing PDF file to path: {pdf_filename}')
|
||||||
if len(filename) > 100:
|
with open(pdf_filename, 'wb') as pdf_f:
|
||||||
filename = filename[:100] + '...]'
|
full_path_list = (
|
||||||
|
[os.path.join(doujinshi_dir, image) for image in file_list]
|
||||||
|
)
|
||||||
|
pdf_f.write(img2pdf.convert(full_path_list))
|
||||||
|
|
||||||
|
if rm_origin_dir:
|
||||||
|
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
||||||
|
|
||||||
|
if move_to_folder:
|
||||||
|
for filename in os.listdir(doujinshi_dir):
|
||||||
|
file_path = os.path.join(doujinshi_dir, filename)
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
try:
|
||||||
|
os.remove(file_path)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error deleting file: {e}")
|
||||||
|
|
||||||
|
shutil.move(pdf_filename, doujinshi_dir)
|
||||||
|
|
||||||
|
logger.log(16, f'PDF file has been written to "{doujinshi_dir}"')
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
logger.error("Please install img2pdf package by using pip.")
|
||||||
|
|
||||||
|
|
||||||
|
def format_filename(s, length=MAX_FIELD_LENGTH, _truncate_only=False):
|
||||||
|
"""
|
||||||
|
It used to be a whitelist approach allowed only alphabet and a part of symbols.
|
||||||
|
but most doujinshi's names include Japanese 2-byte characters and these was rejected.
|
||||||
|
so it is using blacklist approach now.
|
||||||
|
if filename include forbidden characters (\'/:,;*?"<>|) ,it replace space character(' ').
|
||||||
|
"""
|
||||||
|
# maybe you can use `--format` to select a suitable filename
|
||||||
|
|
||||||
|
if not _truncate_only:
|
||||||
|
ban_chars = '\\\'/:,;*?"<>|\t\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b'
|
||||||
|
filename = s.translate(str.maketrans(ban_chars, ' ' * len(ban_chars))).strip()
|
||||||
|
filename = ' '.join(filename.split())
|
||||||
|
|
||||||
|
while filename.endswith('.'):
|
||||||
|
filename = filename[:-1]
|
||||||
|
else:
|
||||||
|
filename = s
|
||||||
|
|
||||||
|
# limit `length` chars
|
||||||
|
if len(filename) >= length:
|
||||||
|
filename = filename[:length - 1] + u'…'
|
||||||
|
|
||||||
# Remove [] from filename
|
# Remove [] from filename
|
||||||
filename = filename.replace('[]', '')
|
filename = filename.replace('[]', '').strip()
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(signal, frame):
|
||||||
|
logger.error('Ctrl-C signal received. Stopping...')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def paging(page_string):
|
||||||
|
# 1,3-5,14 -> [1, 3, 4, 5, 14]
|
||||||
|
if not page_string:
|
||||||
|
return []
|
||||||
|
|
||||||
|
page_list = []
|
||||||
|
for i in page_string.split(','):
|
||||||
|
if '-' in i:
|
||||||
|
start, end = i.split('-')
|
||||||
|
if not (start.isdigit() and end.isdigit()):
|
||||||
|
raise Exception('Invalid page number')
|
||||||
|
page_list.extend(list(range(int(start), int(end) + 1)))
|
||||||
|
else:
|
||||||
|
if not i.isdigit():
|
||||||
|
raise Exception('Invalid page number')
|
||||||
|
page_list.append(int(i))
|
||||||
|
|
||||||
|
return page_list
|
||||||
|
|
||||||
|
|
||||||
|
def generate_metadata_file(output_dir, table, doujinshi_obj=None):
|
||||||
|
logger.info('Writing Metadata Info')
|
||||||
|
|
||||||
|
if doujinshi_obj is not None:
|
||||||
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
|
else:
|
||||||
|
doujinshi_dir = '.'
|
||||||
|
|
||||||
|
logger.info(doujinshi_dir)
|
||||||
|
|
||||||
|
f = open(os.path.join(doujinshi_dir, 'info.txt'), 'w', encoding='utf-8')
|
||||||
|
|
||||||
|
fields = ['TITLE', 'ORIGINAL TITLE', 'AUTHOR', 'ARTIST', 'GROUPS', 'CIRCLE', 'SCANLATOR',
|
||||||
|
'TRANSLATOR', 'PUBLISHER', 'DESCRIPTION', 'STATUS', 'CHAPTERS', 'PAGES',
|
||||||
|
'TAGS', 'TYPE', 'LANGUAGE', 'RELEASED', 'READING DIRECTION', 'CHARACTERS',
|
||||||
|
'SERIES', 'PARODY', 'URL']
|
||||||
|
special_fields = ['PARODY', 'TITLE', 'ORIGINAL TITLE', 'CHARACTERS', 'AUTHOR', 'GROUPS',
|
||||||
|
'LANGUAGE', 'TAGS', 'URL', 'PAGES']
|
||||||
|
|
||||||
|
for i in range(len(fields)):
|
||||||
|
f.write(f'{fields[i]}: ')
|
||||||
|
if fields[i] in special_fields:
|
||||||
|
f.write(str(table[special_fields.index(fields[i])][1]))
|
||||||
|
f.write('\n')
|
||||||
|
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
class DB(object):
|
||||||
|
conn = None
|
||||||
|
cur = None
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.conn = sqlite3.connect(constant.NHENTAI_HISTORY)
|
||||||
|
self.cur = self.conn.cursor()
|
||||||
|
self.cur.execute('CREATE TABLE IF NOT EXISTS download_history (id text)')
|
||||||
|
self.conn.commit()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
|
def clean_all(self):
|
||||||
|
self.cur.execute('DELETE FROM download_history WHERE 1')
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def add_one(self, data):
|
||||||
|
self.cur.execute('INSERT INTO download_history VALUES (?)', [data])
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def get_all(self):
|
||||||
|
data = self.cur.execute('SELECT id FROM download_history')
|
||||||
|
return [i[0] for i in data]
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||||
<title>{TITLE}</title>
|
<title>{TITLE}</title>
|
||||||
<style>
|
<style>
|
||||||
{STYLES}
|
{STYLES}
|
@ -17,6 +17,8 @@ function changePage(pageNum) {
|
|||||||
const display = document.getElementById('dest');
|
const display = document.getElementById('dest');
|
||||||
display.style.backgroundImage = `url("${current.src}")`;
|
display.style.backgroundImage = `url("${current.src}")`;
|
||||||
|
|
||||||
|
scroll(0,0)
|
||||||
|
|
||||||
document.getElementById('page-num')
|
document.getElementById('page-num')
|
||||||
.innerText = [
|
.innerText = [
|
||||||
(pageNum + 1).toLocaleString(),
|
(pageNum + 1).toLocaleString(),
|
||||||
@ -46,14 +48,21 @@ document.getElementById('image-container').onclick = event => {
|
|||||||
document.onkeypress = event => {
|
document.onkeypress = event => {
|
||||||
switch (event.key.toLowerCase()) {
|
switch (event.key.toLowerCase()) {
|
||||||
// Previous Image
|
// Previous Image
|
||||||
|
case 'w':
|
||||||
|
scrollBy(0, -40);
|
||||||
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
changePage(currentPage - 1);
|
changePage(currentPage - 1);
|
||||||
break;
|
break;
|
||||||
|
// Return to previous page
|
||||||
|
case 'q':
|
||||||
|
window.history.go(-1);
|
||||||
|
break;
|
||||||
// Next Image
|
// Next Image
|
||||||
case ' ':
|
case ' ':
|
||||||
case 'esc': // future close page function
|
case 's':
|
||||||
case 'enter':
|
scrollBy(0, 40);
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
changePage(currentPage + 1);
|
changePage(currentPage + 1);
|
||||||
break;
|
break;
|
||||||
@ -66,13 +75,11 @@ document.onkeydown = event =>{
|
|||||||
changePage(currentPage - 1);
|
changePage(currentPage - 1);
|
||||||
break;
|
break;
|
||||||
case 38: //up
|
case 38: //up
|
||||||
changePage(currentPage - 1);
|
|
||||||
break;
|
break;
|
||||||
case 39: //right
|
case 39: //right
|
||||||
changePage(currentPage + 1);
|
changePage(currentPage + 1);
|
||||||
break;
|
break;
|
||||||
case 40: //down
|
case 40: //down
|
||||||
changePage(currentPage + 1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
*, *::after, *::before {
|
*, *::after, *::before {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
@ -17,8 +18,8 @@ html, body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#list {
|
#list {
|
||||||
height: 100%;
|
height: 2000px;
|
||||||
overflow: auto;
|
overflow: scroll;
|
||||||
width: 260px;
|
width: 260px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
@ -37,7 +38,7 @@ html, body {
|
|||||||
|
|
||||||
#image-container {
|
#image-container {
|
||||||
flex: auto;
|
flex: auto;
|
||||||
height: 100vh;
|
height: 2000px;
|
||||||
background: #222;
|
background: #222;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@ -48,16 +49,16 @@ html, body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#image-container #dest {
|
#image-container #dest {
|
||||||
height: 100%;
|
height: 2000px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-size: contain;
|
background-size: contain;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: center;
|
background-position: top;
|
||||||
}
|
}
|
||||||
|
|
||||||
#image-container #page-num {
|
#image-container #page-num {
|
||||||
position: absolute;
|
position: static;
|
||||||
font-size: 18pt;
|
font-size: 14pt;
|
||||||
left: 10px;
|
left: 10px;
|
||||||
bottom: 5px;
|
bottom: 5px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
BIN
nhentai/viewer/logo.png
Normal file
After Width: | Height: | Size: 10 KiB |
332
nhentai/viewer/main.css
Normal file
@ -0,0 +1,332 @@
|
|||||||
|
/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */
|
||||||
|
/* Original from https://static.nhentai.net/css/main_style.9bb9b703e601.css */
|
||||||
|
a {
|
||||||
|
background-color: transparent;
|
||||||
|
-webkit-text-decoration-skip: objects
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border-style: none
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
box-sizing: border-box
|
||||||
|
}
|
||||||
|
|
||||||
|
*,:after,:before {
|
||||||
|
box-sizing: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
body,html {
|
||||||
|
font-family: 'Noto Sans',sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.42857143;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
text-align: center;
|
||||||
|
color: #34495e;
|
||||||
|
background-color: #fff;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #34495e
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
border: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
display: block;
|
||||||
|
clear: both;
|
||||||
|
margin-left: 15rem;
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
margin-top: 5px;
|
||||||
|
padding: 4px;
|
||||||
|
border-radius: 9px;
|
||||||
|
background-color: #ecf0f1;
|
||||||
|
width: 100% - 15rem;
|
||||||
|
max-width: 1500px
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery,.gallery-favorite,.thumb-container {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: top
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery img,.gallery-favorite img,.thumb-container img {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
height: auto
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 980px) {
|
||||||
|
.gallery,.gallery-favorite,.thumb-container {
|
||||||
|
width:19%;
|
||||||
|
margin: 3px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 979px) {
|
||||||
|
.gallery,.gallery-favorite,.thumb-container {
|
||||||
|
width:24%;
|
||||||
|
margin: 2px
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 772px) {
|
||||||
|
.gallery,.gallery-favorite,.thumb-container {
|
||||||
|
width:32%;
|
||||||
|
margin: 1.5px
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 500px) {
|
||||||
|
.gallery,.gallery-favorite,.thumb-container {
|
||||||
|
width:49%;
|
||||||
|
margin: .5px
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery a,.gallery-favorite a {
|
||||||
|
display: block
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery a img,.gallery-favorite a img {
|
||||||
|
position: absolute
|
||||||
|
}
|
||||||
|
|
||||||
|
.caption {
|
||||||
|
line-height: 15px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 100%;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 10;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
|
max-height: 34px;
|
||||||
|
padding: 3px;
|
||||||
|
background-color: #fff;
|
||||||
|
font-weight: 700;
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #34495e
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery {
|
||||||
|
position: relative;
|
||||||
|
margin-bottom: 3em
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery:hover .caption {
|
||||||
|
max-height: 100%;
|
||||||
|
box-shadow: 0 10px 20px rgba(100,100,100,.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
.gallery-favorite .gallery {
|
||||||
|
width: 100%
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidenav {
|
||||||
|
height: 100%;
|
||||||
|
width: 15rem;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
background-color: #0d0d0d;
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
|
padding-top: 20px;
|
||||||
|
-webkit-touch-callout: none; /* iOS Safari */
|
||||||
|
-webkit-user-select: none; /* Safari */
|
||||||
|
-khtml-user-select: none; /* Konqueror HTML */
|
||||||
|
-moz-user-select: none; /* Old versions of Firefox */
|
||||||
|
-ms-user-select: none; /* Internet Explorer/Edge */
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidenav a {
|
||||||
|
background-color: #eee;
|
||||||
|
padding: 5px 0px 5px 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 15px;
|
||||||
|
color: #0d0d0d;
|
||||||
|
display: block;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.sidenav img {
|
||||||
|
width:100%;
|
||||||
|
padding: 0px 5px 0px 5px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidenav h1 {
|
||||||
|
font-size: 1.5em;
|
||||||
|
margin: 0px 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidenav a:hover {
|
||||||
|
color: white;
|
||||||
|
background-color: #EC2754;
|
||||||
|
}
|
||||||
|
|
||||||
|
.accordion {
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: #eee;
|
||||||
|
color: #444;
|
||||||
|
padding: 10px 0px 5px 8px;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
text-align: left;
|
||||||
|
outline: none;
|
||||||
|
font-size: 15px;
|
||||||
|
transition: 0.4s;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.accordion:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.accordion.active{
|
||||||
|
background-color:#ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-btn {
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: #eee;
|
||||||
|
color: #444;
|
||||||
|
padding: 8px 8px 5px 9px;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
text-align: left;
|
||||||
|
outline: none;
|
||||||
|
font-size: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-btn a{
|
||||||
|
font-weight: normal;
|
||||||
|
padding-right: 10px;
|
||||||
|
border-radius: 15px;
|
||||||
|
cursor: crosshair
|
||||||
|
}
|
||||||
|
|
||||||
|
.options {
|
||||||
|
display:block;
|
||||||
|
padding: 0px 0px 0px 0px;
|
||||||
|
background-color: #eee;
|
||||||
|
max-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: max-height 0.2s ease-out;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search{
|
||||||
|
background-color: #eee;
|
||||||
|
padding-right:40px;
|
||||||
|
white-space: nowrap;
|
||||||
|
padding-top: 5px;
|
||||||
|
height:43px;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.search input{
|
||||||
|
border-top-right-radius:10px;
|
||||||
|
padding-top:0;
|
||||||
|
padding-bottom:0;
|
||||||
|
font-size:1em;
|
||||||
|
width:100%;
|
||||||
|
height:38px;
|
||||||
|
vertical-align:top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn{
|
||||||
|
border-top-left-radius:10px;
|
||||||
|
color:#fff;
|
||||||
|
font-size:100%;
|
||||||
|
padding: 8px;
|
||||||
|
width:38px;
|
||||||
|
background-color:#ed2553;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tags{
|
||||||
|
text-align:left;
|
||||||
|
display: flex;
|
||||||
|
width:15rem;
|
||||||
|
justify-content: start;
|
||||||
|
margin: 2px 2px 2px 0px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2{
|
||||||
|
font-weight:700;
|
||||||
|
padding-right:0.5rem;
|
||||||
|
padding-left:0.5rem;
|
||||||
|
color:#fff;
|
||||||
|
border:0;
|
||||||
|
font-size:100%;
|
||||||
|
height:1.25rem;
|
||||||
|
outline: 0;
|
||||||
|
border-radius: 0.3rem;
|
||||||
|
cursor: pointer;
|
||||||
|
margin:0.15rem;
|
||||||
|
transition: all 1s linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2#parody{
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2#character{
|
||||||
|
background-color: blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2#tag{
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2#artist{
|
||||||
|
background-color: fuchsia;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2#group{
|
||||||
|
background-color: teal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-2.hover{
|
||||||
|
filter: saturate(20%)
|
||||||
|
}
|
||||||
|
|
||||||
|
input,input:focus{
|
||||||
|
border:none;
|
||||||
|
outline:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.theme-black,html.theme-black body {
|
||||||
|
color: #d9d9d9;
|
||||||
|
background-color: #0d0d0d
|
||||||
|
}
|
||||||
|
|
||||||
|
html.theme-black #thumbnail-container,html.theme-black .container {
|
||||||
|
background-color: #1f1f1f
|
||||||
|
}
|
||||||
|
|
||||||
|
html.theme-black .gallery:hover .caption {
|
||||||
|
box-shadow: 0 10px 20px rgba(0,0,0,.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
html.theme-black .caption {
|
||||||
|
background-color: #404040;
|
||||||
|
color: #d9d9d9
|
||||||
|
}
|
51
nhentai/viewer/main.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en" class=" theme-black">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="theme-color" content="#1f1f1f" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||||
|
<title>nHentai Viewer</title>
|
||||||
|
<script type="text/javascript" src="data.js"></script>
|
||||||
|
<!-- <link rel="stylesheet" href="./main.css"> -->
|
||||||
|
<style>
|
||||||
|
{STYLES}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="content">
|
||||||
|
<nav class="sidenav">
|
||||||
|
<img src="logo.png">
|
||||||
|
<h1>nHentai Viewer</h1>
|
||||||
|
<button class="accordion">Language</button>
|
||||||
|
<div class="options" id="language">
|
||||||
|
<a>English</a>
|
||||||
|
<a>Japanese</a>
|
||||||
|
<a>Chinese</a>
|
||||||
|
</div>
|
||||||
|
<button class="accordion">Category</button>
|
||||||
|
<div class="options" id ="category">
|
||||||
|
<a>Doujinshi</a>
|
||||||
|
<a>Manga</a>
|
||||||
|
</div>
|
||||||
|
<button class="nav-btn hidden">Filters</button>
|
||||||
|
<div class="search">
|
||||||
|
<input autocomplete="off" type="search" id="tagfilter" name="q" value="" autocapitalize="none" required="">
|
||||||
|
<svg class="btn" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="white" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"/></svg>
|
||||||
|
<div id="tags">
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="container" id="favcontainer">
|
||||||
|
|
||||||
|
{PICTURE}
|
||||||
|
|
||||||
|
</div> <!-- container -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
{SCRIPTS}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
177
nhentai/viewer/main.js
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
//------------------------------------navbar script------------------------------------
|
||||||
|
var menu = document.getElementsByClassName("accordion");
|
||||||
|
for (var i = 0; i < menu.length; i++) {
|
||||||
|
menu[i].addEventListener("click", function() {
|
||||||
|
var panel = this.nextElementSibling;
|
||||||
|
if (panel.style.maxHeight) {
|
||||||
|
this.classList.toggle("active");
|
||||||
|
panel.style.maxHeight = null;
|
||||||
|
} else {
|
||||||
|
panel.style.maxHeight = panel.scrollHeight + "px";
|
||||||
|
this.classList.toggle("active");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var language = document.getElementById("language").children;
|
||||||
|
for (var i = 0; i < language.length; i++){
|
||||||
|
language[i].addEventListener("click", function() {
|
||||||
|
toggler = document.getElementById("language")
|
||||||
|
toggler.style.maxHeight = null;
|
||||||
|
document.getElementsByClassName("accordion")[0].classList.toggle("active");
|
||||||
|
filter_maker(this.innerText, "language");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var category = document.getElementById("category").children;
|
||||||
|
for (var i = 0; i < category.length; i++){
|
||||||
|
category[i].addEventListener("click", function() {
|
||||||
|
document.getElementById("category").style.maxHeight = null;
|
||||||
|
document.getElementsByClassName("accordion")[1].classList.toggle("active");
|
||||||
|
filter_maker(this.innerText, "category");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
|
//----------------------------------Tags Script--------------------------------------
|
||||||
|
tag_maker(tags);
|
||||||
|
|
||||||
|
var tag = document.getElementsByClassName("btn-2");
|
||||||
|
for (var i = 0; i < tag.length; i++){
|
||||||
|
tag[i].addEventListener("click", function() {
|
||||||
|
filter_maker(this.innerText, this.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var input = document.getElementById("tagfilter");
|
||||||
|
input.addEventListener("input", function() {
|
||||||
|
var tags = document.querySelectorAll(".btn-2");
|
||||||
|
if (this.value.length > 0) {
|
||||||
|
for (var i = 0; i < tags.length; i++) {
|
||||||
|
var tag = tags[i];
|
||||||
|
var nome = tag.innerText;
|
||||||
|
var exp = new RegExp(this.value, "i");;
|
||||||
|
if (exp.test(nome)) {
|
||||||
|
tag.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tag.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var i = 0; i < tags.length; i++) {
|
||||||
|
var tag = tags[i];
|
||||||
|
tag.classList.add('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.addEventListener('keypress', function (e) {
|
||||||
|
enter_search(e, this.value);
|
||||||
|
});
|
||||||
|
//-----------------------------------------------------------------------------------
|
||||||
|
//------------------------------------Functions--------------------------------------
|
||||||
|
function enter_search(e, input){
|
||||||
|
var count = 0;
|
||||||
|
var key = e.which || e.keyCode;
|
||||||
|
if (key === 13 && input.length > 0) {
|
||||||
|
var all_tags = document.getElementById("tags").children;
|
||||||
|
for(i = 0; i < all_tags.length; i++){
|
||||||
|
if (!all_tags[i].classList.contains("hidden")){
|
||||||
|
count++;
|
||||||
|
var tag_name = all_tags[i].innerText;
|
||||||
|
var tag_id = all_tags[i].id;
|
||||||
|
if (count>1){break}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count == 1){
|
||||||
|
filter_maker(tag_name, tag_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function filter_maker(text, class_value){
|
||||||
|
var check = filter_checker(text);
|
||||||
|
var nav_btn = document.getElementsByClassName("nav-btn")[0];
|
||||||
|
if (nav_btn.classList.contains("hidden")){
|
||||||
|
nav_btn.classList.toggle("hidden");
|
||||||
|
}
|
||||||
|
if (check == true){
|
||||||
|
var node = document.createElement("a");
|
||||||
|
var textnode = document.createTextNode(text);
|
||||||
|
node.appendChild(textnode);
|
||||||
|
node.classList.add(class_value);
|
||||||
|
nav_btn.appendChild(node);
|
||||||
|
filter_searcher();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filter_searcher(){
|
||||||
|
var verifier = null;
|
||||||
|
var tags_filter = [];
|
||||||
|
var doujinshi_id = [];
|
||||||
|
var filter_tag = document.getElementsByClassName("nav-btn")[0].children;
|
||||||
|
filter_tag[filter_tag.length-1].addEventListener("click", function() {
|
||||||
|
this.remove();
|
||||||
|
try{
|
||||||
|
filter_searcher();
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
var gallery = document.getElementsByClassName("gallery-favorite");
|
||||||
|
for (var i = 0; i < gallery.length; i++){
|
||||||
|
gallery[i].classList.remove("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (var i=0; i < filter_tag.length; i++){
|
||||||
|
var fclass = filter_tag[i].className;
|
||||||
|
var fname = filter_tag[i].innerText.toLowerCase();
|
||||||
|
tags_filter.push([fclass, fname])
|
||||||
|
}
|
||||||
|
for (var i=0; i < data.length; i++){
|
||||||
|
for (var j=0; j < tags_filter.length; j++){
|
||||||
|
try{
|
||||||
|
if(data[i][tags_filter[j][0]].includes(tags_filter[j][1])){
|
||||||
|
verifier = true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
verifier = false;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch{
|
||||||
|
verifier = false;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (verifier){doujinshi_id.push(data[i].Folder);}
|
||||||
|
}
|
||||||
|
var gallery = document.getElementsByClassName("gallery-favorite");
|
||||||
|
for (var i = 0; i < gallery.length; i++){
|
||||||
|
gtext = gallery [i].children[0].children[0].children[1].innerText;
|
||||||
|
if(doujinshi_id.includes(gtext)){
|
||||||
|
gallery[i].classList.remove("hidden");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
gallery[i].classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function filter_checker(text){
|
||||||
|
var filter_tags = document.getElementsByClassName("nav-btn")[0].children;
|
||||||
|
if (filter_tags == null){return true;}
|
||||||
|
for (var i=0; i < filter_tags.length; i++){
|
||||||
|
if (filter_tags[i].innerText == text){return false;}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tag_maker(data){
|
||||||
|
for (i in data){
|
||||||
|
for (j in data[i]){
|
||||||
|
var node = document.createElement("button");
|
||||||
|
var textnode = document.createTextNode(data[i][j]);
|
||||||
|
node.appendChild(textnode);
|
||||||
|
node.classList.add("btn-2");
|
||||||
|
node.setAttribute('id', i);
|
||||||
|
node.classList.add("hidden");
|
||||||
|
document.getElementById("tags").appendChild(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
nhentai/viewer/minimal/index.html
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||||
|
<title>{TITLE}</title>
|
||||||
|
<style>
|
||||||
|
{STYLES}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<nav id="list" hidden=true>
|
||||||
|
{IMAGES}</nav>
|
||||||
|
|
||||||
|
<div id="image-container">
|
||||||
|
<div id="dest"></div>
|
||||||
|
<span id="page-num"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
{SCRIPTS}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
79
nhentai/viewer/minimal/scripts.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
const pages = Array.from(document.querySelectorAll('img.image-item'));
|
||||||
|
let currentPage = 0;
|
||||||
|
|
||||||
|
function changePage(pageNum) {
|
||||||
|
const previous = pages[currentPage];
|
||||||
|
const current = pages[pageNum];
|
||||||
|
|
||||||
|
if (current == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
previous.classList.remove('current');
|
||||||
|
current.classList.add('current');
|
||||||
|
|
||||||
|
currentPage = pageNum;
|
||||||
|
|
||||||
|
const display = document.getElementById('dest');
|
||||||
|
display.style.backgroundImage = `url("${current.src}")`;
|
||||||
|
|
||||||
|
scroll(0,0)
|
||||||
|
|
||||||
|
document.getElementById('page-num')
|
||||||
|
.innerText = [
|
||||||
|
(pageNum + 1).toLocaleString(),
|
||||||
|
pages.length.toLocaleString()
|
||||||
|
].join('\u200a/\u200a');
|
||||||
|
}
|
||||||
|
|
||||||
|
changePage(0);
|
||||||
|
|
||||||
|
document.getElementById('image-container').onclick = event => {
|
||||||
|
const width = document.getElementById('image-container').clientWidth;
|
||||||
|
const clickPos = event.clientX / width;
|
||||||
|
|
||||||
|
if (clickPos < 0.5) {
|
||||||
|
changePage(currentPage - 1);
|
||||||
|
} else {
|
||||||
|
changePage(currentPage + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.onkeypress = event => {
|
||||||
|
switch (event.key.toLowerCase()) {
|
||||||
|
// Previous Image
|
||||||
|
case 'w':
|
||||||
|
scrollBy(0, -40);
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
changePage(currentPage - 1);
|
||||||
|
break;
|
||||||
|
// Return to previous page
|
||||||
|
case 'q':
|
||||||
|
window.history.go(-1);
|
||||||
|
break;
|
||||||
|
// Next Image
|
||||||
|
case ' ':
|
||||||
|
case 's':
|
||||||
|
scrollBy(0, 40);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
changePage(currentPage + 1);
|
||||||
|
break;
|
||||||
|
}// remove arrow cause it won't work
|
||||||
|
};
|
||||||
|
|
||||||
|
document.onkeydown = event =>{
|
||||||
|
switch (event.keyCode) {
|
||||||
|
case 37: //left
|
||||||
|
changePage(currentPage - 1);
|
||||||
|
break;
|
||||||
|
case 38: //up
|
||||||
|
break;
|
||||||
|
case 39: //right
|
||||||
|
changePage(currentPage + 1);
|
||||||
|
break;
|
||||||
|
case 40: //down
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
75
nhentai/viewer/minimal/styles.css
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
|
||||||
|
*, *::after, *::before {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
display: flex;
|
||||||
|
background-color: #e8e6e6;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
#list {
|
||||||
|
height: 2000px;
|
||||||
|
overflow: scroll;
|
||||||
|
width: 260px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#list img {
|
||||||
|
width: 200px;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin: 15px 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#list img.current {
|
||||||
|
background: #0003;
|
||||||
|
}
|
||||||
|
|
||||||
|
#image-container {
|
||||||
|
flex: auto;
|
||||||
|
height: 100%;
|
||||||
|
background: rgb(0, 0, 0);
|
||||||
|
color: rgb(100, 100, 100);
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
#image-container #dest {
|
||||||
|
height: 2000px;
|
||||||
|
width: 100%;
|
||||||
|
background-size: contain;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: top;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100vh;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#image-container #page-num {
|
||||||
|
position: static;
|
||||||
|
font-size: 9pt;
|
||||||
|
left: 10px;
|
||||||
|
bottom: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
opacity: 0.9;
|
||||||
|
text-shadow: /* Duplicate the same shadow to make it very strong */
|
||||||
|
0 0 2px #222,
|
||||||
|
0 0 2px #222,
|
||||||
|
0 0 2px #222;
|
||||||
|
}
|
216
poetry.lock
generated
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "beautifulsoup4"
|
||||||
|
version = "4.11.2"
|
||||||
|
description = "Screen-scraping library"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6.0"
|
||||||
|
files = [
|
||||||
|
{file = "beautifulsoup4-4.11.2-py3-none-any.whl", hash = "sha256:0e79446b10b3ecb499c1556f7e228a53e64a2bfcebd455f370d8927cb5b59e39"},
|
||||||
|
{file = "beautifulsoup4-4.11.2.tar.gz", hash = "sha256:bc4bdda6717de5a2987436fb8d72f45dc90dd856bdfd512a1314ce90349a0106"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
soupsieve = ">1.2"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
html5lib = ["html5lib"]
|
||||||
|
lxml = ["lxml"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "certifi"
|
||||||
|
version = "2022.12.7"
|
||||||
|
description = "Python package for providing Mozilla's CA Bundle."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6"
|
||||||
|
files = [
|
||||||
|
{file = "certifi-2022.12.7-py3-none-any.whl", hash = "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18"},
|
||||||
|
{file = "certifi-2022.12.7.tar.gz", hash = "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "charset-normalizer"
|
||||||
|
version = "3.0.1"
|
||||||
|
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "charset-normalizer-3.0.1.tar.gz", hash = "sha256:ebea339af930f8ca5d7a699b921106c6e29c617fe9606fa7baa043c1cdae326f"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:88600c72ef7587fe1708fd242b385b6ed4b8904976d5da0893e31df8b3480cb6"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c75ffc45f25324e68ab238cb4b5c0a38cd1c3d7f1fb1f72b5541de469e2247db"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:db72b07027db150f468fbada4d85b3b2729a3db39178abf5c543b784c1254539"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:62595ab75873d50d57323a91dd03e6966eb79c41fa834b7a1661ed043b2d404d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ff6f3db31555657f3163b15a6b7c6938d08df7adbfc9dd13d9d19edad678f1e8"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:772b87914ff1152b92a197ef4ea40efe27a378606c39446ded52c8f80f79702e"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70990b9c51340e4044cfc394a81f614f3f90d41397104d226f21e66de668730d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:292d5e8ba896bbfd6334b096e34bffb56161c81408d6d036a7dfa6929cff8783"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:2edb64ee7bf1ed524a1da60cdcd2e1f6e2b4f66ef7c077680739f1641f62f555"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:31a9ddf4718d10ae04d9b18801bd776693487cbb57d74cc3458a7673f6f34639"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:44ba614de5361b3e5278e1241fda3dc1838deed864b50a10d7ce92983797fa76"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:12db3b2c533c23ab812c2b25934f60383361f8a376ae272665f8e48b88e8e1c6"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:c512accbd6ff0270939b9ac214b84fb5ada5f0409c44298361b2f5e13f9aed9e"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-win32.whl", hash = "sha256:502218f52498a36d6bf5ea77081844017bf7982cdbe521ad85e64cabee1b608b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:601f36512f9e28f029d9481bdaf8e89e5148ac5d89cffd3b05cd533eeb423b59"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:0298eafff88c99982a4cf66ba2efa1128e4ddaca0b05eec4c456bbc7db691d8d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a8d0fc946c784ff7f7c3742310cc8a57c5c6dc31631269876a88b809dbeff3d3"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:87701167f2a5c930b403e9756fab1d31d4d4da52856143b609e30a1ce7160f3c"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:14e76c0f23218b8f46c4d87018ca2e441535aed3632ca134b10239dfb6dadd6b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0c0a590235ccd933d9892c627dec5bc7511ce6ad6c1011fdf5b11363022746c1"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8c7fe7afa480e3e82eed58e0ca89f751cd14d767638e2550c77a92a9e749c317"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:79909e27e8e4fcc9db4addea88aa63f6423ebb171db091fb4373e3312cb6d603"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8ac7b6a045b814cf0c47f3623d21ebd88b3e8cf216a14790b455ea7ff0135d18"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:72966d1b297c741541ca8cf1223ff262a6febe52481af742036a0b296e35fa5a"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:f9d0c5c045a3ca9bedfc35dca8526798eb91a07aa7a2c0fee134c6c6f321cbd7"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:5995f0164fa7df59db4746112fec3f49c461dd6b31b841873443bdb077c13cfc"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:4a8fcf28c05c1f6d7e177a9a46a1c52798bfe2ad80681d275b10dcf317deaf0b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:761e8904c07ad053d285670f36dd94e1b6ab7f16ce62b9805c475b7aa1cffde6"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-win32.whl", hash = "sha256:71140351489970dfe5e60fc621ada3e0f41104a5eddaca47a7acb3c1b851d6d3"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:9ab77acb98eba3fd2a85cd160851816bfce6871d944d885febf012713f06659c"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:84c3990934bae40ea69a82034912ffe5a62c60bbf6ec5bc9691419641d7d5c9a"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:74292fc76c905c0ef095fe11e188a32ebd03bc38f3f3e9bcb85e4e6db177b7ea"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c95a03c79bbe30eec3ec2b7f076074f4281526724c8685a42872974ef4d36b72"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f4c39b0e3eac288fedc2b43055cfc2ca7a60362d0e5e87a637beac5d801ef478"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:df2c707231459e8a4028eabcd3cfc827befd635b3ef72eada84ab13b52e1574d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:93ad6d87ac18e2a90b0fe89df7c65263b9a99a0eb98f0a3d2e079f12a0735837"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:59e5686dd847347e55dffcc191a96622f016bc0ad89105e24c14e0d6305acbc6"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:cd6056167405314a4dc3c173943f11249fa0f1b204f8b51ed4bde1a9cd1834dc"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-musllinux_1_1_ppc64le.whl", hash = "sha256:083c8d17153ecb403e5e1eb76a7ef4babfc2c48d58899c98fcaa04833e7a2f9a"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-musllinux_1_1_s390x.whl", hash = "sha256:f5057856d21e7586765171eac8b9fc3f7d44ef39425f85dbcccb13b3ebea806c"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:7eb33a30d75562222b64f569c642ff3dc6689e09adda43a082208397f016c39a"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-win32.whl", hash = "sha256:95dea361dd73757c6f1c0a1480ac499952c16ac83f7f5f4f84f0658a01b8ef41"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp36-cp36m-win_amd64.whl", hash = "sha256:eaa379fcd227ca235d04152ca6704c7cb55564116f8bc52545ff357628e10602"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:3e45867f1f2ab0711d60c6c71746ac53537f1684baa699f4f668d4c6f6ce8e14"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cadaeaba78750d58d3cc6ac4d1fd867da6fc73c88156b7a3212a3cd4819d679d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:911d8a40b2bef5b8bbae2e36a0b103f142ac53557ab421dc16ac4aafee6f53dc"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:503e65837c71b875ecdd733877d852adbc465bd82c768a067badd953bf1bc5a3"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a60332922359f920193b1d4826953c507a877b523b2395ad7bc716ddd386d866"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:16a8663d6e281208d78806dbe14ee9903715361cf81f6d4309944e4d1e59ac5b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:a16418ecf1329f71df119e8a65f3aa68004a3f9383821edcb20f0702934d8087"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:9d9153257a3f70d5f69edf2325357251ed20f772b12e593f3b3377b5f78e7ef8"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:02a51034802cbf38db3f89c66fb5d2ec57e6fe7ef2f4a44d070a593c3688667b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-musllinux_1_1_s390x.whl", hash = "sha256:2e396d70bc4ef5325b72b593a72c8979999aa52fb8bcf03f701c1b03e1166918"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:11b53acf2411c3b09e6af37e4b9005cba376c872503c8f28218c7243582df45d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-win32.whl", hash = "sha256:0bf2dae5291758b6f84cf923bfaa285632816007db0330002fa1de38bfcb7154"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp37-cp37m-win_amd64.whl", hash = "sha256:2c03cc56021a4bd59be889c2b9257dae13bf55041a3372d3295416f86b295fb5"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:024e606be3ed92216e2b6952ed859d86b4cfa52cd5bc5f050e7dc28f9b43ec42"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:4b0d02d7102dd0f997580b51edc4cebcf2ab6397a7edf89f1c73b586c614272c"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:358a7c4cb8ba9b46c453b1dd8d9e431452d5249072e4f56cfda3149f6ab1405e"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:81d6741ab457d14fdedc215516665050f3822d3e56508921cc7239f8c8e66a58"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8b8af03d2e37866d023ad0ddea594edefc31e827fee64f8de5611a1dbc373174"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9cf4e8ad252f7c38dd1f676b46514f92dc0ebeb0db5552f5f403509705e24753"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e696f0dd336161fca9adbb846875d40752e6eba585843c768935ba5c9960722b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c22d3fe05ce11d3671297dc8973267daa0f938b93ec716e12e0f6dee81591dc1"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:109487860ef6a328f3eec66f2bf78b0b72400280d8f8ea05f69c51644ba6521a"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:37f8febc8ec50c14f3ec9637505f28e58d4f66752207ea177c1d67df25da5aed"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:f97e83fa6c25693c7a35de154681fcc257c1c41b38beb0304b9c4d2d9e164479"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:a152f5f33d64a6be73f1d30c9cc82dfc73cec6477ec268e7c6e4c7d23c2d2291"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:39049da0ffb96c8cbb65cbf5c5f3ca3168990adf3551bd1dee10c48fce8ae820"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-win32.whl", hash = "sha256:4457ea6774b5611f4bed5eaa5df55f70abde42364d498c5134b7ef4c6958e20e"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:e62164b50f84e20601c1ff8eb55620d2ad25fb81b59e3cd776a1902527a788af"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:8eade758719add78ec36dc13201483f8e9b5d940329285edcd5f70c0a9edbd7f"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:8499ca8f4502af841f68135133d8258f7b32a53a1d594aa98cc52013fff55678"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3fc1c4a2ffd64890aebdb3f97e1278b0cc72579a08ca4de8cd2c04799a3a22be"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:00d3ffdaafe92a5dc603cb9bd5111aaa36dfa187c8285c543be562e61b755f6b"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c2ac1b08635a8cd4e0cbeaf6f5e922085908d48eb05d44c5ae9eabab148512ca"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f6f45710b4459401609ebebdbcfb34515da4fc2aa886f95107f556ac69a9147e"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ae1de54a77dc0d6d5fcf623290af4266412a7c4be0b1ff7444394f03f5c54e3"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3b590df687e3c5ee0deef9fc8c547d81986d9a1b56073d82de008744452d6541"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ab5de034a886f616a5668aa5d098af2b5385ed70142090e2a31bcbd0af0fdb3d"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9cb3032517f1627cc012dbc80a8ec976ae76d93ea2b5feaa9d2a5b8882597579"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:608862a7bf6957f2333fc54ab4399e405baad0163dc9f8d99cb236816db169d4"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:0f438ae3532723fb6ead77e7c604be7c8374094ef4ee2c5e03a3a17f1fca256c"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:356541bf4381fa35856dafa6a965916e54bed415ad8a24ee6de6e37deccf2786"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-win32.whl", hash = "sha256:39cf9ed17fe3b1bc81f33c9ceb6ce67683ee7526e65fde1447c772afc54a1bb8"},
|
||||||
|
{file = "charset_normalizer-3.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:0a11e971ed097d24c534c037d298ad32c6ce81a45736d31e0ff0ad37ab437d59"},
|
||||||
|
{file = "charset_normalizer-3.0.1-py3-none-any.whl", hash = "sha256:7e189e2e1d3ed2f4aebabd2d5b0f931e883676e51c7624826e0a4e5fe8a0bf24"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "idna"
|
||||||
|
version = "3.4"
|
||||||
|
description = "Internationalized Domain Names in Applications (IDNA)"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.5"
|
||||||
|
files = [
|
||||||
|
{file = "idna-3.4-py3-none-any.whl", hash = "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"},
|
||||||
|
{file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iso8601"
|
||||||
|
version = "1.1.0"
|
||||||
|
description = "Simple module to parse ISO 8601 dates"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.6.2,<4.0"
|
||||||
|
files = [
|
||||||
|
{file = "iso8601-1.1.0-py3-none-any.whl", hash = "sha256:8400e90141bf792bce2634df533dc57e3bee19ea120a87bebcd3da89a58ad73f"},
|
||||||
|
{file = "iso8601-1.1.0.tar.gz", hash = "sha256:32811e7b81deee2063ea6d2e94f8819a86d1f3811e49d23623a41fa832bef03f"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "requests"
|
||||||
|
version = "2.31.0"
|
||||||
|
description = "Python HTTP for Humans."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.7"
|
||||||
|
files = [
|
||||||
|
{file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"},
|
||||||
|
{file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
certifi = ">=2017.4.17"
|
||||||
|
charset-normalizer = ">=2,<4"
|
||||||
|
idna = ">=2.5,<4"
|
||||||
|
urllib3 = ">=1.21.1,<3"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||||
|
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "soupsieve"
|
||||||
|
version = "2.4"
|
||||||
|
description = "A modern CSS selector implementation for Beautiful Soup."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.7"
|
||||||
|
files = [
|
||||||
|
{file = "soupsieve-2.4-py3-none-any.whl", hash = "sha256:49e5368c2cda80ee7e84da9dbe3e110b70a4575f196efb74e51b94549d921955"},
|
||||||
|
{file = "soupsieve-2.4.tar.gz", hash = "sha256:e28dba9ca6c7c00173e34e4ba57448f0688bb681b7c5e8bf4971daafc093d69a"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tabulate"
|
||||||
|
version = "0.9.0"
|
||||||
|
description = "Pretty-print tabular data"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.7"
|
||||||
|
files = [
|
||||||
|
{file = "tabulate-0.9.0-py3-none-any.whl", hash = "sha256:024ca478df22e9340661486f85298cff5f6dcdba14f3813e8830015b9ed1948f"},
|
||||||
|
{file = "tabulate-0.9.0.tar.gz", hash = "sha256:0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
widechars = ["wcwidth"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "urllib3"
|
||||||
|
version = "1.26.18"
|
||||||
|
description = "HTTP library with thread-safe connection pooling, file post, and more."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"
|
||||||
|
files = [
|
||||||
|
{file = "urllib3-1.26.18-py2.py3-none-any.whl", hash = "sha256:34b97092d7e0a3a8cf7cd10e386f401b3737364026c45e622aa02903dffe0f07"},
|
||||||
|
{file = "urllib3-1.26.18.tar.gz", hash = "sha256:f8ecc1bba5667413457c529ab955bf8c67b45db799d159066261719e328580a0"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
brotli = ["brotli (==1.0.9)", "brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"]
|
||||||
|
secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"]
|
||||||
|
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
lock-version = "2.0"
|
||||||
|
python-versions = "^3.8"
|
||||||
|
content-hash = "0a1d5abd47a669c7a1f2dc7b43824a449e29ba94908a4338d2ea0f2dfb4f805e"
|
21
pyproject.toml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "nhentai"
|
||||||
|
version = "0.5.3"
|
||||||
|
description = "nhentai doujinshi downloader"
|
||||||
|
authors = ["Ricter Z <ricterzheng@gmail.com>"]
|
||||||
|
license = "MIT"
|
||||||
|
readme = "README.rst"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = "^3.8"
|
||||||
|
requests = "^2.28.2"
|
||||||
|
soupsieve = "^2.4"
|
||||||
|
beautifulsoup4 = "^4.11.2"
|
||||||
|
tabulate = "^0.9.0"
|
||||||
|
iso8601 = "^1.1.0"
|
||||||
|
urllib3 = "^1.26.14"
|
||||||
|
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
@ -1,5 +1,6 @@
|
|||||||
requests>=2.5.0
|
requests
|
||||||
BeautifulSoup4>=4.0.0
|
soupsieve
|
||||||
threadpool>=1.2.7
|
BeautifulSoup4
|
||||||
tabulate>=0.7.5
|
tabulate
|
||||||
future>=0.15.2
|
iso8601
|
||||||
|
urllib3
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
description-file = README.md
|
description-file = README.rst
|
||||||
|
|
||||||
|
10
setup.py
@ -1,6 +1,4 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import print_function, unicode_literals
|
|
||||||
import sys
|
|
||||||
import codecs
|
import codecs
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
from nhentai import __version__, __author__, __email__
|
from nhentai import __version__, __author__, __email__
|
||||||
@ -11,9 +9,9 @@ with open('requirements.txt') as f:
|
|||||||
|
|
||||||
|
|
||||||
def long_description():
|
def long_description():
|
||||||
with codecs.open('README.md', 'rb') as f:
|
with codecs.open('README.rst', 'rb') as readme:
|
||||||
if sys.version_info >= (3, 0, 0):
|
return readme.read().decode('utf-8')
|
||||||
return str(f.read())
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='nhentai',
|
name='nhentai',
|
||||||
@ -22,7 +20,7 @@ setup(
|
|||||||
|
|
||||||
author=__author__,
|
author=__author__,
|
||||||
author_email=__email__,
|
author_email=__email__,
|
||||||
keywords='nhentai, doujinshi',
|
keywords=['nhentai', 'doujinshi', 'downloader'],
|
||||||
description='nhentai.net doujinshis downloader',
|
description='nhentai.net doujinshis downloader',
|
||||||
long_description=long_description(),
|
long_description=long_description(),
|
||||||
url='https://github.com/RicterZ/nhentai',
|
url='https://github.com/RicterZ/nhentai',
|
||||||
|
0
tests/__init__.py
Normal file
36
tests/test_download.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
import urllib3.exceptions
|
||||||
|
|
||||||
|
from nhentai import constant
|
||||||
|
from nhentai.cmdline import load_config
|
||||||
|
from nhentai.downloader import Downloader
|
||||||
|
from nhentai.parser import doujinshi_parser
|
||||||
|
from nhentai.doujinshi import Doujinshi
|
||||||
|
from nhentai.utils import generate_html, generate_cbz
|
||||||
|
|
||||||
|
|
||||||
|
class TestDownload(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
load_config()
|
||||||
|
constant.CONFIG['cookie'] = os.getenv('NHENTAI_COOKIE')
|
||||||
|
constant.CONFIG['useragent'] = os.getenv('NHENTAI_UA')
|
||||||
|
|
||||||
|
def test_download(self):
|
||||||
|
did = 440546
|
||||||
|
info = Doujinshi(**doujinshi_parser(did), name_format='%i')
|
||||||
|
info.downloader = Downloader(path='/tmp', size=5)
|
||||||
|
info.download()
|
||||||
|
|
||||||
|
self.assertTrue(os.path.exists(f'/tmp/{did}/001.jpg'))
|
||||||
|
|
||||||
|
generate_html('/tmp', info)
|
||||||
|
self.assertTrue(os.path.exists(f'/tmp/{did}/index.html'))
|
||||||
|
|
||||||
|
generate_cbz('/tmp', info)
|
||||||
|
self.assertTrue(os.path.exists(f'/tmp/{did}.cbz'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
26
tests/test_login.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
import urllib3.exceptions
|
||||||
|
|
||||||
|
from nhentai import constant
|
||||||
|
from nhentai.cmdline import load_config
|
||||||
|
from nhentai.utils import check_cookie
|
||||||
|
|
||||||
|
|
||||||
|
class TestLogin(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
load_config()
|
||||||
|
constant.CONFIG['cookie'] = os.getenv('NHENTAI_COOKIE')
|
||||||
|
constant.CONFIG['useragent'] = os.getenv('NHENTAI_UA')
|
||||||
|
|
||||||
|
def test_cookie(self):
|
||||||
|
try:
|
||||||
|
check_cookie()
|
||||||
|
self.assertTrue(True)
|
||||||
|
except Exception as e:
|
||||||
|
self.assertIsNone(e)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
27
tests/test_parser.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
import urllib3.exceptions
|
||||||
|
|
||||||
|
from nhentai import constant
|
||||||
|
from nhentai.cmdline import load_config
|
||||||
|
from nhentai.parser import search_parser, doujinshi_parser, favorites_parser
|
||||||
|
|
||||||
|
|
||||||
|
class TestParser(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||||
|
load_config()
|
||||||
|
constant.CONFIG['cookie'] = os.getenv('NHENTAI_COOKIE')
|
||||||
|
constant.CONFIG['useragent'] = os.getenv('NHENTAI_UA')
|
||||||
|
|
||||||
|
def test_search(self):
|
||||||
|
result = search_parser('umaru', 'recent', [1], False)
|
||||||
|
self.assertTrue(len(result) > 0)
|
||||||
|
|
||||||
|
def test_doujinshi_parser(self):
|
||||||
|
result = doujinshi_parser(123456)
|
||||||
|
self.assertTrue(result['pages'] == 84)
|
||||||
|
|
||||||
|
def test_favorites_parser(self):
|
||||||
|
result = favorites_parser(page=[1])
|
||||||
|
self.assertTrue(len(result) > 0)
|