mirror of
				https://github.com/RicterZ/nhentai.git
				synced 2025-11-04 02:50:55 +01:00 
			
		
		
		
	change output filename
This commit is contained in:
		@@ -17,6 +17,7 @@ EXT_MAP = {
 | 
			
		||||
 | 
			
		||||
class DoujinshiInfo(dict):
 | 
			
		||||
    def __init__(self, **kwargs):
 | 
			
		||||
        print(kwargs)
 | 
			
		||||
        super(DoujinshiInfo, self).__init__(**kwargs)
 | 
			
		||||
 | 
			
		||||
    def __getattr__(self, item):
 | 
			
		||||
@@ -36,6 +37,7 @@ class Doujinshi(object):
 | 
			
		||||
        self.downloader = None
 | 
			
		||||
        self.url = '%s/%d' % (DETAIL_URL, self.id)
 | 
			
		||||
        self.info = DoujinshiInfo(**kwargs)
 | 
			
		||||
        self.filename = format_filename('[%s][%s][%s]' % (self.id, self.info.artist, self.name))
 | 
			
		||||
 | 
			
		||||
    def __repr__(self):
 | 
			
		||||
        return '<Doujinshi: {0}>'.format(self.name)
 | 
			
		||||
@@ -44,10 +46,10 @@ class Doujinshi(object):
 | 
			
		||||
        table = [
 | 
			
		||||
            ["Doujinshi", self.name],
 | 
			
		||||
            ["Subtitle", self.info.subtitle],
 | 
			
		||||
            ["Characters", self.info.characters],
 | 
			
		||||
            ["Authors", self.info.artists],
 | 
			
		||||
            ["Characters", self.info.character],
 | 
			
		||||
            ["Authors", self.info.artist],
 | 
			
		||||
            ["Language", self.info.language],
 | 
			
		||||
            ["Tags", self.info.tags],
 | 
			
		||||
            ["Tags", ', '.join(self.info.tag.keys())],
 | 
			
		||||
            ["URL", self.url],
 | 
			
		||||
            ["Pages", self.pages],
 | 
			
		||||
        ]
 | 
			
		||||
@@ -59,8 +61,7 @@ class Doujinshi(object):
 | 
			
		||||
            download_queue = []
 | 
			
		||||
            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]]))
 | 
			
		||||
 | 
			
		||||
            self.downloader.download(download_queue, format_filename('%s-%s' % (self.id, self.name[:200])))
 | 
			
		||||
                self.downloader.download(download_queue, self.filename)
 | 
			
		||||
        else:
 | 
			
		||||
            logger.critical('Downloader has not been loaded')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@ class Downloader(Singleton):
 | 
			
		||||
        self.path = str(path)
 | 
			
		||||
        self.thread_count = thread
 | 
			
		||||
        self.threads = []
 | 
			
		||||
        self.thread_pool = None
 | 
			
		||||
        self.timeout = timeout
 | 
			
		||||
 | 
			
		||||
    def _download(self, url, folder='', filename='', retried=0):
 | 
			
		||||
 
 | 
			
		||||
@@ -130,7 +130,7 @@ def doujinshi_parser(id_):
 | 
			
		||||
            elif tag_type not in doujinshi:
 | 
			
		||||
                doujinshi[tag_type] = tag['name']
 | 
			
		||||
            else:
 | 
			
		||||
                doujinshi[tag_type] += tag['name']
 | 
			
		||||
                doujinshi[tag_type] += ', ' + tag['name']
 | 
			
		||||
 | 
			
		||||
    return doujinshi
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -43,8 +43,7 @@ def generate_html(output_dir='.', doujinshi_obj=None):
 | 
			
		||||
    image_html = ''
 | 
			
		||||
 | 
			
		||||
    if doujinshi_obj is not None:
 | 
			
		||||
        doujinshi_dir = os.path.join(output_dir, format_filename('%s-%s' % (doujinshi_obj.id,
 | 
			
		||||
                                                                            doujinshi_obj.name)))
 | 
			
		||||
        doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
 | 
			
		||||
    else:
 | 
			
		||||
        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):
 | 
			
		||||
    if doujinshi_obj is not None:
 | 
			
		||||
        doujinshi_dir = os.path.join(output_dir, format_filename('%s-%s' % (doujinshi_obj.id,
 | 
			
		||||
                                                                            doujinshi_obj.name)))
 | 
			
		||||
        doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
 | 
			
		||||
        cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id)
 | 
			
		||||
    else:
 | 
			
		||||
        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.
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
    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 = filename.replace(' ', '_')  # I don't like spaces in filenames.
 | 
			
		||||
    if len(filename) > 100:
 | 
			
		||||
        filename = filename[:100]
 | 
			
		||||
        filename = filename[:100] + '...]'
 | 
			
		||||
    return filename
 | 
			
		||||
 
 | 
			
		||||
@@ -3,4 +3,3 @@ BeautifulSoup4>=4.0.0
 | 
			
		||||
threadpool>=1.2.7
 | 
			
		||||
tabulate>=0.7.5
 | 
			
		||||
future>=0.15.2
 | 
			
		||||
threadpool==1.3.2
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user