mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 02:41:19 +02:00
change output filename
This commit is contained in:
parent
c5fa98ebd1
commit
0df51c83e5
@ -17,6 +17,7 @@ EXT_MAP = {
|
|||||||
|
|
||||||
class DoujinshiInfo(dict):
|
class DoujinshiInfo(dict):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
print(kwargs)
|
||||||
super(DoujinshiInfo, self).__init__(**kwargs)
|
super(DoujinshiInfo, self).__init__(**kwargs)
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
@ -36,6 +37,7 @@ class Doujinshi(object):
|
|||||||
self.downloader = None
|
self.downloader = None
|
||||||
self.url = '%s/%d' % (DETAIL_URL, self.id)
|
self.url = '%s/%d' % (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))
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<Doujinshi: {0}>'.format(self.name)
|
return '<Doujinshi: {0}>'.format(self.name)
|
||||||
@ -44,10 +46,10 @@ class Doujinshi(object):
|
|||||||
table = [
|
table = [
|
||||||
["Doujinshi", self.name],
|
["Doujinshi", self.name],
|
||||||
["Subtitle", self.info.subtitle],
|
["Subtitle", self.info.subtitle],
|
||||||
["Characters", self.info.characters],
|
["Characters", self.info.character],
|
||||||
["Authors", self.info.artists],
|
["Authors", self.info.artist],
|
||||||
["Language", self.info.language],
|
["Language", self.info.language],
|
||||||
["Tags", self.info.tags],
|
["Tags", ', '.join(self.info.tag.keys())],
|
||||||
["URL", self.url],
|
["URL", self.url],
|
||||||
["Pages", self.pages],
|
["Pages", self.pages],
|
||||||
]
|
]
|
||||||
@ -59,8 +61,7 @@ class Doujinshi(object):
|
|||||||
download_queue = []
|
download_queue = []
|
||||||
for i in range(len(self.ext)):
|
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]]))
|
download_queue.append('%s/%d/%d.%s' % (IMAGE_URL, int(self.img_id), i+1, EXT_MAP[self.ext[i]]))
|
||||||
|
self.downloader.download(download_queue, self.filename)
|
||||||
self.downloader.download(download_queue, format_filename('%s-%s' % (self.id, self.name[:200])))
|
|
||||||
else:
|
else:
|
||||||
logger.critical('Downloader has not been loaded')
|
logger.critical('Downloader has not been loaded')
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ class Downloader(Singleton):
|
|||||||
self.path = str(path)
|
self.path = str(path)
|
||||||
self.thread_count = thread
|
self.thread_count = thread
|
||||||
self.threads = []
|
self.threads = []
|
||||||
|
self.thread_pool = None
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
def _download(self, url, folder='', filename='', retried=0):
|
def _download(self, url, folder='', filename='', retried=0):
|
||||||
|
@ -130,7 +130,7 @@ def doujinshi_parser(id_):
|
|||||||
elif tag_type not in doujinshi:
|
elif tag_type not in doujinshi:
|
||||||
doujinshi[tag_type] = tag['name']
|
doujinshi[tag_type] = tag['name']
|
||||||
else:
|
else:
|
||||||
doujinshi[tag_type] += tag['name']
|
doujinshi[tag_type] += ', ' + tag['name']
|
||||||
|
|
||||||
return doujinshi
|
return doujinshi
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
|||||||
image_html = ''
|
image_html = ''
|
||||||
|
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
doujinshi_dir = os.path.join(output_dir, format_filename('%s-%s' % (doujinshi_obj.id,
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
doujinshi_obj.name)))
|
|
||||||
else:
|
else:
|
||||||
doujinshi_dir = '.'
|
doujinshi_dir = '.'
|
||||||
|
|
||||||
@ -85,8 +84,7 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
|||||||
|
|
||||||
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
def generate_cbz(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
|
||||||
if doujinshi_obj is not None:
|
if doujinshi_obj is not None:
|
||||||
doujinshi_dir = os.path.join(output_dir, format_filename('%s-%s' % (doujinshi_obj.id,
|
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||||
doujinshi_obj.name)))
|
|
||||||
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id)
|
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id)
|
||||||
else:
|
else:
|
||||||
cbz_filename = './doujinshi.cbz'
|
cbz_filename = './doujinshi.cbz'
|
||||||
@ -118,9 +116,9 @@ and append a file extension like '.txt', so I avoid the potential of using
|
|||||||
an invalid filename.
|
an invalid filename.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
valid_chars = "-_.()[] %s%s" % (string.ascii_letters, string.digits)
|
||||||
filename = ''.join(c for c in s if c in valid_chars)
|
filename = ''.join(c for c in s if c in valid_chars)
|
||||||
filename = filename.replace(' ', '_') # I don't like spaces in filenames.
|
filename = filename.replace(' ', '_') # I don't like spaces in filenames.
|
||||||
if len(filename) > 100:
|
if len(filename) > 100:
|
||||||
filename = filename[:100]
|
filename = filename[:100] + '...]'
|
||||||
return filename
|
return filename
|
||||||
|
@ -3,4 +3,3 @@ BeautifulSoup4>=4.0.0
|
|||||||
threadpool>=1.2.7
|
threadpool>=1.2.7
|
||||||
tabulate>=0.7.5
|
tabulate>=0.7.5
|
||||||
future>=0.15.2
|
future>=0.15.2
|
||||||
threadpool==1.3.2
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user