From ba6d4047e21b5d7dea8b062d3d5d70578d025229 Mon Sep 17 00:00:00 2001 From: reynog <59975438+reynog@users.noreply.github.com> Date: Thu, 16 Jan 2020 20:12:27 +0100 Subject: [PATCH 1/3] Larger image display Bodged file edit. Changed image to extend off the screen, and be scrollable. Easier to read speech and other text on smaller displays. Moved page counter to top center. Not quite as nice looking. --- nhentai/viewer/styles.css | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nhentai/viewer/styles.css b/nhentai/viewer/styles.css index f9830dc..132bded 100644 --- a/nhentai/viewer/styles.css +++ b/nhentai/viewer/styles.css @@ -17,8 +17,8 @@ html, body { } #list { - height: 100%; - overflow: auto; + height: 2000px; + overflow: scroll; width: 260px; text-align: center; } @@ -37,7 +37,7 @@ html, body { #image-container { flex: auto; - height: 100vh; + height: 2000px; background: #222; color: #fff; text-align: center; @@ -48,16 +48,16 @@ html, body { } #image-container #dest { - height: 100%; + height: 2000px; width: 100%; background-size: contain; background-repeat: no-repeat; - background-position: center; + background-position: top; } #image-container #page-num { - position: absolute; - font-size: 18pt; + position: static; + font-size: 14pt; left: 10px; bottom: 5px; font-weight: bold; @@ -66,4 +66,4 @@ html, body { 0 0 2px #222, 0 0 2px #222, 0 0 2px #222; -} \ No newline at end of file +} From 53e1923e67c64469eb7d1c09888c3f57c21b27dc Mon Sep 17 00:00:00 2001 From: reynog <59975438+reynog@users.noreply.github.com> Date: Thu, 16 Jan 2020 20:20:42 +0100 Subject: [PATCH 2/3] Changed keyboard nav In conjunction with styles.css change, changed W, and S keys to scroll image vertically and removed page change from Up and Down, leaving A, D, Left, and Right as keys for changing page. Page returns to the top when changing page. W and S scroll behavior is not smooth. Up and Down scroll relies on browser's in-built keyboard scrolling functionality. --- nhentai/viewer/scripts.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nhentai/viewer/scripts.js b/nhentai/viewer/scripts.js index 8e3f8bf..9045258 100644 --- a/nhentai/viewer/scripts.js +++ b/nhentai/viewer/scripts.js @@ -17,6 +17,8 @@ function changePage(pageNum) { const display = document.getElementById('dest'); display.style.backgroundImage = `url("${current.src}")`; + scroll(0,0) + document.getElementById('page-num') .innerText = [ (pageNum + 1).toLocaleString(), @@ -47,6 +49,8 @@ document.onkeypress = event => { switch (event.key.toLowerCase()) { // Previous Image case 'w': + scrollBy(0, -40); + break; case 'a': changePage(currentPage - 1); break; @@ -57,6 +61,8 @@ document.onkeypress = event => { // Next Image case ' ': case 's': + scrollBy(0, 40); + break; case 'd': changePage(currentPage + 1); break; @@ -69,13 +75,11 @@ document.onkeydown = event =>{ changePage(currentPage - 1); break; case 38: //up - changePage(currentPage - 1); break; case 39: //right changePage(currentPage + 1); break; case 40: //down - changePage(currentPage + 1); break; } -}; \ No newline at end of file +}; From 43a9b981ddc92c5f06be84b83898eb9dd6973697 Mon Sep 17 00:00:00 2001 From: myzWILLmake Date: Fri, 7 Feb 2020 01:32:51 +0800 Subject: [PATCH 3/3] add page_range option for favorites --- nhentai/cmdline.py | 2 ++ nhentai/command.py | 2 +- nhentai/parser.py | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/nhentai/cmdline.py b/nhentai/cmdline.py index 10f5ecd..f8e7679 100644 --- a/nhentai/cmdline.py +++ b/nhentai/cmdline.py @@ -63,6 +63,8 @@ def cmd_parser(): help='page number of search results') parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1, help='The max page when recursive download tagged doujinshi') + parser.add_option('--page-range', type='string', dest='page_range', action='store', + help='page range of favorites. e.g. 1,2-5,14') parser.add_option('--sorting', dest='sorting', action='store', default='date', help='sorting of doujinshi (date / popular)', choices=['date', 'popular']) diff --git a/nhentai/command.py b/nhentai/command.py index 8009351..deb9071 100644 --- a/nhentai/command.py +++ b/nhentai/command.py @@ -35,7 +35,7 @@ def main(): if not options.is_download: logger.warning('You do not specify --download option') - doujinshis = favorites_parser() + doujinshis = favorites_parser(options.page_range) print_doujinshi(doujinshis) if options.is_download and doujinshis: doujinshi_ids = [i['id'] for i in doujinshis] diff --git a/nhentai/parser.py b/nhentai/parser.py index 57e94bf..212461f 100644 --- a/nhentai/parser.py +++ b/nhentai/parser.py @@ -65,7 +65,7 @@ def _get_title_and_id(response): return result -def favorites_parser(): +def favorites_parser(page_range=''): result = [] html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser') count = html.find('span', attrs={'class': 'count'}) @@ -89,7 +89,12 @@ def favorites_parser(): if os.getenv('DEBUG'): pages = 1 - for page in range(1, pages + 1): + page_range_list = range(1, pages + 1) + if page_range: + logger.info('page range is {0}'.format(page_range)) + page_range_list = page_range_parser(page_range, pages) + + for page in page_range_list: try: logger.info('Getting doujinshi ids of page %d' % page) resp = request('get', constant.FAV_URL + '?page=%d' % page).content @@ -100,6 +105,30 @@ def favorites_parser(): return result +def page_range_parser(page_range, max_page_num): + pages = set() + ranges = str.split(page_range, ',') + for range_str in ranges: + idx = range_str.find('-') + if idx == -1: + try: + page = int(range_str) + if page <= max_page_num: + pages.add(page) + except ValueError: + logger.error('page range({0}) is not valid'.format(page_range)) + else: + try: + left = int(range_str[:idx]) + right = int(range_str[idx+1:]) + if right > max_page_num: + right = max_page_num + for page in range(left, right+1): + pages.add(page) + except ValueError: + logger.error('page range({0}) is not valid'.format(page_range)) + + return list(pages) def doujinshi_parser(id_): if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):