From 5592b30be4382efa220e7637aff9814a4039b27a Mon Sep 17 00:00:00 2001 From: Ricter Z Date: Wed, 23 Nov 2016 22:11:47 +0800 Subject: [PATCH] do not download 404 --- nhentai/cmdline.py | 9 ++++++--- nhentai/downloader.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 7621715..624b9ab 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -30,9 +30,12 @@ def banner(): def cmd_parser(): - parser = OptionParser() - parser.add_option('--download', dest='is_download', action='store_true', help='download doujinshi or not') - parser.add_option('--show-info', dest='is_show', action='store_true', help='just show the doujinshi information.') + parser = OptionParser('\nnhentai --search [keyword] --download' + '\nNHENTAI=http://h.loli.club nhentai --id [ID ...]' + '\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('--search', type='string', dest='keyword', action='store', help='search doujinshi by keyword') parser.add_option('--page', type='int', dest='page', action='store', default=1, diff --git a/nhentai/downloader.py b/nhentai/downloader.py index c46c5e6..737a409 100644 --- a/nhentai/downloader.py +++ b/nhentai/downloader.py @@ -31,6 +31,8 @@ class Downloader(Singleton): try: with open(os.path.join(folder, base_filename.zfill(3) + extension), "wb") as f: 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') if length is None: f.write(response.content)