How to use the nhentai.logger.logger.info function in nhentai

To help you get started, we’ve selected a few nhentai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RicterZ / nhentai / nhentai / cmdline.py View on Github external
args, _ = parser.parse_args(sys.argv[1:])

    if args.html_viewer:
        generate_html()
        exit(0)

    if args.main_viewer and not args.id and not args.keyword and not args.favorites:
        generate_main_html()
        exit(0)

    if args.clean_download_history:
        with DB() as db:
            db.clean_all()

        logger.info('Download history cleaned.')
        exit(0)

    if os.path.exists(constant.NHENTAI_COOKIE):
        with open(constant.NHENTAI_COOKIE, 'r') as f:
            constant.COOKIE = f.read()

    if args.cookie:
        try:
            if not os.path.exists(constant.NHENTAI_HOME):
                os.mkdir(constant.NHENTAI_HOME)

            with open(constant.NHENTAI_COOKIE, 'w') as f:
                f.write(args.cookie)
        except Exception as e:
            logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
            exit(1)
github RicterZ / nhentai / nhentai / cmdline.py View on Github external
if args.proxy:
        try:
            if not os.path.exists(constant.NHENTAI_HOME):
                os.mkdir(constant.NHENTAI_HOME)

            proxy_url = urlparse(args.proxy)
            if proxy_url.scheme not in ('http', 'https'):
                logger.error('Invalid protocol \'{0}\' of proxy, ignored'.format(proxy_url.scheme))
            else:
                with open(os.path.join(constant.NHENTAI_HOME, 'proxy'), 'w') as f:
                    f.write(args.proxy)
        except Exception as e:
            logger.error('Cannot create NHENTAI_HOME: {}'.format(str(e)))
            exit(1)

        logger.info('Proxy \'{0}\' saved.'.format(args.proxy))
        exit(0)

    if args.favorites:
        if not constant.COOKIE:
            logger.warning('Cookie has not been set, please use `nhentai --cookie \'COOKIE\'` to set it.')
            exit(1)

    if args.id:
        _ = [i.strip() for i in args.id.split(',')]
        args.id = set(int(i) for i in _ if i.isdigit())

    if args.file:
        with open(args.file, 'r') as f:
            _ = [i.strip() for i in f.readlines()]
            args.id = set(int(i) for i in _ if i.isdigit())
github RicterZ / nhentai / nhentai / cmdline.py View on Github external
def banner():
    logger.info(u'''nHentai ver %s: あなたも変態。 いいね?
       _   _            _        _
 _ __ | | | | ___ _ __ | |_ __ _(_)
| '_ \| |_| |/ _ \ '_ \| __/ _` | |
| | | |  _  |  __/ | | | || (_| | |
|_| |_|_| |_|\___|_| |_|\__\__,_|_|
''' % __version__)
github RicterZ / nhentai / nhentai / utils.py View on Github external
<a style="padding:0 0 141.6% 0" class="cover" href="./{FOLDER}/index.html">\n\
                        <div class="caption">{TITLE}</div>\n\
                    </a>\n\
                \n\
            \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('Add doujinshi \'{}\''.format(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)
        if sys.version_info &lt; (3, 0):
github RicterZ / nhentai / nhentai / utils.py View on Github external
def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
    """Write images to a PDF file using img2pdf."""
    if doujinshi_obj is not None:
        doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
        pdf_filename = os.path.join(
            os.path.join(doujinshi_dir, '..'),
            '{}.pdf'.format(doujinshi_obj.filename)
        )
    else:
        pdf_filename = './doujinshi.pdf'
        doujinshi_dir = '.'

    file_list = os.listdir(doujinshi_dir)
    file_list.sort()

    logger.info('Writing PDF file to path: {}'.format(pdf_filename))
    with open(pdf_filename, 'wb') as pdf_f:
        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)

    logger.log(15, 'PDF file has been written to \'{0}\''.format(doujinshi_dir))
github RicterZ / nhentai / nhentai / doujinshi.py View on Github external
def show(self):
        table = [
            ["Doujinshi", self.name],
            ["Subtitle", self.info.subtitle],
            ["Characters", self.info.character],
            ["Authors", self.info.artists],
            ["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)))
github RicterZ / nhentai / nhentai / command.py View on Github external
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
    doujinshis = []
    doujinshi_ids = []
    doujinshi_list = []

    if options.favorites:
        if not options.is_download:
github RicterZ / nhentai / nhentai / utils.py View on Github external
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_comic_info=False):
    if doujinshi_obj is not None:
        doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
        if write_comic_info:
            serialize_comicxml(doujinshi_obj, doujinshi_dir)
        cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '{}.cbz'.format(doujinshi_obj.filename))
    else:
        cbz_filename = './doujinshi.cbz'
        doujinshi_dir = '.'

    file_list = os.listdir(doujinshi_dir)
    file_list.sort()

    logger.info('Writing CBZ file to path: {}'.format(cbz_filename))
    with zipfile.ZipFile(cbz_filename, 'w') as cbz_pf:
        for image in file_list:
            image_path = os.path.join(doujinshi_dir, image)
            cbz_pf.write(image_path, image)

    if rm_origin_dir:
        shutil.rmtree(doujinshi_dir, ignore_errors=True)

    logger.log(15, 'Comic Book CBZ file has been written to \'{0}\''.format(doujinshi_dir))
github RicterZ / nhentai / nhentai / parser.py View on Github external
if not count:
        logger.error("Can't get your number of favorited doujins. Did the login failed?")
        return []

    count = int(count.text.strip('(').strip(')').replace(',', ''))
    if count == 0:
        logger.warning('No favorites found')
        return []
    pages = int(count / 25)

    if pages:
        pages += 1 if count % (25 * pages) else 0
    else:
        pages = 1

    logger.info('You have %d favorites in %d pages.' % (count, pages))

    if os.getenv('DEBUG'):
        pages = 1

    page_range_list = range(1, pages + 1)
    if page_range:
        logger.info('page range is {0}'.format(page_range))
        page_range_list = page_range_parser(page_range, pages)

    for page in page_range_list:
        try:
            logger.info('Getting doujinshi ids of page %d' % page)
            resp = request('get', constant.FAV_URL + '?page=%d' % page).content

            result.extend(_get_title_and_id(resp))
        except Exception as e: