mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-07-02 00:19:29 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
eb6df28fba | |||
1091ea3e0a | |||
0df51c83e5 | |||
c5fa98ebd1 | |||
3154a94c3d | |||
c47018251f | |||
74d0499092 | |||
7e56d9b901 | |||
8cbb334d36 | |||
db6d45efe0 | |||
d412794bce | |||
8eedbf077b | |||
c95ecdded4 |
@ -14,5 +14,6 @@ install:
|
|||||||
script:
|
script:
|
||||||
- NHENTAI=https://nhentai.net nhentai --search umaru
|
- NHENTAI=https://nhentai.net nhentai --search umaru
|
||||||
- NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/
|
- NHENTAI=https://nhentai.net nhentai --id=152503,146134 -t 10 --output=/tmp/
|
||||||
- NHENTAI=https://nhentai.net nhentai -l nhentai_test:nhentai --output=/tmp/
|
- NHENTAI=https://nhentai.net nhentai -l nhentai_test:nhentai --download --output=/tmp/
|
||||||
- NHENTAI=https://nhentai.net nhentai --tag lolicon
|
- NHENTAI=https://nhentai.net nhentai --tag lolicon
|
||||||
|
- NHENTAI=https://nhentai.net nhentai --id 92066 --output=/tmp/ --cbz
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
__version__ = '0.2.16'
|
__version__ = '0.2.19'
|
||||||
__author__ = 'RicterZ'
|
__author__ = 'RicterZ'
|
||||||
__email__ = 'ricterzheng@gmail.com'
|
__email__ = 'ricterzheng@gmail.com'
|
||||||
|
@ -68,6 +68,8 @@ def cmd_parser():
|
|||||||
|
|
||||||
parser.add_option('--cbz', dest='is_cbz', action='store_true',
|
parser.add_option('--cbz', dest='is_cbz', action='store_true',
|
||||||
help='Generate Comic Book CBZ File')
|
help='Generate Comic Book CBZ File')
|
||||||
|
parser.add_option('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
|
||||||
|
help='Remove downloaded doujinshi dir when generated CBZ file.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sys.argv = list(map(lambda x: unicode(x.decode(sys.stdin.encoding)), sys.argv))
|
sys.argv = list(map(lambda x: unicode(x.decode(sys.stdin.encoding)), sys.argv))
|
||||||
|
@ -21,8 +21,6 @@ def main():
|
|||||||
doujinshi_ids = []
|
doujinshi_ids = []
|
||||||
doujinshi_list = []
|
doujinshi_list = []
|
||||||
|
|
||||||
import pdb; pdb.set_trace()
|
|
||||||
|
|
||||||
if options.login:
|
if options.login:
|
||||||
username, password = options.login.split(':', 1)
|
username, password = options.login.split(':', 1)
|
||||||
logger.info('Logging in to nhentai using credential pair \'%s:%s\'' % (username, '*' * len(password)))
|
logger.info('Logging in to nhentai using credential pair \'%s:%s\'' % (username, '*' * len(password)))
|
||||||
@ -61,7 +59,7 @@ def main():
|
|||||||
if not options.is_nohtml and not options.is_cbz:
|
if not options.is_nohtml and not options.is_cbz:
|
||||||
generate_html(options.output_dir, doujinshi)
|
generate_html(options.output_dir, doujinshi)
|
||||||
elif options.is_cbz:
|
elif options.is_cbz:
|
||||||
generate_cbz(options.output_dir, doujinshi)
|
generate_cbz(options.output_dir, doujinshi, options.rm_origin_dir)
|
||||||
|
|
||||||
if not platform.system() == 'Windows':
|
if not platform.system() == 'Windows':
|
||||||
logger.log(15, '🍻 All done.')
|
logger.log(15, '🍻 All done.')
|
||||||
|
@ -36,6 +36,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 +45,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 +60,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):
|
||||||
@ -41,20 +42,27 @@ class Downloader(Singleton):
|
|||||||
extension)))
|
extension)))
|
||||||
return 1, url
|
return 1, url
|
||||||
|
|
||||||
|
response = None
|
||||||
with open(os.path.join(folder, base_filename.zfill(3) + extension), "wb") as f:
|
with open(os.path.join(folder, base_filename.zfill(3) + extension), "wb") as f:
|
||||||
i=0
|
i = 0
|
||||||
while i<10:
|
while i < 10:
|
||||||
try:
|
try:
|
||||||
response = request('get', url, stream=True, timeout=self.timeout)
|
response = request('get', url, stream=True, timeout=self.timeout)
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise NhentaiImageNotExistException
|
||||||
|
|
||||||
|
except NhentaiImageNotExistException as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
i+=1
|
i += 1
|
||||||
if not i<10:
|
if not i < 10:
|
||||||
logger.critical(str(e))
|
logger.critical(str(e))
|
||||||
return 0, None
|
return 0, None
|
||||||
continue
|
continue
|
||||||
|
|
||||||
break
|
break
|
||||||
if response.status_code != 200:
|
|
||||||
raise NhentaiImageNotExistException
|
|
||||||
length = response.headers.get('content-length')
|
length = response.headers.get('content-length')
|
||||||
if length is None:
|
if length is None:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
|
@ -50,7 +50,7 @@ def login_parser(username, password):
|
|||||||
if not count:
|
if not count:
|
||||||
logger.error("Can't get your number of favorited doujins. Did the login failed?")
|
logger.error("Can't get your number of favorited doujins. Did the login failed?")
|
||||||
|
|
||||||
count = int(count.text.strip('(').strip(')'))
|
count = int(count.text.strip('(').strip(')').replace(',', ''))
|
||||||
if count == 0:
|
if count == 0:
|
||||||
logger.warning('No favorites found')
|
logger.warning('No favorites found')
|
||||||
return []
|
return []
|
||||||
@ -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 = '.'
|
||||||
|
|
||||||
@ -83,12 +82,10 @@ def generate_html(output_dir='.', doujinshi_obj=None):
|
|||||||
logger.warning('Writen HTML Viewer failed ({})'.format(str(e)))
|
logger.warning('Writen HTML Viewer failed ({})'.format(str(e)))
|
||||||
|
|
||||||
|
|
||||||
def generate_cbz(output_dir='.', doujinshi_obj=None):
|
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)
|
||||||
str(doujinshi_obj.name[:200]))))
|
cbz_filename = os.path.join(os.path.join(doujinshi_dir, '..'), '%s.cbz' % doujinshi_obj.id)
|
||||||
cbz_filename = os.path.join(output_dir, format_filename('%s-%s.cbz' % (doujinshi_obj.id,
|
|
||||||
str(doujinshi_obj.name[:200]))))
|
|
||||||
else:
|
else:
|
||||||
cbz_filename = './doujinshi.cbz'
|
cbz_filename = './doujinshi.cbz'
|
||||||
doujinshi_dir = '.'
|
doujinshi_dir = '.'
|
||||||
@ -96,20 +93,18 @@ def generate_cbz(output_dir='.', doujinshi_obj=None):
|
|||||||
file_list = os.listdir(doujinshi_dir)
|
file_list = os.listdir(doujinshi_dir)
|
||||||
file_list.sort()
|
file_list.sort()
|
||||||
|
|
||||||
|
logger.info('Writing CBZ file to path: {}'.format(cbz_filename))
|
||||||
with zipfile.ZipFile(cbz_filename, 'w') as cbz_pf:
|
with zipfile.ZipFile(cbz_filename, 'w') as cbz_pf:
|
||||||
for image in file_list:
|
for image in file_list:
|
||||||
image_path = os.path.join(doujinshi_dir, image)
|
image_path = os.path.join(doujinshi_dir, image)
|
||||||
cbz_pf.write(image_path, image)
|
cbz_pf.write(image_path, image)
|
||||||
|
|
||||||
|
if rm_origin_dir:
|
||||||
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
shutil.rmtree(doujinshi_dir, ignore_errors=True)
|
||||||
|
|
||||||
logger.log(15, 'Comic Book CBZ file has been write to \'{0}\''.format(doujinshi_dir))
|
logger.log(15, 'Comic Book CBZ file has been write to \'{0}\''.format(doujinshi_dir))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def format_filename(s):
|
def format_filename(s):
|
||||||
"""Take a string and return a valid filename constructed from the string.
|
"""Take a string and return a valid filename constructed from the string.
|
||||||
Uses a whitelist approach: any characters not present in valid_chars are
|
Uses a whitelist approach: any characters not present in valid_chars are
|
||||||
@ -121,7 +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:
|
||||||
|
filename = filename[:100] + '...]'
|
||||||
return filename
|
return filename
|
||||||
|
@ -2,4 +2,4 @@ requests>=2.5.0
|
|||||||
BeautifulSoup4>=4.0.0
|
BeautifulSoup4>=4.0.0
|
||||||
threadpool>=1.2.7
|
threadpool>=1.2.7
|
||||||
tabulate>=0.7.5
|
tabulate>=0.7.5
|
||||||
future>=0.15.2threadpool==1.3.2
|
future>=0.15.2
|
||||||
|
Reference in New Issue
Block a user