do not download 404

This commit is contained in:
Ricter Z 2016-11-23 22:11:47 +08:00
parent 12f7b2225b
commit 5592b30be4
2 changed files with 8 additions and 3 deletions

View File

@ -30,9 +30,12 @@ def banner():
def cmd_parser(): def cmd_parser():
parser = OptionParser() parser = OptionParser('\nnhentai --search [keyword] --download'
parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not') '\nNHENTAI=http://h.loli.club nhentai --id [ID ...]'
parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information.') '\n\nEnvironment Variable:\n'
'NHENTAI nhentai mirror url')
parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi (for search result)')
parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information')
parser.add_option('--id', type='string', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3') parser.add_option('--id', type='string', dest='id', action='store', help='doujinshi ids set, e.g. 1,2,3')
parser.add_option('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword') parser.add_option('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword')
parser.add_option('--page', type='int', dest='page', action='store', default=1, parser.add_option('--page', type='int', dest='page', action='store', default=1,

View File

@ -31,6 +31,8 @@ class Downloader(Singleton):
try: try:
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:
response = request('get', url, stream=True, timeout=self.timeout) response = request('get', url, stream=True, timeout=self.timeout)
if response.status_code != 200:
logger.warning('Warning: url: {} return status code 404'.format(url))
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)