downloads hentai from nhentai.net and converts to CBZ
downloads hentai from nhentai.net and converts to CBZ
[!IMPORTANT] If you have any questions, please consult the readme first.
I spend a lot of effort to keep the readme up-to-date and chances are high that your problem has already been addressed here. If you still require assistance after reading the readme, post it publicly, preferably as a GitHub issue, so others can benefit from the troubleshooting as well.
nHentai Archivist is a tool to download hentai from https://nhentai.net and convert them to CBZ files. From quickly downloading a few hentai specified in the console, downloading a few hundred hentai specified in a downloadme.txt, up to automatically keeping a massive self-hosted library up-to-date by automatically generating a downloadme.txt from a search by tag. (For that use-case it has been optimised to tag the CBZ files in a way that Komga in oneshot mode interprets everything correctly.)
Why CBZ? CBZ is a widespread standard and basically just a ZIP file containing the images and a metadata file. This enables nHentai Archivist to keep the tags which wouldn't be possible with PDF as far as I know.
Big thanks go out to h3nTa1m4st3r_xx69, who helped me with using nHentai's completely undocumented API. Without him this project could not have been reactivated. I'm happy about anyone who finds my software useful and feedback is also always welcome. Happy downloading~
./config/.env../config/.env.USER_AGENT to your system's specific user agent. You can go to https://www.whatismybrowser.com/detect/ and copy your user agent into there.CIRCUMVENT_LOAD_BALANCER, optional, defaults to false
Setting this to true circumvents the load balancer at i.nhentai.net and directly uses a random media server, for example i2.nhentai.net. Only use this if the load balancer is broken. You can confirm this by setting DEBUG = true and checking the logs for consistent download errors when using i.nhentai.net and success when using a specific media server like i2.nhentai.net.
CLEANUP_TEMPORARY_FILES, optional, defaults to true
Setting this to false prevents the temporary directory containing the original images from being deleted after the CBZ file has been created. In addition to that it also saves a ComicBook.xml in the directory. This can be useful to improve compatibility with third party readers or deduplication software.
DONTDOWNLOADME_FILEPATH, optional, defaults to None
This is the path to the file containing the nHentai ID you explicitly do not want to download, separated by line breaks. It has priority over all input methods. If you want to systematically exclude hentai by tag, use the - operator in the tag search instead.
DOWNLOAD_WORKERS, optional, defaults to $5$
This sets the number of download workers for parallel image downloads. More does not always mean faster! $5$ usually is a good balance between overhead and bandwidth usage.
If you had to set CIRCUMVENT_LOAD_BALANCER = true because the load balancer is broken, you are randomly trying out media servers directly if they happen to have the image, which will result in a lot of download errors. In this case it might make sense to set this to a higher value like $10$, because a lot of time is wasted waiting for timeouts of download requests to expire.
DOWNLOADME_FILEPATH, optional, defaults to None
This is the path to the file containing the nHentai ID you want to download, separated by line breaks. If this file exists, it has priority over tag search and console input.
FILENAME_TITLE_TYPE, optional, defaults to English
Determines which title type to use when naming downloaded hentai files. Available settings:
EnglishJapanesePrettyIf a Japanese or pretty title is not available, the English title will be used instead.
[!IMPORTANT] If
FILENAME_TITLE_TYPEis changed after hentai files have already been downloaded, existing files will not be renamed. They also will not be detected as already downloaded any more which can lead to duplicates. I therefore recommend to only change this setting before starting a fresh library.
LIBRARY_PATH
This is the directory temporary images and finished CBZ files are download to. By default, it will download to ./hentai/.
LIBRARY_SPLIT, optional, defaults to 0
Setting this to a value other than 0 splits the library at LIBRARY_PATH into sub-directories with a maximum number of LIBRARY_SPLIT hentai allowed per sub-directory. It is recommended if the number of hentai in 1 directory starts to affect file explorer performance. This should not affect you if you plan to keep less than 10.000 files in your LIBRARY_PATH directory, otherwise the recommended setting is LIBRARY_SPLIT = 10000.
NHENTAI_TAGS, optional, defaults to None (client mode)
Setting this will trigger "server mode". If no file at DOWNLOADME_FILEPATH is found, it will generate one by searching for the tags specified. After all hentai on the downloadme have been downloaded, it will wait for SLEEP_INTERVAL seconds and restart the search. This is useful to keep a self-hosted library up-to-date with the latest releases from the specified tag search. Multiple tags and tag exclusions can be specified and are connected via logical AND. This means results must fullfill all criteria specified.
./config/.env examples:
…`docker-compose.yaml` examples:…Pay attention to copy the format exactly as shown in the examples. That includes the usage of single quotation marks outside and double quotation marks inside. If the format is not being copied exactly, at least searching by tags that contain a space leads to erroneous API responses. More information can be found [here](https://nhentai.net/info/).
The docker compose method can be especially useful if altering quickly between searches, or configs in general, is desired. Just define a `docker-compose.yaml` for each config and then simply spinning down and up stacks is all that is needed to switch between them.[!WARNING] I advise against running multiple instances of nHentai Archivist at the same time.
NHENTAI_TAGS and make sure there is no file at DOWNLOADME_FILEPATH.Example ./config/.env:
LIBRARY_PATH = "./hentai/"NHENTAI_TAGS.DOWNLOADME_FILEPATH and create a file there.Example ./config/.env:
DONTDOWNLOADME_FILEPATH = "./config/dontdownloadme.txt"
DOWNLOADME_FILEPATH = "./config/downloadme.txt"
LIBRARY_PATH = "./hentai/"
USER_AGENT = "your user agent here"NHENTAI_TAGS to define the tag search that you want to use to keep your library up-to-date.DOWNLOADME_FILEPATH but ensure there is no file actually there, otherwise it will be downloaded first.LIBRARY_SPLIT to a value other than 0 if you plan to keep more than 10.000 files in your LIBRARY_PATH directory.SLEEP_INTERVAL to wait a bit between searches. I recommend a value of at least 50.000.Example ./config/.env:
DONTDOWNLOADME_FILEPATH = "./config/dontdownloadme.txt"
DOWNLOADME_FILEPATH = "./config/downloadme.txt"
LIBRARY_PATH = "./hentai/"
LIBRARY_SPLIT = 10000
NHENTAI_TAGS = ['language:"english"']
SLEEP_INTERVAL = 50000
USER_AGENT = "your user agent here"nHentai Archivist is not connected to your nHentai account in any way. Automatically generating a downloadme.txt from your list of favourites is beyond the scope of this tool. However, once you compiled your favourites as a list of ID separated by line breaks, nHentai Archivist can take over. Other users were quick to automate this process, I have linked a few of the provided solutions:
[!CAUTION] I have not tested any of these scripts. I am linking them in good faith and rely on the feedback of the community.
Searching by tags / downloading metadata often results in error 404 on seemingly random pages.
This behaviour is consistent even when the URL is opened by a browser, so I assume the problem to be on nHentai's side. Just ignore the warnings and let nHentai Archivist search and download multiple times to get everything reliably, ideally with a SLEEP_INTERVAL of at least 50.000 so searches are guaranteed to be far enough apart. After a few runs, you will notice all but the newest hentai being skipped during the download phase. That's when you know you got everything. See issue #3.
Seems to have been fixed upstream 2024-10-30.
nHentai contains a lot of duplicates.
There is currently no way to filter them out. Setting CLEANUP_TEMPORARY_FILES has been added to improve interoperability with third party deduplication software. See issue #6.
The nHentai search API does not match whole words only; or at least I can't figure out how. For example, searching the artist "mana" will download "mana-ko" and "aoi manabu", everything with mana in it. This does not affect (normal) tags as far as I have experienced.
I recommend to always double check your NHENTAI_TAGS with a search on nhentai.net. See issue #10.
Multiple tag searches can not be combined via logical OR.
The current workaround is to have multiple docker-compose.yaml each defining a different search by defining NHENTAI_TAGS in their environment section and then playing round robin with the container that is being used. See issue #11.
I have upgraded from an older version and now nHentai Archivist complains about missing or invalid settings.
Either follow the error message's instructions and manually make the necessary changes or delete ./config/.env and execute the program once to create a new default one.
I have upgraded from an older version to version 3.8.0 or newer and now nHentai Archivist raises database errors (code 1).
This is due to me adding migrations to the database which enables me to change the database schema in the future without you having to do anything yourself. This is my very first project that utilises a proper database which is why I haven't utilised migrations from the start, I apologise for the hassle. To fix the error either add the migrations entry manually to the
No open issues yet, or sync has not completed.