mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
131 lines
3.7 KiB
Python
131 lines
3.7 KiB
Python
#!/usr/bin/env python2.7
|
|
# coding: utf-8
|
|
from __future__ import unicode_literals, print_function
|
|
import signal
|
|
import platform
|
|
import time
|
|
|
|
from nhentai.cmdline import cmd_parser, banner
|
|
from nhentai.parser import doujinshi_parser, search_parser, print_doujinshi, favorites_parser, tag_parser
|
|
from nhentai.doujinshi import Doujinshi
|
|
from nhentai.downloader import Downloader
|
|
from nhentai.logger import logger
|
|
from nhentai.constant import BASE_URL
|
|
from nhentai.utils import generate_html, generate_cbz, generate_main_html, check_cookie, signal_handler, DB
|
|
|
|
|
|
def main():
|
|
banner()
|
|
options = cmd_parser()
|
|
logger.info('Using mirror: {0}'.format(BASE_URL))
|
|
|
|
from nhentai.constant import PROXY
|
|
# constant.PROXY will be changed after cmd_parser()
|
|
if PROXY != {}:
|
|
logger.info('Using proxy: {0}'.format(PROXY))
|
|
|
|
# check your cookie
|
|
check_cookie()
|
|
|
|
index = 0
|
|
index_value = None
|
|
doujinshis = []
|
|
doujinshi_ids = []
|
|
doujinshi_list = []
|
|
|
|
if options.favorites:
|
|
if not options.is_download:
|
|
logger.warning('You do not specify --download option')
|
|
|
|
doujinshis = favorites_parser(options.page_range)
|
|
|
|
elif options.tag:
|
|
doujinshis = tag_parser(options.tag, sorting=options.sorting, max_page=options.max_page)
|
|
|
|
elif options.artist:
|
|
index = 1
|
|
index_value = options.artist
|
|
|
|
elif options.character:
|
|
index = 2
|
|
index_value = options.character
|
|
|
|
elif options.parody:
|
|
index = 3
|
|
index_value = options.parody
|
|
|
|
elif options.group:
|
|
index = 4
|
|
index_value = options.group
|
|
|
|
elif options.language:
|
|
index = 5
|
|
index_value = options.language
|
|
|
|
elif options.keyword:
|
|
doujinshis = search_parser(options.keyword, sorting=options.sorting, page=options.page)
|
|
|
|
elif not doujinshi_ids:
|
|
doujinshi_ids = options.id
|
|
|
|
if index:
|
|
doujinshis = tag_parser(index_value, max_page=options.max_page, index=index)
|
|
|
|
print_doujinshi(doujinshis)
|
|
if options.is_download and doujinshis:
|
|
doujinshi_ids = [i['id'] for i in doujinshis]
|
|
|
|
if options.is_save_download_history:
|
|
with DB() as db:
|
|
data = set(db.get_all())
|
|
|
|
doujinshi_ids = list(set(doujinshi_ids) - data)
|
|
|
|
if doujinshi_ids:
|
|
for i, id_ in enumerate(doujinshi_ids):
|
|
if options.delay:
|
|
time.sleep(options.delay)
|
|
|
|
doujinshi_info = doujinshi_parser(id_)
|
|
|
|
if doujinshi_info:
|
|
doujinshi_list.append(Doujinshi(name_format=options.name_format, **doujinshi_info))
|
|
|
|
if (i + 1) % 10 == 0:
|
|
logger.info('Progress: %d / %d' % (i + 1, len(doujinshi_ids)))
|
|
|
|
if not options.is_show:
|
|
downloader = Downloader(path=options.output_dir, size=options.threads,
|
|
timeout=options.timeout, delay=options.delay)
|
|
|
|
for doujinshi in doujinshi_list:
|
|
|
|
doujinshi.downloader = downloader
|
|
doujinshi.download()
|
|
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:
|
|
generate_html(options.output_dir, doujinshi)
|
|
elif options.is_cbz:
|
|
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
|
|
|
if options.main_viewer:
|
|
generate_main_html(options.output_dir)
|
|
|
|
if not platform.system() == 'Windows':
|
|
logger.log(15, '🍻 All done.')
|
|
else:
|
|
logger.log(15, 'All done.')
|
|
|
|
else:
|
|
[doujinshi.show() for doujinshi in doujinshi_list]
|
|
|
|
|
|
signal.signal(signal.SIGINT, signal_handler)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|