Merge branch 'master' into dev

This commit is contained in:
Ricter Zheng 2020-03-14 23:34:49 +08:00 committed by GitHub
commit 49ac1d035d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 187 additions and 174 deletions

View File

@ -64,6 +64,8 @@ def cmd_parser():
help='page number of search results') help='page number of search results')
parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1, parser.add_option('--max-page', type='int', dest='max_page', action='store', default=1,
help='The max page when recursive download tagged doujinshi') 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', parser.add_option('--sorting', dest='sorting', action='store', default='date',
help='sorting of doujinshi (date / popular)', choices=['date', 'popular']) help='sorting of doujinshi (date / popular)', choices=['date', 'popular'])

View File

@ -35,7 +35,7 @@ def main():
if not options.is_download: if not options.is_download:
logger.warning('You do not specify --download option') logger.warning('You do not specify --download option')
doujinshis = favorites_parser() doujinshis = favorites_parser(options.page_range)
print_doujinshi(doujinshis) print_doujinshi(doujinshis)
if options.is_download and doujinshis: if options.is_download and doujinshis:
doujinshi_ids = [i['id'] for i in doujinshis] doujinshi_ids = [i['id'] for i in doujinshis]

View File

@ -65,7 +65,7 @@ def _get_title_and_id(response):
return result return result
def favorites_parser(): def favorites_parser(page_range=''):
result = [] result = []
html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser') html = BeautifulSoup(request('get', constant.FAV_URL).content, 'html.parser')
count = html.find('span', attrs={'class': 'count'}) count = html.find('span', attrs={'class': 'count'})
@ -89,7 +89,12 @@ def favorites_parser():
if os.getenv('DEBUG'): if os.getenv('DEBUG'):
pages = 1 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: try:
logger.info('Getting doujinshi ids of page %d' % page) logger.info('Getting doujinshi ids of page %d' % page)
resp = request('get', constant.FAV_URL + '?page=%d' % page).content resp = request('get', constant.FAV_URL + '?page=%d' % page).content
@ -100,6 +105,30 @@ def favorites_parser():
return result 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_): def doujinshi_parser(id_):
if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()): if not isinstance(id_, (int,)) and (isinstance(id_, (str,)) and not id_.isdigit()):

View File

@ -1,81 +1,85 @@
const pages = Array.from(document.querySelectorAll('img.image-item')); const pages = Array.from(document.querySelectorAll('img.image-item'));
let currentPage = 0; let currentPage = 0;
function changePage(pageNum) { function changePage(pageNum) {
const previous = pages[currentPage]; const previous = pages[currentPage];
const current = pages[pageNum]; const current = pages[pageNum];
if (current == null) { if (current == null) {
return; return;
} }
previous.classList.remove('current'); previous.classList.remove('current');
current.classList.add('current'); current.classList.add('current');
currentPage = pageNum; currentPage = pageNum;
const display = document.getElementById('dest'); const display = document.getElementById('dest');
display.style.backgroundImage = `url("${current.src}")`; display.style.backgroundImage = `url("${current.src}")`;
document.getElementById('page-num') scroll(0,0)
.innerText = [
(pageNum + 1).toLocaleString(), document.getElementById('page-num')
pages.length.toLocaleString() .innerText = [
].join('\u200a/\u200a'); (pageNum + 1).toLocaleString(),
} pages.length.toLocaleString()
].join('\u200a/\u200a');
changePage(0); }
document.getElementById('list').onclick = event => { changePage(0);
if (pages.includes(event.target)) {
changePage(pages.indexOf(event.target)); document.getElementById('list').onclick = event => {
} if (pages.includes(event.target)) {
}; changePage(pages.indexOf(event.target));
}
document.getElementById('image-container').onclick = event => { };
const width = document.getElementById('image-container').clientWidth;
const clickPos = event.clientX / width; document.getElementById('image-container').onclick = event => {
const width = document.getElementById('image-container').clientWidth;
if (clickPos < 0.5) { const clickPos = event.clientX / width;
changePage(currentPage - 1);
} else { if (clickPos < 0.5) {
changePage(currentPage + 1); changePage(currentPage - 1);
} } else {
}; changePage(currentPage + 1);
}
document.onkeypress = event => { };
switch (event.key.toLowerCase()) {
// Previous Image document.onkeypress = event => {
case 'w': switch (event.key.toLowerCase()) {
document.getElementById("dest").style.height = "200%"; // Previous Image
document.getElementById("list").style.height = "200%"; case 'w':
break; scrollBy(0, -40);
case 'a': break;
changePage(currentPage - 1); case 'a':
break; changePage(currentPage - 1);
// Return to previous page break;
case 'q': // Return to previous page
window.history.go(-1); case 'q':
break; window.history.go(-1);
// Next Image break;
case ' ': // Next Image
case 's': case ' ':
document.getElementById("dest").style.height = "100%"; case 's':
document.getElementById("list").style.height = "100%"; scrollBy(0, 40);
break; break;
case 'd': case 'd':
changePage(currentPage + 1); changePage(currentPage + 1);
break; break;
}// remove arrow cause it won't work }// remove arrow cause it won't work
}; };
document.onkeydown = event =>{ document.onkeydown = event =>{
switch (event.keyCode) { switch (event.keyCode) {
case 37: //left case 37: //left
changePage(currentPage - 1); changePage(currentPage - 1);
break; break;
case 39: //right case 38: //up
changePage(currentPage + 1); break;
break; case 39: //right
} changePage(currentPage + 1);
break;
case 40: //down
break;
}
}; };

View File

@ -1,92 +1,70 @@
*, *::after, *::before {
box-sizing: border-box; *, *::after, *::before {
} box-sizing: border-box;
}
img {
vertical-align: middle; img {
} vertical-align: middle;
}
html, body {
display: flex; html, body {
background-color: #e8e6e6; display: flex;
height: 100%; background-color: #e8e6e6;
width: 100%; height: 100%;
padding: 0; width: 100%;
margin: 0; padding: 0;
font-family: sans-serif; margin: 0;
} font-family: sans-serif;
}
#list {
height: 100%; #list {
overflow: auto; height: 2000px;
width: 260px; overflow: scroll;
text-align: center; width: 260px;
} text-align: center;
}
#list img {
width: 200px; #list img {
padding: 10px; width: 200px;
border-radius: 10px; padding: 10px;
margin: 15px 0; border-radius: 10px;
cursor: pointer; margin: 15px 0;
} cursor: pointer;
}
#list img.current {
background: #0003; #list img.current {
} background: #0003;
}
#image-container {
flex: auto; #image-container {
height: 100vh; flex: auto;
background: #000; height: 2000px;
color: #fff; background: #222;
text-align: center; color: #fff;
cursor: pointer; text-align: center;
-webkit-user-select: none; cursor: pointer;
user-select: none; -webkit-user-select: none;
position: relative; user-select: none;
} position: relative;
}
#image-container #dest {
background: #000; #image-container #dest {
height: 100%; height: 2000px;
width: 100%; width: 100%;
background-size: contain; background-size: contain;
background-repeat: no-repeat; background-repeat: no-repeat;
background-position: center; background-position: top;
} }
#image-container #page-num { #image-container #page-num {
position: absolute; position: static;
font-size: 18pt; font-size: 14pt;
left: 10px; left: 10px;
bottom: 5px; bottom: 5px;
font-weight: bold; font-weight: bold;
opacity: 0.75; opacity: 0.75;
text-shadow: /* Duplicate the same shadow to make it very strong */ text-shadow: /* Duplicate the same shadow to make it very strong */
0 0 2px #222, 0 0 2px #222,
0 0 2px #222, 0 0 2px #222,
0 0 2px #222; 0 0 2px #222;
}
@media only screen and (max-width: 855px) {
nav {
display: none;
}
}
@media only screen and (max-device-width: 855px) {
nav {
display: none;
}
}
div {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
:focus {
outline: 0;
border:none;
color: rgba(0, 0, 0, 0);
} }