mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 11:01:17 +02:00
fix #220 add pretty name of doujinshi format
This commit is contained in:
parent
24be2d37d4
commit
19a1d5c404
@ -26,8 +26,10 @@ class DoujinshiInfo(dict):
|
|||||||
|
|
||||||
|
|
||||||
class Doujinshi(object):
|
class Doujinshi(object):
|
||||||
def __init__(self, name=None, id=None, img_id=None, ext='', pages=0, name_format='[%i][%a][%t]', **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
|
||||||
@ -39,6 +41,7 @@ class Doujinshi(object):
|
|||||||
name_format = name_format.replace('%i', str(self.id))
|
name_format = name_format.replace('%i', str(self.id))
|
||||||
name_format = name_format.replace('%a', self.info.artists)
|
name_format = name_format.replace('%a', self.info.artists)
|
||||||
name_format = name_format.replace('%t', self.name)
|
name_format = name_format.replace('%t', self.name)
|
||||||
|
name_format = name_format.replace('%p', self.pretty_name)
|
||||||
name_format = name_format.replace('%s', self.info.subtitle)
|
name_format = name_format.replace('%s', self.info.subtitle)
|
||||||
self.filename = format_filename(name_format)
|
self.filename = format_filename(name_format)
|
||||||
|
|
||||||
@ -63,7 +66,6 @@ class Doujinshi(object):
|
|||||||
logger.info('Starting to download doujinshi: %s' % self.name)
|
logger.info('Starting to download doujinshi: %s' % 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')
|
||||||
|
|
||||||
@ -71,12 +73,6 @@ class Doujinshi(object):
|
|||||||
download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext[i-1]))
|
download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i, self.ext[i-1]))
|
||||||
|
|
||||||
self.downloader.download(download_queue, self.filename)
|
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]]))
|
|
||||||
'''
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.critical('Downloader has not been loaded')
|
logger.critical('Downloader has not been loaded')
|
||||||
|
|
||||||
|
@ -133,13 +133,16 @@ def doujinshi_parser(id_):
|
|||||||
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|gif)$', 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'}):
|
||||||
|
@ -4,6 +4,7 @@ import os
|
|||||||
from xml.sax.saxutils import escape
|
from xml.sax.saxutils import escape
|
||||||
from nhentai.constant import LANGUAGEISO
|
from nhentai.constant import LANGUAGEISO
|
||||||
|
|
||||||
|
|
||||||
def serialize_json(doujinshi, dir):
|
def serialize_json(doujinshi, dir):
|
||||||
metadata = {'title': doujinshi.name,
|
metadata = {'title': doujinshi.name,
|
||||||
'subtitle': doujinshi.info.subtitle}
|
'subtitle': doujinshi.info.subtitle}
|
||||||
@ -26,10 +27,10 @@ def serialize_json(doujinshi, dir):
|
|||||||
metadata['Pages'] = doujinshi.pages
|
metadata['Pages'] = doujinshi.pages
|
||||||
|
|
||||||
with open(os.path.join(dir, 'metadata.json'), 'w') as f:
|
with open(os.path.join(dir, 'metadata.json'), 'w') as f:
|
||||||
json.dump(metadata, f, separators=','':')
|
json.dump(metadata, f, separators=(',', ':'))
|
||||||
|
|
||||||
|
|
||||||
def serialize_comicxml(doujinshi, dir):
|
def serialize_comic_xml(doujinshi, dir):
|
||||||
from iso8601 import parse_date
|
from iso8601 import parse_date
|
||||||
with open(os.path.join(dir, 'ComicInfo.xml'), 'w') as f:
|
with open(os.path.join(dir, 'ComicInfo.xml'), 'w') as f:
|
||||||
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||||
@ -45,7 +46,8 @@ def serialize_comicxml(doujinshi, dir):
|
|||||||
xml_write_simple_tag(f, 'NhentaiId', doujinshi.id)
|
xml_write_simple_tag(f, 'NhentaiId', doujinshi.id)
|
||||||
xml_write_simple_tag(f, 'Genre', doujinshi.info.categories)
|
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')
|
xml_write_simple_tag(f, 'BlackAndWhite', 'No' if doujinshi.info.tags and
|
||||||
|
'full color' in doujinshi.info.tags else 'Yes')
|
||||||
|
|
||||||
if doujinshi.info.date:
|
if doujinshi.info.date:
|
||||||
dt = parse_date(doujinshi.info.date)
|
dt = parse_date(doujinshi.info.date)
|
||||||
@ -59,13 +61,13 @@ def serialize_comicxml(doujinshi, dir):
|
|||||||
if doujinshi.info.tags:
|
if doujinshi.info.tags:
|
||||||
xml_write_simple_tag(f, 'Tags', doujinshi.info.tags)
|
xml_write_simple_tag(f, 'Tags', doujinshi.info.tags)
|
||||||
if doujinshi.info.artists:
|
if doujinshi.info.artists:
|
||||||
xml_write_simple_tag(f, 'Writer', ' & '.join([i.strip() for i in doujinshi.info.artists.split(',')]))
|
xml_write_simple_tag(f, 'Writer', ' & '.join([i.strip() for i in
|
||||||
# if doujinshi.info.groups:
|
doujinshi.info.artists.split(',')]))
|
||||||
# metadata['group'] = [i.strip() for i in doujinshi.info.groups.split(',')]
|
|
||||||
if doujinshi.info.languages:
|
if doujinshi.info.languages:
|
||||||
languages = [i.strip() for i in doujinshi.info.languages.split(',')]
|
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, 'Translated', 'Yes' if 'translated' in languages else 'No')
|
||||||
[xml_write_simple_tag(f, 'LanguageISO', LANGUAGEISO[i]) for i in languages \
|
[xml_write_simple_tag(f, 'LanguageISO', LANGUAGEISO[i]) for i in languages
|
||||||
if (i != 'translated' and i in LANGUAGEISO)]
|
if (i != 'translated' and i in LANGUAGEISO)]
|
||||||
|
|
||||||
f.write('</ComicInfo>')
|
f.write('</ComicInfo>')
|
||||||
@ -121,7 +123,7 @@ def serialize_unique(lst):
|
|||||||
def set_js_database():
|
def set_js_database():
|
||||||
with open('data.js', 'w') as f:
|
with open('data.js', 'w') as f:
|
||||||
indexed_json = merge_json()
|
indexed_json = merge_json()
|
||||||
unique_json = json.dumps(serialize_unique(indexed_json), separators=','':')
|
unique_json = json.dumps(serialize_unique(indexed_json), separators=(',', ':'))
|
||||||
indexed_json = json.dumps(indexed_json, separators=','':')
|
indexed_json = json.dumps(indexed_json, separators=(',', ':'))
|
||||||
f.write('var data = ' + indexed_json)
|
f.write('var data = ' + indexed_json)
|
||||||
f.write(';\nvar tags = ' + unique_json)
|
f.write(';\nvar tags = ' + unique_json)
|
||||||
|
@ -10,7 +10,7 @@ import sqlite3
|
|||||||
|
|
||||||
from nhentai import constant
|
from nhentai import constant
|
||||||
from nhentai.logger import logger
|
from nhentai.logger import logger
|
||||||
from nhentai.serializer import serialize_json, serialize_comicxml, set_js_database
|
from nhentai.serializer import serialize_json, serialize_comic_xml, set_js_database
|
||||||
|
|
||||||
|
|
||||||
def request(method, url, **kwargs):
|
def request(method, url, **kwargs):
|
||||||
@ -174,7 +174,7 @@ def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False, write_
|
|||||||
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)
|
||||||
if write_comic_info:
|
if write_comic_info:
|
||||||
serialize_comicxml(doujinshi_obj, doujinshi_dir)
|
serialize_comic_xml(doujinshi_obj, doujinshi_dir)
|
||||||
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '{}.cbz'.format(doujinshi_obj.filename))
|
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '{}.cbz'.format(doujinshi_obj.filename))
|
||||||
else:
|
else:
|
||||||
cbz_filename = './doujinshi.cbz'
|
cbz_filename = './doujinshi.cbz'
|
||||||
@ -246,7 +246,6 @@ def format_filename(s):
|
|||||||
ban_chars = '\\\'/:,;*?"<>|\t'
|
ban_chars = '\\\'/:,;*?"<>|\t'
|
||||||
filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars))).strip()
|
filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars))).strip()
|
||||||
filename = ' '.join(filename.split())
|
filename = ' '.join(filename.split())
|
||||||
print(repr(filename))
|
|
||||||
|
|
||||||
while filename.endswith('.'):
|
while filename.endswith('.'):
|
||||||
filename = filename[:-1]
|
filename = filename[:-1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user