mirror of
https://github.com/RicterZ/nhentai.git
synced 2026-04-08 10:40:22 +02:00
Initial commit: doujinshi-dl generic plugin framework
History reset as part of DMCA compliance. The project has been refactored into a generic, site-agnostic download framework. Site-specific logic lives in separate plugin packages. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
3
doujinshi_dl/__init__.py
Normal file
3
doujinshi_dl/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
__version__ = '2.0.5'
|
||||
__author__ = 'RicterZ'
|
||||
__email__ = 'ricterzheng@gmail.com'
|
||||
290
doujinshi_dl/cmdline.py
Normal file
290
doujinshi_dl/cmdline.py
Normal file
@@ -0,0 +1,290 @@
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from doujinshi_dl import __version__
|
||||
from doujinshi_dl.utils import generate_html, generate_main_html, DB, EXTENSIONS
|
||||
from doujinshi_dl.logger import logger
|
||||
from doujinshi_dl.constant import PATH_SEPARATOR
|
||||
|
||||
|
||||
_plugin_const_cache = None
|
||||
|
||||
|
||||
def _plugin_const():
|
||||
"""Return the active plugin's constant module without hard-coding plugin names."""
|
||||
global _plugin_const_cache
|
||||
if _plugin_const_cache is not None:
|
||||
return _plugin_const_cache
|
||||
from doujinshi_dl.core.registry import get_first_plugin
|
||||
import importlib
|
||||
plugin = get_first_plugin()
|
||||
pkg = type(plugin).__module__.split('.')[0] # top-level package name of the plugin
|
||||
_plugin_const_cache = importlib.import_module(f'{pkg}.constant')
|
||||
return _plugin_const_cache
|
||||
|
||||
|
||||
def banner():
|
||||
logger.debug(f'doujinshi-dl ver {__version__}: あなたも変態。 いいね?')
|
||||
|
||||
|
||||
def load_config():
|
||||
c = _plugin_const()
|
||||
if not os.path.exists(c.PLUGIN_CONFIG_FILE):
|
||||
return
|
||||
|
||||
try:
|
||||
with open(c.PLUGIN_CONFIG_FILE, 'r') as f:
|
||||
c.CONFIG.update(json.load(f))
|
||||
except json.JSONDecodeError:
|
||||
logger.error('Failed to load config file.')
|
||||
write_config()
|
||||
|
||||
|
||||
def write_config():
|
||||
c = _plugin_const()
|
||||
if not os.path.exists(c.PLUGIN_HOME):
|
||||
os.mkdir(c.PLUGIN_HOME)
|
||||
|
||||
with open(c.PLUGIN_CONFIG_FILE, 'w') as f:
|
||||
f.write(json.dumps(c.CONFIG))
|
||||
|
||||
|
||||
def callback(option, _opt_str, _value, parser):
|
||||
if option == '--id':
|
||||
pass
|
||||
value = []
|
||||
|
||||
for arg in parser.rargs:
|
||||
if arg.isdigit():
|
||||
value.append(int(arg))
|
||||
elif arg.startswith('-'):
|
||||
break
|
||||
else:
|
||||
logger.warning(f'Ignore invalid id {arg}')
|
||||
|
||||
setattr(parser.values, option.dest, value)
|
||||
|
||||
|
||||
def cmd_parser():
|
||||
load_config()
|
||||
c = _plugin_const()
|
||||
|
||||
parser = ArgumentParser(
|
||||
description='\n doujinshi-dl --search [keyword] --download'
|
||||
'\n DOUJINSHI_DL_URL=https://mirror-url/ doujinshi-dl --id [ID ...]'
|
||||
'\n doujinshi-dl --file [filename]'
|
||||
'\n\nEnvironment Variable:\n'
|
||||
' DOUJINSHI_DL_URL mirror url'
|
||||
)
|
||||
|
||||
# operation options
|
||||
parser.add_argument('--download', '-D', dest='is_download', action='store_true',
|
||||
help='download doujinshi (for search results)')
|
||||
parser.add_argument('--no-download', dest='no_download', action='store_true', default=False,
|
||||
help='download doujinshi (for search results)')
|
||||
parser.add_argument('--show', '-S', dest='is_show', action='store_true',
|
||||
help='just show the doujinshi information')
|
||||
|
||||
# doujinshi options
|
||||
parser.add_argument('--id', dest='id', nargs='+', type=int,
|
||||
help='doujinshi ids set, e.g. 167680 167681 167682')
|
||||
parser.add_argument('--search', '-s', type=str, dest='keyword',
|
||||
help='search doujinshi by keyword')
|
||||
parser.add_argument('--favorites', '-F', action='store_true', dest='favorites',
|
||||
help='list or download your favorites')
|
||||
parser.add_argument('--artist', '-a', type=str, dest='artist',
|
||||
help='list doujinshi by artist name')
|
||||
|
||||
# page options
|
||||
parser.add_argument('--page-all', dest='page_all', action='store_true', default=False,
|
||||
help='all search results')
|
||||
parser.add_argument('--page', '--page-range', type=str, dest='page',
|
||||
help='page number of search results. e.g. 1,2-5,14')
|
||||
parser.add_argument('--sorting', '--sort', dest='sorting', type=str, default='popular',
|
||||
help='sorting of doujinshi (recent / popular / popular-[today|week])',
|
||||
choices=['recent', 'popular', 'popular-today', 'popular-week', 'date'])
|
||||
|
||||
# download options
|
||||
parser.add_argument('--output', '-o', type=str, dest='output_dir', default='.',
|
||||
help='output dir')
|
||||
parser.add_argument('--threads', '-t', type=int, dest='threads', default=5,
|
||||
help='thread count for downloading doujinshi')
|
||||
parser.add_argument('--timeout', '-T', type=int, dest='timeout', default=30,
|
||||
help='timeout for downloading doujinshi')
|
||||
parser.add_argument('--delay', '-d', type=int, dest='delay', default=0,
|
||||
help='slow down between downloading every doujinshi')
|
||||
parser.add_argument('--retry', type=int, dest='retry', default=3,
|
||||
help='retry times when downloading failed')
|
||||
parser.add_argument('--exit-on-fail', dest='exit_on_fail', action='store_true', default=False,
|
||||
help='exit on fail to prevent generating incomplete files')
|
||||
parser.add_argument('--proxy', type=str, dest='proxy',
|
||||
help='store a proxy, for example: -p "http://127.0.0.1:1080"')
|
||||
parser.add_argument('--file', '-f', type=str, dest='file',
|
||||
help='read gallery IDs from file.')
|
||||
parser.add_argument('--format', type=str, dest='name_format', default='[%i][%a][%t]',
|
||||
help='format the saved folder name')
|
||||
|
||||
parser.add_argument('--no-filename-padding', action='store_true', dest='no_filename_padding',
|
||||
default=False, help='no padding in the images filename, such as \'001.jpg\'')
|
||||
|
||||
# generate options
|
||||
parser.add_argument('--html', dest='html_viewer', type=str, nargs='?', const='.',
|
||||
help='generate an HTML viewer in the specified directory, or scan all subfolders '
|
||||
'within the entire directory to generate the HTML viewer. By default, current '
|
||||
'working directory is used.')
|
||||
parser.add_argument('--no-html', dest='is_nohtml', action='store_true',
|
||||
help='don\'t generate HTML after downloading')
|
||||
parser.add_argument('--gen-main', dest='main_viewer', action='store_true',
|
||||
help='generate a main viewer contain all the doujin in the folder')
|
||||
parser.add_argument('--cbz', '-C', dest='is_cbz', action='store_true',
|
||||
help='generate Comic Book CBZ File')
|
||||
parser.add_argument('--pdf', '-P', dest='is_pdf', action='store_true',
|
||||
help='generate PDF file')
|
||||
|
||||
parser.add_argument('--meta', dest='generate_metadata', action='store_true', default=False,
|
||||
help='generate a metadata file in doujinshi format')
|
||||
parser.add_argument('--update-meta', dest='update_metadata', action='store_true', default=False,
|
||||
help='update the metadata file of a doujinshi, update CBZ metadata if exists')
|
||||
|
||||
parser.add_argument('--rm-origin-dir', dest='rm_origin_dir', action='store_true', default=False,
|
||||
help='remove downloaded doujinshi dir when generated CBZ or PDF file')
|
||||
parser.add_argument('--move-to-folder', dest='move_to_folder', action='store_true', default=False,
|
||||
help='remove files in doujinshi dir then move new file to folder when generated CBZ or PDF file')
|
||||
|
||||
parser.add_argument('--regenerate', dest='regenerate', action='store_true', default=False,
|
||||
help='regenerate the cbz or pdf file if exists')
|
||||
parser.add_argument('--zip', action='store_true', help='Package into a single zip file')
|
||||
|
||||
# site options
|
||||
parser.add_argument('--cookie', type=str, dest='cookie',
|
||||
help='set cookie to bypass Cloudflare captcha')
|
||||
parser.add_argument('--useragent', '--user-agent', type=str, dest='useragent',
|
||||
help='set useragent to bypass Cloudflare captcha')
|
||||
parser.add_argument('--language', type=str, dest='language',
|
||||
help='set default language to parse doujinshis')
|
||||
parser.add_argument('--clean-language', dest='clean_language', action='store_true', default=False,
|
||||
help='set DEFAULT as language to parse doujinshis')
|
||||
parser.add_argument('--save-download-history', dest='is_save_download_history', action='store_true',
|
||||
default=False, help='save downloaded doujinshis, whose will be skipped if you re-download them')
|
||||
parser.add_argument('--clean-download-history', action='store_true', default=False, dest='clean_download_history',
|
||||
help='clean download history')
|
||||
parser.add_argument('--template', dest='viewer_template', type=str, default='',
|
||||
help='set viewer template')
|
||||
parser.add_argument('--legacy', dest='legacy', action='store_true', default=False,
|
||||
help='use legacy searching method')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.html_viewer:
|
||||
if not os.path.exists(args.html_viewer):
|
||||
logger.error(f'Path \'{args.html_viewer}\' not exists')
|
||||
sys.exit(1)
|
||||
|
||||
for root, dirs, files in os.walk(args.html_viewer):
|
||||
if not dirs:
|
||||
generate_html(output_dir=args.html_viewer, template=c.CONFIG['template'])
|
||||
sys.exit(0)
|
||||
|
||||
for dir_name in dirs:
|
||||
# it will scan the entire subdirectories
|
||||
doujinshi_dir = os.path.join(root, dir_name)
|
||||
items = set(map(lambda s: os.path.splitext(s)[1], os.listdir(doujinshi_dir)))
|
||||
|
||||
# skip directory without any images
|
||||
if items & set(EXTENSIONS):
|
||||
generate_html(output_dir=doujinshi_dir, template=c.CONFIG['template'])
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
if args.main_viewer and not args.id and not args.keyword and not args.favorites:
|
||||
generate_main_html()
|
||||
sys.exit(0)
|
||||
|
||||
if args.clean_download_history:
|
||||
with DB() as db:
|
||||
db.clean_all()
|
||||
|
||||
logger.info('Download history cleaned.')
|
||||
sys.exit(0)
|
||||
|
||||
# --- set config ---
|
||||
if args.cookie is not None:
|
||||
c.CONFIG['cookie'] = args.cookie.strip()
|
||||
write_config()
|
||||
logger.info('Cookie saved.')
|
||||
|
||||
if args.useragent is not None:
|
||||
c.CONFIG['useragent'] = args.useragent.strip()
|
||||
write_config()
|
||||
logger.info('User-Agent saved.')
|
||||
|
||||
if args.language is not None:
|
||||
c.CONFIG['language'] = args.language
|
||||
write_config()
|
||||
logger.info(f'Default language now set to "{args.language}"')
|
||||
# TODO: search without language
|
||||
|
||||
if any([args.cookie, args.useragent, args.language]):
|
||||
sys.exit(0)
|
||||
|
||||
if args.proxy is not None:
|
||||
proxy_url = urlparse(args.proxy)
|
||||
if not args.proxy == '' and proxy_url.scheme not in ('http', 'https', 'socks5', 'socks5h',
|
||||
'socks4', 'socks4a'):
|
||||
logger.error(f'Invalid protocol "{proxy_url.scheme}" of proxy, ignored')
|
||||
sys.exit(0)
|
||||
else:
|
||||
c.CONFIG['proxy'] = args.proxy
|
||||
logger.info(f'Proxy now set to "{args.proxy}"')
|
||||
write_config()
|
||||
sys.exit(0)
|
||||
|
||||
if args.viewer_template is not None:
|
||||
if not args.viewer_template:
|
||||
args.viewer_template = 'default'
|
||||
|
||||
if not os.path.exists(os.path.join(os.path.dirname(__file__),
|
||||
f'viewer/{args.viewer_template}/index.html')):
|
||||
logger.error(f'Template "{args.viewer_template}" does not exists')
|
||||
sys.exit(1)
|
||||
else:
|
||||
c.CONFIG['template'] = args.viewer_template
|
||||
write_config()
|
||||
|
||||
# --- end set config ---
|
||||
|
||||
if args.favorites:
|
||||
if not c.CONFIG['cookie']:
|
||||
logger.warning('Cookie has not been set, please use `doujinshi-dl --cookie \'COOKIE\'` to set it.')
|
||||
sys.exit(1)
|
||||
|
||||
if args.file:
|
||||
with open(args.file, 'r') as f:
|
||||
_ = [i.strip() for i in f.readlines()]
|
||||
args.id = set(int(i) for i in _ if i.isdigit())
|
||||
|
||||
if (args.is_download or args.is_show) and not args.id and not args.keyword and not args.favorites and not args.artist:
|
||||
logger.critical('Doujinshi id(s) are required for downloading')
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
if not args.keyword and not args.id and not args.favorites and not args.artist:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
if args.threads <= 0:
|
||||
args.threads = 1
|
||||
|
||||
elif args.threads > 15:
|
||||
logger.critical('Maximum number of used threads is 15')
|
||||
sys.exit(1)
|
||||
|
||||
return args
|
||||
197
doujinshi_dl/command.py
Normal file
197
doujinshi_dl/command.py
Normal file
@@ -0,0 +1,197 @@
|
||||
# coding: utf-8
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import signal
|
||||
import platform
|
||||
import urllib3.exceptions
|
||||
|
||||
from doujinshi_dl.cmdline import cmd_parser, banner, write_config
|
||||
from doujinshi_dl.core.registry import get_first_plugin
|
||||
from doujinshi_dl.core import config as core_config
|
||||
from doujinshi_dl.downloader import Downloader, CompressedDownloader
|
||||
from doujinshi_dl.logger import logger
|
||||
from doujinshi_dl.utils import (
|
||||
generate_html, generate_doc, generate_main_html,
|
||||
paging, signal_handler, DB, move_to_folder,
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
banner()
|
||||
|
||||
if sys.version_info < (3, 0, 0):
|
||||
logger.error('doujinshi-dl requires Python 3.x')
|
||||
sys.exit(1)
|
||||
|
||||
plugin = get_first_plugin()
|
||||
parser = plugin.create_parser()
|
||||
serializer = plugin.create_serializer()
|
||||
|
||||
options = cmd_parser()
|
||||
|
||||
# Let the plugin configure its own CONFIG and register runtime values
|
||||
# (this also sets core_config 'base_url' from env or plugin default)
|
||||
plugin.configure(options)
|
||||
|
||||
# Read common config values registered by the plugin
|
||||
plugin_config = core_config.get('plugin_config', {})
|
||||
base_url = core_config.get('base_url', os.getenv('DOUJINSHI_DL_URL', ''))
|
||||
if not base_url:
|
||||
logger.error('No target URL configured. Set DOUJINSHI_DL_URL or install a plugin that provides a default URL.')
|
||||
sys.exit(1)
|
||||
logger.info(f'Using mirror: {base_url}')
|
||||
|
||||
# CONFIG['proxy'] may have been updated after cmd_parser()
|
||||
proxy = plugin_config.get('proxy', '')
|
||||
if proxy:
|
||||
if isinstance(proxy, dict):
|
||||
proxy = proxy.get('http', '')
|
||||
plugin_config['proxy'] = proxy
|
||||
logger.warning(f'Update proxy config to: {proxy}')
|
||||
write_config()
|
||||
logger.info(f'Using proxy: {proxy}')
|
||||
|
||||
if not plugin_config.get('template'):
|
||||
plugin_config['template'] = 'default'
|
||||
|
||||
template = plugin_config.get('template', 'default')
|
||||
language = plugin_config.get('language', '')
|
||||
logger.info(f'Using viewer template "{template}"')
|
||||
|
||||
# Check authentication
|
||||
plugin.check_auth()
|
||||
|
||||
doujinshis = []
|
||||
doujinshi_ids = []
|
||||
|
||||
page_list = paging(options.page)
|
||||
|
||||
if options.favorites:
|
||||
if not options.is_download:
|
||||
logger.warning('You do not specify --download option')
|
||||
|
||||
doujinshis = parser.favorites(page=page_list) if options.page else parser.favorites()
|
||||
|
||||
elif options.keyword:
|
||||
if language:
|
||||
logger.info(f'Using default language: {language}')
|
||||
options.keyword += f' language:{language}'
|
||||
|
||||
doujinshis = parser.search(
|
||||
options.keyword,
|
||||
sorting=options.sorting,
|
||||
page=page_list,
|
||||
legacy=options.legacy,
|
||||
is_page_all=options.page_all,
|
||||
)
|
||||
|
||||
elif options.artist:
|
||||
doujinshis = parser.search(
|
||||
options.artist,
|
||||
sorting=options.sorting,
|
||||
page=page_list,
|
||||
is_page_all=options.page_all,
|
||||
type_='ARTIST',
|
||||
)
|
||||
|
||||
elif not doujinshi_ids:
|
||||
doujinshi_ids = options.id
|
||||
|
||||
plugin.print_results(doujinshis)
|
||||
if options.is_download and doujinshis:
|
||||
doujinshi_ids = [i['id'] for i in doujinshis]
|
||||
|
||||
if options.is_save_download_history:
|
||||
with DB() as db:
|
||||
data = set(map(int, db.get_all()))
|
||||
|
||||
doujinshi_ids = list(set(map(int, doujinshi_ids)) - set(data))
|
||||
logger.info(f'New doujinshis account: {len(doujinshi_ids)}')
|
||||
|
||||
if options.zip:
|
||||
options.is_nohtml = True
|
||||
|
||||
if not options.is_show:
|
||||
downloader = (CompressedDownloader if options.zip else Downloader)(
|
||||
path=options.output_dir,
|
||||
threads=options.threads,
|
||||
timeout=options.timeout,
|
||||
delay=options.delay,
|
||||
exit_on_fail=options.exit_on_fail,
|
||||
no_filename_padding=options.no_filename_padding,
|
||||
)
|
||||
|
||||
for doujinshi_id in doujinshi_ids:
|
||||
meta = parser.fetch(str(doujinshi_id))
|
||||
if not meta:
|
||||
continue
|
||||
|
||||
doujinshi_model = plugin.create_model(meta, name_format=options.name_format)
|
||||
doujinshi = doujinshi_model.doujinshi
|
||||
doujinshi.downloader = downloader
|
||||
|
||||
if doujinshi.check_if_need_download(options):
|
||||
doujinshi.download()
|
||||
else:
|
||||
logger.info(
|
||||
f'Skip download doujinshi because a PDF/CBZ file exists of doujinshi {doujinshi.name}'
|
||||
)
|
||||
|
||||
doujinshi_dir = os.path.join(options.output_dir, doujinshi.filename)
|
||||
|
||||
if options.generate_metadata:
|
||||
serializer.write_all(meta, doujinshi_dir)
|
||||
logger.log(16, f'Metadata files have been written to "{doujinshi_dir}"')
|
||||
|
||||
if options.is_save_download_history:
|
||||
with DB() as db:
|
||||
db.add_one(doujinshi.id)
|
||||
|
||||
if not options.is_nohtml:
|
||||
generate_html(options.output_dir, doujinshi, template=template)
|
||||
|
||||
if options.is_cbz:
|
||||
# Write ComicInfo.xml metadata before packaging
|
||||
serializer.write_all(meta, doujinshi_dir)
|
||||
generate_doc('cbz', options.output_dir, doujinshi, options.regenerate)
|
||||
|
||||
if options.is_pdf:
|
||||
generate_doc('pdf', options.output_dir, doujinshi, options.regenerate)
|
||||
|
||||
if options.move_to_folder:
|
||||
if options.is_cbz:
|
||||
move_to_folder(options.output_dir, doujinshi, 'cbz')
|
||||
if options.is_pdf:
|
||||
move_to_folder(options.output_dir, doujinshi, 'pdf')
|
||||
|
||||
if options.rm_origin_dir:
|
||||
if options.move_to_folder:
|
||||
logger.critical('You specified both --move-to-folder and --rm-origin-dir options, '
|
||||
'you will not get anything :(')
|
||||
shutil.rmtree(os.path.join(options.output_dir, doujinshi.filename), ignore_errors=True)
|
||||
|
||||
if options.main_viewer:
|
||||
generate_main_html(options.output_dir)
|
||||
serializer.finalize(options.output_dir)
|
||||
|
||||
if not platform.system() == 'Windows':
|
||||
logger.log(16, '🍻 All done.')
|
||||
else:
|
||||
logger.log(16, 'All done.')
|
||||
|
||||
else:
|
||||
for doujinshi_id in doujinshi_ids:
|
||||
meta = parser.fetch(str(doujinshi_id))
|
||||
if not meta:
|
||||
continue
|
||||
doujinshi_model = plugin.create_model(meta, name_format=options.name_format)
|
||||
doujinshi = doujinshi_model.doujinshi
|
||||
doujinshi.show()
|
||||
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
9
doujinshi_dl/constant.py
Normal file
9
doujinshi_dl/constant.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# coding: utf-8
|
||||
"""Main-package constants.
|
||||
|
||||
Only the constants that the main package itself needs are defined here.
|
||||
Plugin-specific constants live in the respective plugin package.
|
||||
"""
|
||||
import os
|
||||
|
||||
PATH_SEPARATOR = os.path.sep
|
||||
1
doujinshi_dl/core/__init__.py
Normal file
1
doujinshi_dl/core/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# coding: utf-8
|
||||
16
doujinshi_dl/core/config.py
Normal file
16
doujinshi_dl/core/config.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# coding: utf-8
|
||||
"""Runtime configuration store for the main package.
|
||||
|
||||
Plugins write their paths and settings here so that generic utilities
|
||||
(e.g. db.py) can read them without hard-coding any plugin name.
|
||||
"""
|
||||
|
||||
_runtime: dict = {}
|
||||
|
||||
|
||||
def set(key: str, value) -> None:
|
||||
_runtime[key] = value
|
||||
|
||||
|
||||
def get(key: str, default=None):
|
||||
return _runtime.get(key, default)
|
||||
214
doujinshi_dl/core/downloader.py
Normal file
214
doujinshi_dl/core/downloader.py
Normal file
@@ -0,0 +1,214 @@
|
||||
# coding: utf-
|
||||
|
||||
import os
|
||||
import asyncio
|
||||
import httpx
|
||||
import urllib3.exceptions
|
||||
import zipfile
|
||||
import io
|
||||
|
||||
from urllib.parse import urlparse
|
||||
from doujinshi_dl.core.logger import logger
|
||||
from doujinshi_dl.core.utils.db import Singleton
|
||||
from doujinshi_dl.core import config as core_config
|
||||
|
||||
|
||||
async def _async_request(method, url, timeout=30, proxy=None):
|
||||
"""Minimal async HTTP helper using httpx directly."""
|
||||
# httpx >=0.28 uses `proxy` (str), older versions used `proxies` (dict)
|
||||
client_kwargs = {'verify': False}
|
||||
if proxy:
|
||||
client_kwargs['proxy'] = proxy
|
||||
async with httpx.AsyncClient(**client_kwargs) as client:
|
||||
headers = {}
|
||||
cookie = core_config.get('plugin_config', {}).get('cookie', '')
|
||||
useragent = core_config.get('plugin_config', {}).get('useragent', '')
|
||||
if cookie:
|
||||
headers['Cookie'] = cookie
|
||||
if useragent:
|
||||
headers['User-Agent'] = useragent
|
||||
return await client.request(method, url, timeout=timeout, headers=headers, follow_redirects=True)
|
||||
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
def download_callback(result):
|
||||
result, data = result
|
||||
if result == 0:
|
||||
logger.warning('fatal errors occurred, ignored')
|
||||
elif result == -1:
|
||||
logger.warning(f'url {data} return status code 404')
|
||||
elif result == -2:
|
||||
logger.warning('Ctrl-C pressed, exiting sub processes ...')
|
||||
elif result == -3:
|
||||
# workers won't be run, just pass
|
||||
pass
|
||||
else:
|
||||
logger.log(16, f'{data} downloaded successfully')
|
||||
|
||||
|
||||
class Downloader(Singleton):
|
||||
def __init__(self, path='', threads=5, timeout=30, delay=0, exit_on_fail=False,
|
||||
no_filename_padding=False):
|
||||
self.threads = threads
|
||||
self.path = str(path)
|
||||
self.timeout = timeout
|
||||
self.delay = delay
|
||||
self.exit_on_fail = exit_on_fail
|
||||
self.folder = None
|
||||
self.semaphore = None
|
||||
self.no_filename_padding = no_filename_padding
|
||||
|
||||
async def fiber(self, tasks):
|
||||
self.semaphore = asyncio.Semaphore(self.threads)
|
||||
for completed_task in asyncio.as_completed(tasks):
|
||||
try:
|
||||
result = await completed_task
|
||||
if result[0] > 0:
|
||||
logger.info(f'{result[1]} download completed')
|
||||
else:
|
||||
raise Exception(f'{result[1]} download failed, return value {result[0]}')
|
||||
except Exception as e:
|
||||
logger.error(f'An error occurred: {e}')
|
||||
if self.exit_on_fail:
|
||||
raise Exception('User intends to exit on fail')
|
||||
|
||||
async def _semaphore_download(self, *args, **kwargs):
|
||||
async with self.semaphore:
|
||||
return await self.download(*args, **kwargs)
|
||||
|
||||
async def download(self, url, folder='', filename='', retried=0, proxy=None, length=0):
|
||||
logger.info(f'Starting to download {url} ...')
|
||||
|
||||
if self.delay:
|
||||
await asyncio.sleep(self.delay)
|
||||
|
||||
filename = filename if filename else os.path.basename(urlparse(url).path)
|
||||
base_filename, extension = os.path.splitext(filename)
|
||||
|
||||
if not self.no_filename_padding:
|
||||
filename = base_filename.zfill(length) + extension
|
||||
else:
|
||||
filename = base_filename + extension
|
||||
|
||||
try:
|
||||
response = await _async_request('GET', url, timeout=self.timeout, proxy=proxy)
|
||||
|
||||
if response.status_code != 200:
|
||||
path = urlparse(url).path
|
||||
image_url_mirrors = core_config.get('image_url_mirrors', [])
|
||||
for mirror in image_url_mirrors:
|
||||
logger.info(f"Try mirror: {mirror}{path}")
|
||||
mirror_url = f'{mirror}{path}'
|
||||
response = await _async_request('GET', mirror_url, timeout=self.timeout, proxy=proxy)
|
||||
if response.status_code == 200:
|
||||
break
|
||||
|
||||
if not await self.save(filename, response):
|
||||
logger.error(f'Can not download image {url}')
|
||||
return -1, url
|
||||
|
||||
except (httpx.HTTPStatusError, httpx.TimeoutException, httpx.ConnectError) as e:
|
||||
retry_times = core_config.get('retry_times', 3)
|
||||
if retried < retry_times:
|
||||
logger.warning(f'Download {filename} failed, retrying({retried + 1}) times...')
|
||||
return await self.download(
|
||||
url=url,
|
||||
folder=folder,
|
||||
filename=filename,
|
||||
retried=retried + 1,
|
||||
proxy=proxy,
|
||||
)
|
||||
else:
|
||||
logger.warning(f'Download {filename} failed with {retry_times} times retried, skipped')
|
||||
return -2, url
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
||||
logger.error(f"Exception type: {type(e)}")
|
||||
traceback.print_stack()
|
||||
logger.critical(str(e))
|
||||
return -9, url
|
||||
|
||||
except KeyboardInterrupt:
|
||||
return -4, url
|
||||
|
||||
return 1, url
|
||||
|
||||
async def save(self, filename, response) -> bool:
|
||||
if response is None:
|
||||
logger.error('Error: Response is None')
|
||||
return False
|
||||
save_file_path = os.path.join(self.folder, filename)
|
||||
with open(save_file_path, 'wb') as f:
|
||||
if response is not None:
|
||||
length = response.headers.get('content-length')
|
||||
if length is None:
|
||||
f.write(response.content)
|
||||
else:
|
||||
async for chunk in response.aiter_bytes(2048):
|
||||
f.write(chunk)
|
||||
return True
|
||||
|
||||
def create_storage_object(self, folder:str):
|
||||
if not os.path.exists(folder):
|
||||
try:
|
||||
os.makedirs(folder)
|
||||
except EnvironmentError as e:
|
||||
logger.critical(str(e))
|
||||
self.folder:str = folder
|
||||
self.close = lambda: None # Only available in class CompressedDownloader
|
||||
|
||||
def start_download(self, queue, folder='') -> bool:
|
||||
if not isinstance(folder, (str,)):
|
||||
folder = str(folder)
|
||||
|
||||
if self.path:
|
||||
folder = os.path.join(self.path, folder)
|
||||
|
||||
logger.info(f'Doujinshi will be saved at "{folder}"')
|
||||
self.create_storage_object(folder)
|
||||
|
||||
if os.getenv('DEBUG', None) == 'NODOWNLOAD':
|
||||
# Assuming we want to continue with rest of process.
|
||||
return True
|
||||
|
||||
digit_length = len(str(len(queue)))
|
||||
logger.info(f'Total download pages: {len(queue)}')
|
||||
coroutines = [
|
||||
self._semaphore_download(url, filename=os.path.basename(urlparse(url).path), length=digit_length)
|
||||
for url in queue
|
||||
]
|
||||
|
||||
# Prevent coroutines infection
|
||||
asyncio.run(self.fiber(coroutines))
|
||||
|
||||
self.close()
|
||||
|
||||
return True
|
||||
|
||||
class CompressedDownloader(Downloader):
|
||||
def create_storage_object(self, folder):
|
||||
filename = f'{folder}.zip'
|
||||
print(filename)
|
||||
self.zipfile = zipfile.ZipFile(filename,'w')
|
||||
self.close = lambda: self.zipfile.close()
|
||||
|
||||
async def save(self, filename, response) -> bool:
|
||||
if response is None:
|
||||
logger.error('Error: Response is None')
|
||||
return False
|
||||
|
||||
image_data = io.BytesIO()
|
||||
length = response.headers.get('content-length')
|
||||
if length is None:
|
||||
content = await response.read()
|
||||
image_data.write(content)
|
||||
else:
|
||||
async for chunk in response.aiter_bytes(2048):
|
||||
image_data.write(chunk)
|
||||
|
||||
image_data.seek(0)
|
||||
self.zipfile.writestr(filename, image_data.read())
|
||||
return True
|
||||
179
doujinshi_dl/core/logger.py
Normal file
179
doujinshi_dl/core/logger.py
Normal file
@@ -0,0 +1,179 @@
|
||||
#
|
||||
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
|
||||
#
|
||||
import logging
|
||||
import re
|
||||
import platform
|
||||
import sys
|
||||
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
import ctypes
|
||||
import ctypes.wintypes
|
||||
|
||||
# Reference: https://gist.github.com/vsajip/758430
|
||||
# https://github.com/ipython/ipython/issues/4252
|
||||
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms686047%28v=vs.85%29.aspx
|
||||
ctypes.windll.kernel32.SetConsoleTextAttribute.argtypes = [ctypes.wintypes.HANDLE, ctypes.wintypes.WORD]
|
||||
ctypes.windll.kernel32.SetConsoleTextAttribute.restype = ctypes.wintypes.BOOL
|
||||
|
||||
|
||||
class ColorizingStreamHandler(logging.StreamHandler):
|
||||
# color names to indices
|
||||
color_map = {
|
||||
'black': 0,
|
||||
'red': 1,
|
||||
'green': 2,
|
||||
'yellow': 3,
|
||||
'blue': 4,
|
||||
'magenta': 5,
|
||||
'cyan': 6,
|
||||
'white': 7,
|
||||
}
|
||||
|
||||
# levels to (background, foreground, bold/intense)
|
||||
level_map = {
|
||||
logging.DEBUG: (None, 'blue', False),
|
||||
logging.INFO: (None, 'white', False),
|
||||
logging.WARNING: (None, 'yellow', False),
|
||||
logging.ERROR: (None, 'red', False),
|
||||
logging.CRITICAL: ('red', 'white', False)
|
||||
}
|
||||
csi = '\x1b['
|
||||
reset = '\x1b[0m'
|
||||
disable_coloring = False
|
||||
|
||||
@property
|
||||
def is_tty(self):
|
||||
isatty = getattr(self.stream, 'isatty', None)
|
||||
return isatty and isatty() and not self.disable_coloring
|
||||
|
||||
def emit(self, record):
|
||||
try:
|
||||
message = self.format(record)
|
||||
stream = self.stream
|
||||
|
||||
if not self.is_tty:
|
||||
if message and message[0] == "\r":
|
||||
message = message[1:]
|
||||
stream.write(message)
|
||||
else:
|
||||
self.output_colorized(message)
|
||||
stream.write(getattr(self, 'terminator', '\n'))
|
||||
|
||||
self.flush()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except IOError:
|
||||
pass
|
||||
except:
|
||||
self.handleError(record)
|
||||
|
||||
|
||||
if not platform.system() == 'Windows':
|
||||
def output_colorized(self, message):
|
||||
self.stream.write(message)
|
||||
else:
|
||||
ansi_esc = re.compile(r'\x1b\[((?:\d+)(?:;(?:\d+))*)m')
|
||||
|
||||
nt_color_map = {
|
||||
0: 0x00, # black
|
||||
1: 0x04, # red
|
||||
2: 0x02, # green
|
||||
3: 0x06, # yellow
|
||||
4: 0x01, # blue
|
||||
5: 0x05, # magenta
|
||||
6: 0x03, # cyan
|
||||
7: 0x07, # white
|
||||
}
|
||||
|
||||
def output_colorized(self, message):
|
||||
parts = self.ansi_esc.split(message)
|
||||
write = self.stream.write
|
||||
h = None
|
||||
fd = getattr(self.stream, 'fileno', None)
|
||||
|
||||
if fd is not None:
|
||||
fd = fd()
|
||||
|
||||
if fd in (1, 2): # stdout or stderr
|
||||
h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)
|
||||
|
||||
while parts:
|
||||
text = parts.pop(0)
|
||||
|
||||
if text:
|
||||
if sys.version_info < (3, 0, 0):
|
||||
write(text.encode('utf-8'))
|
||||
else:
|
||||
write(text)
|
||||
|
||||
if parts:
|
||||
params = parts.pop(0)
|
||||
|
||||
if h is not None:
|
||||
params = [int(p) for p in params.split(';')]
|
||||
color = 0
|
||||
|
||||
for p in params:
|
||||
if 40 <= p <= 47:
|
||||
color |= self.nt_color_map[p - 40] << 4
|
||||
elif 30 <= p <= 37:
|
||||
color |= self.nt_color_map[p - 30]
|
||||
elif p == 1:
|
||||
color |= 0x08 # foreground intensity on
|
||||
elif p == 0: # reset to default color
|
||||
color = 0x07
|
||||
else:
|
||||
pass # error condition ignored
|
||||
|
||||
ctypes.windll.kernel32.SetConsoleTextAttribute(h, color)
|
||||
|
||||
def colorize(self, message, record):
|
||||
if record.levelno in self.level_map and self.is_tty:
|
||||
bg, fg, bold = self.level_map[record.levelno]
|
||||
params = []
|
||||
|
||||
if bg in self.color_map:
|
||||
params.append(str(self.color_map[bg] + 40))
|
||||
|
||||
if fg in self.color_map:
|
||||
params.append(str(self.color_map[fg] + 30))
|
||||
|
||||
if bold:
|
||||
params.append('1')
|
||||
|
||||
if params and message:
|
||||
if message.lstrip() != message:
|
||||
prefix = re.search(r"\s+", message).group(0)
|
||||
message = message[len(prefix):]
|
||||
else:
|
||||
prefix = ""
|
||||
|
||||
message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params),
|
||||
'm', message, self.reset)))
|
||||
|
||||
return message
|
||||
|
||||
def format(self, record):
|
||||
message = logging.StreamHandler.format(self, record)
|
||||
return self.colorize(message, record)
|
||||
|
||||
|
||||
logging.addLevelName(16, "SUCCESS")
|
||||
logger = logging.getLogger('doujinshi_dl')
|
||||
LOGGER_HANDLER = ColorizingStreamHandler(sys.stdout)
|
||||
FORMATTER = logging.Formatter("\r[%(asctime)s] %(funcName)s: %(message)s", "%H:%M:%S")
|
||||
LOGGER_HANDLER.setFormatter(FORMATTER)
|
||||
LOGGER_HANDLER.level_map[logging.getLevelName("SUCCESS")] = (None, "green", False)
|
||||
logger.addHandler(LOGGER_HANDLER)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logger.log(16, 'doujinshi-dl')
|
||||
logger.info('info')
|
||||
logger.warning('warning')
|
||||
logger.debug('debug')
|
||||
logger.error('error')
|
||||
logger.critical('critical')
|
||||
77
doujinshi_dl/core/plugin.py
Normal file
77
doujinshi_dl/core/plugin.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# coding: utf-8
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass, field
|
||||
from typing import List, Dict, Any, Iterator, Tuple
|
||||
|
||||
|
||||
@dataclass
|
||||
class GalleryMeta:
|
||||
id: str
|
||||
name: str
|
||||
pretty_name: str
|
||||
img_id: str
|
||||
ext: list
|
||||
pages: int
|
||||
info: Dict[str, Any] = field(default_factory=dict)
|
||||
extra: Dict[str, Any] = field(default_factory=dict) # plugin-private data
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
d = {
|
||||
'id': self.id,
|
||||
'name': self.name,
|
||||
'pretty_name': self.pretty_name,
|
||||
'img_id': self.img_id,
|
||||
'ext': self.ext,
|
||||
'pages': self.pages,
|
||||
}
|
||||
d.update(self.info)
|
||||
d.update(self.extra)
|
||||
return d
|
||||
|
||||
|
||||
class BaseParser(ABC):
|
||||
@abstractmethod
|
||||
def fetch(self, gallery_id: str) -> GalleryMeta: ...
|
||||
|
||||
@abstractmethod
|
||||
def search(self, keyword: str, sorting: str = 'date', page=None, **kwargs) -> List[Dict]: ...
|
||||
|
||||
def favorites(self, page=None) -> List[Dict]:
|
||||
return []
|
||||
|
||||
def configure(self, args): ...
|
||||
|
||||
|
||||
class BaseModel(ABC):
|
||||
@abstractmethod
|
||||
def iter_tasks(self) -> Iterator[Tuple[str, str]]: ...
|
||||
# yields (url, filename) tuples
|
||||
|
||||
|
||||
class BaseSerializer(ABC):
|
||||
@abstractmethod
|
||||
def write_all(self, meta: GalleryMeta, output_dir: str): ...
|
||||
|
||||
def finalize(self, output_dir: str) -> None:
|
||||
pass
|
||||
|
||||
|
||||
class BasePlugin(ABC):
|
||||
name: str
|
||||
|
||||
@abstractmethod
|
||||
def create_parser(self) -> BaseParser: ...
|
||||
|
||||
@abstractmethod
|
||||
def create_model(self, meta: GalleryMeta, name_format: str = '[%i][%a][%t]') -> BaseModel: ...
|
||||
|
||||
@abstractmethod
|
||||
def create_serializer(self) -> BaseSerializer: ...
|
||||
|
||||
def register_args(self, argparser): pass
|
||||
|
||||
def check_auth(self) -> None:
|
||||
pass
|
||||
|
||||
def print_results(self, results) -> None:
|
||||
pass
|
||||
28
doujinshi_dl/core/registry.py
Normal file
28
doujinshi_dl/core/registry.py
Normal file
@@ -0,0 +1,28 @@
|
||||
# coding: utf-8
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from doujinshi_dl.core.plugin import BasePlugin
|
||||
|
||||
|
||||
def get_plugin(name: str) -> 'BasePlugin':
|
||||
from importlib.metadata import entry_points
|
||||
eps = entry_points(group='doujinshi_dl.plugins')
|
||||
for ep in eps:
|
||||
if ep.name == name:
|
||||
return ep.load()
|
||||
raise KeyError(
|
||||
f"Plugin {name!r} not found. "
|
||||
f"Install it with: pip install doujinshi-dl-{name}"
|
||||
)
|
||||
|
||||
|
||||
def get_first_plugin() -> 'BasePlugin':
|
||||
from importlib.metadata import entry_points
|
||||
eps = list(entry_points(group='doujinshi_dl.plugins'))
|
||||
if not eps:
|
||||
raise RuntimeError(
|
||||
"No doujinshi-dl plugin installed. "
|
||||
"Install a plugin from PyPI, e.g.: pip install doujinshi-dl-<name>"
|
||||
)
|
||||
return eps[0].load()
|
||||
5
doujinshi_dl/core/utils/__init__.py
Normal file
5
doujinshi_dl/core/utils/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# coding: utf-8
|
||||
from doujinshi_dl.core.utils.db import Singleton, DB
|
||||
from doujinshi_dl.core.utils.fs import format_filename, generate_cbz, move_to_folder, parse_doujinshi_obj, EXTENSIONS
|
||||
from doujinshi_dl.core.utils.html import generate_html, generate_main_html
|
||||
from doujinshi_dl.core.utils.http import async_request
|
||||
50
doujinshi_dl/core/utils/db.py
Normal file
50
doujinshi_dl/core/utils/db.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# coding: utf-8
|
||||
"""DB and Singleton utilities."""
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
|
||||
class _Singleton(type):
|
||||
""" A metaclass that creates a Singleton base class when called. """
|
||||
_instances = {}
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls not in cls._instances:
|
||||
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
|
||||
return cls._instances[cls]
|
||||
|
||||
|
||||
class Singleton(_Singleton(str('SingletonMeta'), (object,), {})):
|
||||
pass
|
||||
|
||||
|
||||
class DB(object):
|
||||
conn = None
|
||||
cur = None
|
||||
|
||||
def __enter__(self):
|
||||
from doujinshi_dl.core import config
|
||||
history_path = config.get(
|
||||
'history_path',
|
||||
os.path.expanduser('~/.doujinshi-dl/history.sqlite3'),
|
||||
)
|
||||
self.conn = sqlite3.connect(history_path)
|
||||
self.cur = self.conn.cursor()
|
||||
self.cur.execute('CREATE TABLE IF NOT EXISTS download_history (id text)')
|
||||
self.conn.commit()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.conn.close()
|
||||
|
||||
def clean_all(self):
|
||||
self.cur.execute('DELETE FROM download_history WHERE 1')
|
||||
self.conn.commit()
|
||||
|
||||
def add_one(self, data):
|
||||
self.cur.execute('INSERT INTO download_history VALUES (?)', [data])
|
||||
self.conn.commit()
|
||||
|
||||
def get_all(self):
|
||||
data = self.cur.execute('SELECT id FROM download_history')
|
||||
return [i[0] for i in data]
|
||||
98
doujinshi_dl/core/utils/fs.py
Normal file
98
doujinshi_dl/core/utils/fs.py
Normal file
@@ -0,0 +1,98 @@
|
||||
# coding: utf-8
|
||||
"""Filesystem utilities: filename formatting, CBZ generation, folder management."""
|
||||
import os
|
||||
import zipfile
|
||||
import shutil
|
||||
from typing import Tuple
|
||||
|
||||
from doujinshi_dl.core.logger import logger
|
||||
from doujinshi_dl.constant import PATH_SEPARATOR
|
||||
|
||||
MAX_FIELD_LENGTH = 100
|
||||
EXTENSIONS = ('.png', '.jpg', '.jpeg', '.gif', '.webp')
|
||||
|
||||
|
||||
def format_filename(s, length=MAX_FIELD_LENGTH, _truncate_only=False):
|
||||
"""
|
||||
It used to be a whitelist approach allowed only alphabet and a part of symbols.
|
||||
but most doujinshi's names include Japanese 2-byte characters and these was rejected.
|
||||
so it is using blacklist approach now.
|
||||
if filename include forbidden characters ('/:,;*?"<>|) ,it replaces space character(" ").
|
||||
"""
|
||||
if not _truncate_only:
|
||||
ban_chars = '\\\'/:,;*?"<>|\t\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b'
|
||||
filename = s.translate(str.maketrans(ban_chars, ' ' * len(ban_chars))).strip()
|
||||
filename = ' '.join(filename.split())
|
||||
|
||||
while filename.endswith('.'):
|
||||
filename = filename[:-1]
|
||||
else:
|
||||
filename = s
|
||||
|
||||
# limit `length` chars
|
||||
if len(filename) >= length:
|
||||
filename = filename[:length - 1] + u'…'
|
||||
|
||||
# Remove [] from filename
|
||||
filename = filename.replace('[]', '').strip()
|
||||
return filename
|
||||
|
||||
|
||||
def parse_doujinshi_obj(
|
||||
output_dir: str,
|
||||
doujinshi_obj=None,
|
||||
file_type: str = ''
|
||||
) -> Tuple[str, str]:
|
||||
filename = f'.{PATH_SEPARATOR}doujinshi.{file_type}'
|
||||
if doujinshi_obj is not None:
|
||||
doujinshi_dir = os.path.join(output_dir, doujinshi_obj.filename)
|
||||
_filename = f'{doujinshi_obj.filename}.{file_type}'
|
||||
|
||||
if file_type == 'pdf':
|
||||
_filename = _filename.replace('/', '-')
|
||||
|
||||
filename = os.path.join(output_dir, _filename)
|
||||
else:
|
||||
if file_type == 'html':
|
||||
return output_dir, 'index.html'
|
||||
|
||||
doujinshi_dir = f'.{PATH_SEPARATOR}'
|
||||
|
||||
if not os.path.exists(doujinshi_dir):
|
||||
os.makedirs(doujinshi_dir)
|
||||
|
||||
return doujinshi_dir, filename
|
||||
|
||||
|
||||
def generate_cbz(doujinshi_dir, filename):
|
||||
file_list = os.listdir(doujinshi_dir)
|
||||
file_list.sort()
|
||||
|
||||
logger.info(f'Writing CBZ file to path: {filename}')
|
||||
with zipfile.ZipFile(filename, 'w') as cbz_pf:
|
||||
for image in file_list:
|
||||
image_path = os.path.join(doujinshi_dir, image)
|
||||
cbz_pf.write(image_path, image)
|
||||
|
||||
logger.log(16, f'Comic Book CBZ file has been written to "{filename}"')
|
||||
|
||||
|
||||
def move_to_folder(output_dir='.', doujinshi_obj=None, file_type=None):
|
||||
if not file_type:
|
||||
raise RuntimeError('no file_type specified')
|
||||
|
||||
doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, file_type)
|
||||
|
||||
for fn in os.listdir(doujinshi_dir):
|
||||
file_path = os.path.join(doujinshi_dir, fn)
|
||||
_, ext = os.path.splitext(file_path)
|
||||
if ext in ['.pdf', '.cbz']:
|
||||
continue
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
try:
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting file: {e}")
|
||||
|
||||
shutil.move(filename, os.path.join(doujinshi_dir, os.path.basename(filename)))
|
||||
118
doujinshi_dl/core/utils/html.py
Normal file
118
doujinshi_dl/core/utils/html.py
Normal file
@@ -0,0 +1,118 @@
|
||||
# coding: utf-8
|
||||
"""HTML viewer generation utilities (generic, no site-specific references)."""
|
||||
import json
|
||||
import os
|
||||
import urllib.parse
|
||||
|
||||
from doujinshi_dl.core.logger import logger
|
||||
from doujinshi_dl.core.utils.fs import EXTENSIONS, parse_doujinshi_obj
|
||||
from doujinshi_dl.constant import PATH_SEPARATOR
|
||||
|
||||
|
||||
def _readfile(path):
|
||||
loc = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) # doujinshi_dl/
|
||||
|
||||
with open(os.path.join(loc, path), 'r') as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def generate_html(output_dir='.', doujinshi_obj=None, template='default'):
|
||||
doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, 'html')
|
||||
image_html = ''
|
||||
|
||||
if not os.path.exists(doujinshi_dir):
|
||||
logger.warning(f'Path "{doujinshi_dir}" does not exist, creating.')
|
||||
try:
|
||||
os.makedirs(doujinshi_dir)
|
||||
except EnvironmentError as e:
|
||||
logger.critical(e)
|
||||
|
||||
file_list = os.listdir(doujinshi_dir)
|
||||
file_list.sort()
|
||||
|
||||
for image in file_list:
|
||||
if not os.path.splitext(image)[1] in EXTENSIONS:
|
||||
continue
|
||||
image_html += f'<img src="{image}" class="image-item"/>\n'
|
||||
|
||||
html = _readfile(f'viewer/{template}/index.html')
|
||||
css = _readfile(f'viewer/{template}/styles.css')
|
||||
js = _readfile(f'viewer/{template}/scripts.js')
|
||||
|
||||
if doujinshi_obj is not None:
|
||||
name = doujinshi_obj.name
|
||||
else:
|
||||
metadata_path = os.path.join(doujinshi_dir, "metadata.json")
|
||||
if os.path.exists(metadata_path):
|
||||
with open(metadata_path, 'r') as file:
|
||||
doujinshi_info = json.loads(file.read())
|
||||
name = doujinshi_info.get("title")
|
||||
else:
|
||||
name = 'Doujinshi HTML Viewer'
|
||||
|
||||
data = html.format(TITLE=name, IMAGES=image_html, SCRIPTS=js, STYLES=css)
|
||||
try:
|
||||
with open(os.path.join(doujinshi_dir, 'index.html'), 'wb') as f:
|
||||
f.write(data.encode('utf-8'))
|
||||
|
||||
logger.log(16, f'HTML Viewer has been written to "{os.path.join(doujinshi_dir, "index.html")}"')
|
||||
except Exception as e:
|
||||
logger.warning(f'Writing HTML Viewer failed ({e})')
|
||||
|
||||
|
||||
def generate_main_html(output_dir=f'.{PATH_SEPARATOR}'):
|
||||
"""
|
||||
Generate a main html to show all the contained doujinshi.
|
||||
With a link to their `index.html`.
|
||||
Default output folder will be the CLI path.
|
||||
"""
|
||||
import shutil
|
||||
|
||||
image_html = ''
|
||||
|
||||
main = _readfile('viewer/main.html')
|
||||
css = _readfile('viewer/main.css')
|
||||
js = _readfile('viewer/main.js')
|
||||
|
||||
element = '\n\
|
||||
<div class="gallery-favorite">\n\
|
||||
<div class="gallery">\n\
|
||||
<a href="./{FOLDER}/index.html" class="cover" style="padding:0 0 141.6% 0"><img\n\
|
||||
src="./{FOLDER}/{IMAGE}" />\n\
|
||||
<div class="caption">{TITLE}</div>\n\
|
||||
</a>\n\
|
||||
</div>\n\
|
||||
</div>\n'
|
||||
|
||||
os.chdir(output_dir)
|
||||
doujinshi_dirs = next(os.walk('.'))[1]
|
||||
|
||||
for folder in doujinshi_dirs:
|
||||
files = os.listdir(folder)
|
||||
files.sort()
|
||||
|
||||
if 'index.html' in files:
|
||||
logger.info(f'Add doujinshi "{folder}"')
|
||||
else:
|
||||
continue
|
||||
|
||||
image = files[0] # 001.jpg or 001.png
|
||||
if folder is not None:
|
||||
title = folder.replace('_', ' ')
|
||||
else:
|
||||
title = 'Doujinshi HTML Viewer'
|
||||
|
||||
image_html += element.format(FOLDER=urllib.parse.quote(folder), IMAGE=image, TITLE=title)
|
||||
if image_html == '':
|
||||
logger.warning('No index.html found, --gen-main paused.')
|
||||
return
|
||||
try:
|
||||
data = main.format(STYLES=css, SCRIPTS=js, PICTURE=image_html)
|
||||
with open('./main.html', 'wb') as f:
|
||||
f.write(data.encode('utf-8'))
|
||||
pkg_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||
shutil.copy(os.path.join(pkg_dir, 'viewer/logo.png'), './')
|
||||
output_dir = output_dir[:-1] if output_dir.endswith('/') else output_dir
|
||||
logger.log(16, f'Main Viewer has been written to "{output_dir}/main.html"')
|
||||
except Exception as e:
|
||||
logger.warning(f'Writing Main Viewer failed ({e})')
|
||||
34
doujinshi_dl/core/utils/http.py
Normal file
34
doujinshi_dl/core/utils/http.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# coding: utf-8
|
||||
"""Generic async HTTP request helper (no site-specific headers injected here)."""
|
||||
import httpx
|
||||
import urllib3.exceptions
|
||||
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
|
||||
async def async_request(method, url, proxy=None, **kwargs):
|
||||
"""
|
||||
Thin async HTTP client wrapper.
|
||||
|
||||
Header injection (Cookie, User-Agent, Referer) is done by callers that
|
||||
have access to site-specific configuration; this helper stays generic.
|
||||
"""
|
||||
from doujinshi_dl import constant
|
||||
|
||||
headers = kwargs.pop('headers', {})
|
||||
|
||||
if proxy is None:
|
||||
proxy = constant.CONFIG.get('proxy', '')
|
||||
|
||||
if isinstance(proxy, str) and not proxy:
|
||||
proxy = None
|
||||
|
||||
# Remove 'timeout' from kwargs to avoid duplicate keyword argument since
|
||||
# httpx.AsyncClient accepts it as a constructor arg or request arg.
|
||||
timeout = kwargs.pop('timeout', 30)
|
||||
|
||||
async with httpx.AsyncClient(headers=headers, verify=False, proxy=proxy,
|
||||
timeout=timeout) as client:
|
||||
response = await client.request(method, url, **kwargs)
|
||||
|
||||
return response
|
||||
5
doujinshi_dl/downloader.py
Normal file
5
doujinshi_dl/downloader.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# coding: utf-8
|
||||
# Compatibility shim — re-exports from new location.
|
||||
# Preserves backward compatibility for: from doujinshi_dl.downloader import Downloader, CompressedDownloader
|
||||
from doujinshi_dl.core.downloader import * # noqa: F401, F403
|
||||
from doujinshi_dl.core.downloader import Downloader, CompressedDownloader, download_callback # noqa: F401
|
||||
5
doujinshi_dl/logger.py
Normal file
5
doujinshi_dl/logger.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# coding: utf-8
|
||||
# Compatibility shim — re-exports from new location.
|
||||
# Preserves backward compatibility for: from doujinshi_dl.logger import logger
|
||||
from doujinshi_dl.core.logger import * # noqa: F401, F403
|
||||
from doujinshi_dl.core.logger import logger # noqa: F401
|
||||
77
doujinshi_dl/utils.py
Normal file
77
doujinshi_dl/utils.py
Normal file
@@ -0,0 +1,77 @@
|
||||
# coding: utf-8
|
||||
# Utility helpers for the main package.
|
||||
# No plugin-specific imports.
|
||||
|
||||
# Generic filesystem / HTML utilities
|
||||
from doujinshi_dl.core.utils.fs import ( # noqa: F401
|
||||
format_filename, parse_doujinshi_obj, generate_cbz, move_to_folder,
|
||||
EXTENSIONS, MAX_FIELD_LENGTH,
|
||||
)
|
||||
from doujinshi_dl.core.utils.html import generate_html, generate_main_html # noqa: F401
|
||||
from doujinshi_dl.core.utils.db import Singleton, DB # noqa: F401
|
||||
|
||||
# Signal handler and paging helper (kept inline — they have no site-specific code)
|
||||
import sys
|
||||
from doujinshi_dl.core.logger import logger # noqa: F401
|
||||
|
||||
|
||||
def signal_handler(_signal, _frame):
|
||||
logger.error('Ctrl-C signal received. Stopping...')
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def paging(page_string):
|
||||
# 1,3-5,14 -> [1, 3, 4, 5, 14]
|
||||
if not page_string:
|
||||
return [1]
|
||||
|
||||
page_list = []
|
||||
for i in page_string.split(','):
|
||||
if '-' in i:
|
||||
start, end = i.split('-')
|
||||
if not (start.isdigit() and end.isdigit()):
|
||||
raise Exception('Invalid page number')
|
||||
page_list.extend(list(range(int(start), int(end) + 1)))
|
||||
else:
|
||||
if not i.isdigit():
|
||||
raise Exception('Invalid page number')
|
||||
page_list.append(int(i))
|
||||
|
||||
return page_list
|
||||
|
||||
|
||||
def generate_doc(file_type='', output_dir='.', doujinshi_obj=None, regenerate=False):
|
||||
"""Generate a CBZ or PDF document from a downloaded doujinshi directory.
|
||||
|
||||
For CBZ, any metadata files (ComicInfo.xml, etc.) should be written to the
|
||||
directory *before* calling this function.
|
||||
"""
|
||||
import os
|
||||
|
||||
doujinshi_dir, filename = parse_doujinshi_obj(output_dir, doujinshi_obj, file_type)
|
||||
|
||||
if os.path.exists(f'{doujinshi_dir}.{file_type}') and not regenerate:
|
||||
logger.info(f'Skipped {file_type} file generation: {doujinshi_dir}.{file_type} already exists')
|
||||
return
|
||||
|
||||
if file_type == 'cbz':
|
||||
generate_cbz(doujinshi_dir, filename)
|
||||
|
||||
elif file_type == 'pdf':
|
||||
try:
|
||||
import img2pdf
|
||||
|
||||
file_list = [f for f in os.listdir(doujinshi_dir) if f.lower().endswith(EXTENSIONS)]
|
||||
file_list.sort()
|
||||
|
||||
logger.info(f'Writing PDF file to path: {filename}')
|
||||
with open(filename, 'wb') as pdf_f:
|
||||
full_path_list = [os.path.join(doujinshi_dir, image) for image in file_list]
|
||||
pdf_f.write(img2pdf.convert(full_path_list, rotation=img2pdf.Rotation.ifvalid))
|
||||
|
||||
logger.log(16, f'PDF file has been written to "{filename}"')
|
||||
|
||||
except ImportError:
|
||||
logger.error("Please install img2pdf package by using pip.")
|
||||
else:
|
||||
raise ValueError('invalid file type')
|
||||
25
doujinshi_dl/viewer/default/index.html
Normal file
25
doujinshi_dl/viewer/default/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>{TITLE}</title>
|
||||
<style>
|
||||
{STYLES}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav id="list">
|
||||
{IMAGES}</nav>
|
||||
|
||||
<div id="image-container">
|
||||
<span id="page-num"></span>
|
||||
<div id="dest"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
{SCRIPTS}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
87
doujinshi_dl/viewer/default/scripts.js
Normal file
87
doujinshi_dl/viewer/default/scripts.js
Normal file
@@ -0,0 +1,87 @@
|
||||
const pages = Array.from(document.querySelectorAll('img.image-item'));
|
||||
let currentPage = 0;
|
||||
|
||||
function changePage(pageNum) {
|
||||
const previous = pages[currentPage];
|
||||
const current = pages[pageNum];
|
||||
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
previous.classList.remove('current');
|
||||
current.classList.add('current');
|
||||
|
||||
currentPage = pageNum;
|
||||
|
||||
const display = document.getElementById('dest');
|
||||
display.style.backgroundImage = `url("${current.src}")`;
|
||||
|
||||
scroll(0,0)
|
||||
|
||||
document.getElementById('page-num')
|
||||
.innerText = [
|
||||
(pageNum + 1).toLocaleString(),
|
||||
pages.length.toLocaleString()
|
||||
].join('\u200a/\u200a');
|
||||
}
|
||||
|
||||
changePage(0);
|
||||
|
||||
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;
|
||||
|
||||
if (clickPos < 0.5) {
|
||||
changePage(currentPage - 1);
|
||||
} else {
|
||||
changePage(currentPage + 1);
|
||||
}
|
||||
};
|
||||
|
||||
document.onkeypress = event => {
|
||||
switch (event.key.toLowerCase()) {
|
||||
// Previous Image
|
||||
case 'w':
|
||||
scrollBy(0, -40);
|
||||
break;
|
||||
case 'a':
|
||||
changePage(currentPage - 1);
|
||||
break;
|
||||
// Return to previous page
|
||||
case 'q':
|
||||
window.history.go(-1);
|
||||
break;
|
||||
// Next Image
|
||||
case ' ':
|
||||
case 's':
|
||||
scrollBy(0, 40);
|
||||
break;
|
||||
case 'd':
|
||||
changePage(currentPage + 1);
|
||||
break;
|
||||
}// remove arrow cause it won't work
|
||||
};
|
||||
|
||||
document.onkeydown = event =>{
|
||||
switch (event.keyCode) {
|
||||
case 37: //left
|
||||
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;
|
||||
}
|
||||
};
|
||||
70
doujinshi_dl/viewer/default/styles.css
Normal file
70
doujinshi_dl/viewer/default/styles.css
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
*, *::after, *::before {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
html, body {
|
||||
display: flex;
|
||||
background-color: #e8e6e6;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#list {
|
||||
height: 2000px;
|
||||
overflow: scroll;
|
||||
width: 260px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#list img {
|
||||
width: 200px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin: 15px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#list img.current {
|
||||
background: #0003;
|
||||
}
|
||||
|
||||
#image-container {
|
||||
flex: auto;
|
||||
height: 2000px;
|
||||
background: #222;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#image-container #dest {
|
||||
height: 2000px;
|
||||
width: 100%;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: top;
|
||||
}
|
||||
|
||||
#image-container #page-num {
|
||||
position: static;
|
||||
font-size: 14pt;
|
||||
left: 10px;
|
||||
bottom: 5px;
|
||||
font-weight: bold;
|
||||
opacity: 0.75;
|
||||
text-shadow: /* Duplicate the same shadow to make it very strong */
|
||||
0 0 2px #222,
|
||||
0 0 2px #222,
|
||||
0 0 2px #222;
|
||||
}
|
||||
BIN
doujinshi_dl/viewer/logo.png
Normal file
BIN
doujinshi_dl/viewer/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
331
doujinshi_dl/viewer/main.css
Normal file
331
doujinshi_dl/viewer/main.css
Normal file
@@ -0,0 +1,331 @@
|
||||
/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */
|
||||
a {
|
||||
background-color: transparent;
|
||||
-webkit-text-decoration-skip: objects
|
||||
}
|
||||
|
||||
img {
|
||||
border-style: none
|
||||
}
|
||||
|
||||
html {
|
||||
box-sizing: border-box
|
||||
}
|
||||
|
||||
*,:after,:before {
|
||||
box-sizing: inherit
|
||||
}
|
||||
|
||||
body,html {
|
||||
font-family: 'Noto Sans',sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.42857143;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
color: #34495e;
|
||||
background-color: #fff;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #34495e
|
||||
}
|
||||
|
||||
blockquote {
|
||||
border: 0
|
||||
}
|
||||
|
||||
.container {
|
||||
display: block;
|
||||
clear: both;
|
||||
margin-left: 15rem;
|
||||
margin-right: 0.5rem;
|
||||
margin-bottom: 5px;
|
||||
margin-top: 5px;
|
||||
padding: 4px;
|
||||
border-radius: 9px;
|
||||
background-color: #ecf0f1;
|
||||
width: 100% - 15rem;
|
||||
max-width: 1500px
|
||||
}
|
||||
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
display: inline-block;
|
||||
vertical-align: top
|
||||
}
|
||||
|
||||
.gallery img,.gallery-favorite img,.thumb-container img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto
|
||||
}
|
||||
|
||||
@media screen and (min-width: 980px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:19%;
|
||||
margin: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 979px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:24%;
|
||||
margin: 2px
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 772px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:32%;
|
||||
margin: 1.5px
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:49%;
|
||||
margin: .5px
|
||||
}
|
||||
}
|
||||
|
||||
.gallery a,.gallery-favorite a {
|
||||
display: block
|
||||
}
|
||||
|
||||
.gallery a img,.gallery-favorite a img {
|
||||
position: absolute
|
||||
}
|
||||
|
||||
.caption {
|
||||
line-height: 15px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 100%;
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
max-height: 34px;
|
||||
padding: 3px;
|
||||
background-color: #fff;
|
||||
font-weight: 700;
|
||||
display: block;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
color: #34495e
|
||||
}
|
||||
|
||||
.gallery {
|
||||
position: relative;
|
||||
margin-bottom: 3em
|
||||
}
|
||||
|
||||
.gallery:hover .caption {
|
||||
max-height: 100%;
|
||||
box-shadow: 0 10px 20px rgba(100,100,100,.5)
|
||||
}
|
||||
|
||||
.gallery-favorite .gallery {
|
||||
width: 100%
|
||||
}
|
||||
|
||||
.sidenav {
|
||||
height: 100%;
|
||||
width: 15rem;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background-color: #0d0d0d;
|
||||
overflow: hidden;
|
||||
|
||||
padding-top: 20px;
|
||||
-webkit-touch-callout: none; /* iOS Safari */
|
||||
-webkit-user-select: none; /* Safari */
|
||||
-khtml-user-select: none; /* Konqueror HTML */
|
||||
-moz-user-select: none; /* Old versions of Firefox */
|
||||
-ms-user-select: none; /* Internet Explorer/Edge */
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.sidenav a {
|
||||
background-color: #eee;
|
||||
padding: 5px 0px 5px 15px;
|
||||
text-decoration: none;
|
||||
font-size: 15px;
|
||||
color: #0d0d0d;
|
||||
display: block;
|
||||
text-align: left;
|
||||
}
|
||||
.sidenav img {
|
||||
width:100%;
|
||||
padding: 0px 5px 0px 5px;
|
||||
|
||||
}
|
||||
|
||||
.sidenav h1 {
|
||||
font-size: 1.5em;
|
||||
margin: 0px 0px 10px;
|
||||
}
|
||||
|
||||
.sidenav a:hover {
|
||||
color: white;
|
||||
background-color: #EC2754;
|
||||
}
|
||||
|
||||
.accordion {
|
||||
font-weight: bold;
|
||||
background-color: #eee;
|
||||
color: #444;
|
||||
padding: 10px 0px 5px 8px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
text-align: left;
|
||||
outline: none;
|
||||
font-size: 15px;
|
||||
transition: 0.4s;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.accordion:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.accordion.active{
|
||||
background-color:#ddd;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
font-weight: bold;
|
||||
background-color: #eee;
|
||||
color: #444;
|
||||
padding: 8px 8px 5px 9px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
text-align: left;
|
||||
outline: none;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.nav-btn a{
|
||||
font-weight: normal;
|
||||
padding-right: 10px;
|
||||
border-radius: 15px;
|
||||
cursor: crosshair
|
||||
}
|
||||
|
||||
.options {
|
||||
display:block;
|
||||
padding: 0px 0px 0px 0px;
|
||||
background-color: #eee;
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.2s ease-out;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.search{
|
||||
background-color: #eee;
|
||||
padding-right:40px;
|
||||
white-space: nowrap;
|
||||
padding-top: 5px;
|
||||
height:43px;
|
||||
|
||||
}
|
||||
|
||||
.search input{
|
||||
border-top-right-radius:10px;
|
||||
padding-top:0;
|
||||
padding-bottom:0;
|
||||
font-size:1em;
|
||||
width:100%;
|
||||
height:38px;
|
||||
vertical-align:top;
|
||||
}
|
||||
|
||||
.btn{
|
||||
border-top-left-radius:10px;
|
||||
color:#fff;
|
||||
font-size:100%;
|
||||
padding: 8px;
|
||||
width:38px;
|
||||
background-color:#ed2553;
|
||||
}
|
||||
|
||||
#tags{
|
||||
text-align:left;
|
||||
display: flex;
|
||||
width:15rem;
|
||||
justify-content: start;
|
||||
margin: 2px 2px 2px 0px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.btn-2{
|
||||
font-weight:700;
|
||||
padding-right:0.5rem;
|
||||
padding-left:0.5rem;
|
||||
color:#fff;
|
||||
border:0;
|
||||
font-size:100%;
|
||||
height:1.25rem;
|
||||
outline: 0;
|
||||
border-radius: 0.3rem;
|
||||
cursor: pointer;
|
||||
margin:0.15rem;
|
||||
transition: all 1s linear;
|
||||
}
|
||||
|
||||
.btn-2#parody{
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.btn-2#character{
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.btn-2#tag{
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.btn-2#artist{
|
||||
background-color: fuchsia;
|
||||
}
|
||||
|
||||
.btn-2#group{
|
||||
background-color: teal;
|
||||
}
|
||||
|
||||
.btn-2.hover{
|
||||
filter: saturate(20%)
|
||||
}
|
||||
|
||||
input,input:focus{
|
||||
border:none;
|
||||
outline:0;
|
||||
}
|
||||
|
||||
html.theme-black,html.theme-black body {
|
||||
color: #d9d9d9;
|
||||
background-color: #0d0d0d
|
||||
}
|
||||
|
||||
html.theme-black #thumbnail-container,html.theme-black .container {
|
||||
background-color: #1f1f1f
|
||||
}
|
||||
|
||||
html.theme-black .gallery:hover .caption {
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,.5)
|
||||
}
|
||||
|
||||
html.theme-black .caption {
|
||||
background-color: #404040;
|
||||
color: #d9d9d9
|
||||
}
|
||||
51
doujinshi_dl/viewer/main.html
Normal file
51
doujinshi_dl/viewer/main.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!doctype html>
|
||||
<html lang="en" class=" theme-black">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="theme-color" content="#1f1f1f" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>Doujinshi Viewer</title>
|
||||
<script type="text/javascript" src="data.js"></script>
|
||||
<!-- <link rel="stylesheet" href="./main.css"> -->
|
||||
<style>
|
||||
{STYLES}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">
|
||||
<nav class="sidenav">
|
||||
<img src="logo.png">
|
||||
<h1>Doujinshi Viewer</h1>
|
||||
<button class="accordion">Language</button>
|
||||
<div class="options" id="language">
|
||||
<a>English</a>
|
||||
<a>Japanese</a>
|
||||
<a>Chinese</a>
|
||||
</div>
|
||||
<button class="accordion">Category</button>
|
||||
<div class="options" id ="category">
|
||||
<a>Doujinshi</a>
|
||||
<a>Manga</a>
|
||||
</div>
|
||||
<button class="nav-btn hidden">Filters</button>
|
||||
<div class="search">
|
||||
<input autocomplete="off" type="search" id="tagfilter" name="q" value="" autocapitalize="none" required="">
|
||||
<svg class="btn" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="white" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"/></svg>
|
||||
<div id="tags">
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container" id="favcontainer">
|
||||
|
||||
{PICTURE}
|
||||
|
||||
</div> <!-- container -->
|
||||
|
||||
</div>
|
||||
<script>
|
||||
{SCRIPTS}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
177
doujinshi_dl/viewer/main.js
Normal file
177
doujinshi_dl/viewer/main.js
Normal file
@@ -0,0 +1,177 @@
|
||||
//------------------------------------navbar script------------------------------------
|
||||
var menu = document.getElementsByClassName("accordion");
|
||||
for (var i = 0; i < menu.length; i++) {
|
||||
menu[i].addEventListener("click", function() {
|
||||
var panel = this.nextElementSibling;
|
||||
if (panel.style.maxHeight) {
|
||||
this.classList.toggle("active");
|
||||
panel.style.maxHeight = null;
|
||||
} else {
|
||||
panel.style.maxHeight = panel.scrollHeight + "px";
|
||||
this.classList.toggle("active");
|
||||
}
|
||||
});
|
||||
}
|
||||
var language = document.getElementById("language").children;
|
||||
for (var i = 0; i < language.length; i++){
|
||||
language[i].addEventListener("click", function() {
|
||||
toggler = document.getElementById("language")
|
||||
toggler.style.maxHeight = null;
|
||||
document.getElementsByClassName("accordion")[0].classList.toggle("active");
|
||||
filter_maker(this.innerText, "language");
|
||||
});
|
||||
}
|
||||
var category = document.getElementById("category").children;
|
||||
for (var i = 0; i < category.length; i++){
|
||||
category[i].addEventListener("click", function() {
|
||||
document.getElementById("category").style.maxHeight = null;
|
||||
document.getElementsByClassName("accordion")[1].classList.toggle("active");
|
||||
filter_maker(this.innerText, "category");
|
||||
});
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
//----------------------------------Tags Script--------------------------------------
|
||||
tag_maker(tags);
|
||||
|
||||
var tag = document.getElementsByClassName("btn-2");
|
||||
for (var i = 0; i < tag.length; i++){
|
||||
tag[i].addEventListener("click", function() {
|
||||
filter_maker(this.innerText, this.id);
|
||||
});
|
||||
}
|
||||
|
||||
var input = document.getElementById("tagfilter");
|
||||
input.addEventListener("input", function() {
|
||||
var tags = document.querySelectorAll(".btn-2");
|
||||
if (this.value.length > 0) {
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
var tag = tags[i];
|
||||
var nome = tag.innerText;
|
||||
var exp = new RegExp(this.value, "i");;
|
||||
if (exp.test(nome)) {
|
||||
tag.classList.remove("hidden");
|
||||
}
|
||||
else {
|
||||
tag.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
var tag = tags[i];
|
||||
tag.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
input.addEventListener('keypress', function (e) {
|
||||
enter_search(e, this.value);
|
||||
});
|
||||
//-----------------------------------------------------------------------------------
|
||||
//------------------------------------Functions--------------------------------------
|
||||
function enter_search(e, input){
|
||||
var count = 0;
|
||||
var key = e.which || e.keyCode;
|
||||
if (key === 13 && input.length > 0) {
|
||||
var all_tags = document.getElementById("tags").children;
|
||||
for(i = 0; i < all_tags.length; i++){
|
||||
if (!all_tags[i].classList.contains("hidden")){
|
||||
count++;
|
||||
var tag_name = all_tags[i].innerText;
|
||||
var tag_id = all_tags[i].id;
|
||||
if (count>1){break}
|
||||
}
|
||||
}
|
||||
if (count == 1){
|
||||
filter_maker(tag_name, tag_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
function filter_maker(text, class_value){
|
||||
var check = filter_checker(text);
|
||||
var nav_btn = document.getElementsByClassName("nav-btn")[0];
|
||||
if (nav_btn.classList.contains("hidden")){
|
||||
nav_btn.classList.toggle("hidden");
|
||||
}
|
||||
if (check == true){
|
||||
var node = document.createElement("a");
|
||||
var textnode = document.createTextNode(text);
|
||||
node.appendChild(textnode);
|
||||
node.classList.add(class_value);
|
||||
nav_btn.appendChild(node);
|
||||
filter_searcher();
|
||||
}
|
||||
}
|
||||
|
||||
function filter_searcher(){
|
||||
var verifier = null;
|
||||
var tags_filter = [];
|
||||
var doujinshi_id = [];
|
||||
var filter_tag = document.getElementsByClassName("nav-btn")[0].children;
|
||||
filter_tag[filter_tag.length-1].addEventListener("click", function() {
|
||||
this.remove();
|
||||
try{
|
||||
filter_searcher();
|
||||
}
|
||||
catch{
|
||||
var gallery = document.getElementsByClassName("gallery-favorite");
|
||||
for (var i = 0; i < gallery.length; i++){
|
||||
gallery[i].classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
});
|
||||
for (var i=0; i < filter_tag.length; i++){
|
||||
var fclass = filter_tag[i].className;
|
||||
var fname = filter_tag[i].innerText.toLowerCase();
|
||||
tags_filter.push([fclass, fname])
|
||||
}
|
||||
for (var i=0; i < data.length; i++){
|
||||
for (var j=0; j < tags_filter.length; j++){
|
||||
try{
|
||||
if(data[i][tags_filter[j][0]].includes(tags_filter[j][1])){
|
||||
verifier = true;
|
||||
}
|
||||
else{
|
||||
verifier = false;
|
||||
break
|
||||
}
|
||||
}
|
||||
catch{
|
||||
verifier = false;
|
||||
break
|
||||
}
|
||||
}
|
||||
if (verifier){doujinshi_id.push(data[i].Folder.replace("_", " "));}
|
||||
}
|
||||
var gallery = document.getElementsByClassName("gallery-favorite");
|
||||
for (var i = 0; i < gallery.length; i++){
|
||||
gtext = gallery [i].children[0].children[0].children[1].innerText;
|
||||
if(doujinshi_id.includes(gtext)){
|
||||
gallery[i].classList.remove("hidden");
|
||||
}
|
||||
else{
|
||||
gallery[i].classList.add("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filter_checker(text){
|
||||
var filter_tags = document.getElementsByClassName("nav-btn")[0].children;
|
||||
if (filter_tags == null){return true;}
|
||||
for (var i=0; i < filter_tags.length; i++){
|
||||
if (filter_tags[i].innerText == text){return false;}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function tag_maker(data){
|
||||
for (i in data){
|
||||
for (j in data[i]){
|
||||
var node = document.createElement("button");
|
||||
var textnode = document.createTextNode(data[i][j]);
|
||||
node.appendChild(textnode);
|
||||
node.classList.add("btn-2");
|
||||
node.setAttribute('id', i);
|
||||
node.classList.add("hidden");
|
||||
document.getElementById("tags").appendChild(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
doujinshi_dl/viewer/minimal/index.html
Normal file
25
doujinshi_dl/viewer/minimal/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>{TITLE}</title>
|
||||
<style>
|
||||
{STYLES}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav id="list" hidden=true>
|
||||
{IMAGES}</nav>
|
||||
|
||||
<div id="image-container">
|
||||
<div id="dest"></div>
|
||||
<span id="page-num"></span>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
{SCRIPTS}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
79
doujinshi_dl/viewer/minimal/scripts.js
Normal file
79
doujinshi_dl/viewer/minimal/scripts.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const pages = Array.from(document.querySelectorAll('img.image-item'));
|
||||
let currentPage = 0;
|
||||
|
||||
function changePage(pageNum) {
|
||||
const previous = pages[currentPage];
|
||||
const current = pages[pageNum];
|
||||
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
previous.classList.remove('current');
|
||||
current.classList.add('current');
|
||||
|
||||
currentPage = pageNum;
|
||||
|
||||
const display = document.getElementById('dest');
|
||||
display.style.backgroundImage = `url("${current.src}")`;
|
||||
|
||||
scroll(0,0)
|
||||
|
||||
document.getElementById('page-num')
|
||||
.innerText = [
|
||||
(pageNum + 1).toLocaleString(),
|
||||
pages.length.toLocaleString()
|
||||
].join('\u200a/\u200a');
|
||||
}
|
||||
|
||||
changePage(0);
|
||||
|
||||
document.getElementById('image-container').onclick = event => {
|
||||
const width = document.getElementById('image-container').clientWidth;
|
||||
const clickPos = event.clientX / width;
|
||||
|
||||
if (clickPos < 0.5) {
|
||||
changePage(currentPage - 1);
|
||||
} else {
|
||||
changePage(currentPage + 1);
|
||||
}
|
||||
};
|
||||
|
||||
document.onkeypress = event => {
|
||||
switch (event.key.toLowerCase()) {
|
||||
// Previous Image
|
||||
case 'w':
|
||||
scrollBy(0, -40);
|
||||
break;
|
||||
case 'a':
|
||||
changePage(currentPage - 1);
|
||||
break;
|
||||
// Return to previous page
|
||||
case 'q':
|
||||
window.history.go(-1);
|
||||
break;
|
||||
// Next Image
|
||||
case ' ':
|
||||
case 's':
|
||||
scrollBy(0, 40);
|
||||
break;
|
||||
case 'd':
|
||||
changePage(currentPage + 1);
|
||||
break;
|
||||
}// remove arrow cause it won't work
|
||||
};
|
||||
|
||||
document.onkeydown = event =>{
|
||||
switch (event.keyCode) {
|
||||
case 37: //left
|
||||
changePage(currentPage - 1);
|
||||
break;
|
||||
case 38: //up
|
||||
break;
|
||||
case 39: //right
|
||||
changePage(currentPage + 1);
|
||||
break;
|
||||
case 40: //down
|
||||
break;
|
||||
}
|
||||
};
|
||||
75
doujinshi_dl/viewer/minimal/styles.css
Normal file
75
doujinshi_dl/viewer/minimal/styles.css
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
*, *::after, *::before {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
html, body {
|
||||
display: flex;
|
||||
background-color: #e8e6e6;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#list {
|
||||
height: 2000px;
|
||||
overflow: scroll;
|
||||
width: 260px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#list img {
|
||||
width: 200px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin: 15px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#list img.current {
|
||||
background: #0003;
|
||||
}
|
||||
|
||||
#image-container {
|
||||
flex: auto;
|
||||
height: 100%;
|
||||
background: rgb(0, 0, 0);
|
||||
color: rgb(100, 100, 100);
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#image-container #dest {
|
||||
height: 2000px;
|
||||
width: 100%;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: top;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 100%;
|
||||
max-height: 100vh;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
#image-container #page-num {
|
||||
position: static;
|
||||
font-size: 9pt;
|
||||
left: 10px;
|
||||
bottom: 5px;
|
||||
font-weight: bold;
|
||||
opacity: 0.9;
|
||||
text-shadow: /* Duplicate the same shadow to make it very strong */
|
||||
0 0 2px #222,
|
||||
0 0 2px #222,
|
||||
0 0 2px #222;
|
||||
}
|
||||
25
doujinshi_dl/viewer/viewer/default/index.html
Normal file
25
doujinshi_dl/viewer/viewer/default/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>{TITLE}</title>
|
||||
<style>
|
||||
{STYLES}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav id="list">
|
||||
{IMAGES}</nav>
|
||||
|
||||
<div id="image-container">
|
||||
<span id="page-num"></span>
|
||||
<div id="dest"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
{SCRIPTS}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
87
doujinshi_dl/viewer/viewer/default/scripts.js
Normal file
87
doujinshi_dl/viewer/viewer/default/scripts.js
Normal file
@@ -0,0 +1,87 @@
|
||||
const pages = Array.from(document.querySelectorAll('img.image-item'));
|
||||
let currentPage = 0;
|
||||
|
||||
function changePage(pageNum) {
|
||||
const previous = pages[currentPage];
|
||||
const current = pages[pageNum];
|
||||
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
previous.classList.remove('current');
|
||||
current.classList.add('current');
|
||||
|
||||
currentPage = pageNum;
|
||||
|
||||
const display = document.getElementById('dest');
|
||||
display.style.backgroundImage = `url("${current.src}")`;
|
||||
|
||||
scroll(0,0)
|
||||
|
||||
document.getElementById('page-num')
|
||||
.innerText = [
|
||||
(pageNum + 1).toLocaleString(),
|
||||
pages.length.toLocaleString()
|
||||
].join('\u200a/\u200a');
|
||||
}
|
||||
|
||||
changePage(0);
|
||||
|
||||
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;
|
||||
|
||||
if (clickPos < 0.5) {
|
||||
changePage(currentPage - 1);
|
||||
} else {
|
||||
changePage(currentPage + 1);
|
||||
}
|
||||
};
|
||||
|
||||
document.onkeypress = event => {
|
||||
switch (event.key.toLowerCase()) {
|
||||
// Previous Image
|
||||
case 'w':
|
||||
scrollBy(0, -40);
|
||||
break;
|
||||
case 'a':
|
||||
changePage(currentPage - 1);
|
||||
break;
|
||||
// Return to previous page
|
||||
case 'q':
|
||||
window.history.go(-1);
|
||||
break;
|
||||
// Next Image
|
||||
case ' ':
|
||||
case 's':
|
||||
scrollBy(0, 40);
|
||||
break;
|
||||
case 'd':
|
||||
changePage(currentPage + 1);
|
||||
break;
|
||||
}// remove arrow cause it won't work
|
||||
};
|
||||
|
||||
document.onkeydown = event =>{
|
||||
switch (event.keyCode) {
|
||||
case 37: //left
|
||||
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;
|
||||
}
|
||||
};
|
||||
70
doujinshi_dl/viewer/viewer/default/styles.css
Normal file
70
doujinshi_dl/viewer/viewer/default/styles.css
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
*, *::after, *::before {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
html, body {
|
||||
display: flex;
|
||||
background-color: #e8e6e6;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#list {
|
||||
height: 2000px;
|
||||
overflow: scroll;
|
||||
width: 260px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#list img {
|
||||
width: 200px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin: 15px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#list img.current {
|
||||
background: #0003;
|
||||
}
|
||||
|
||||
#image-container {
|
||||
flex: auto;
|
||||
height: 2000px;
|
||||
background: #222;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#image-container #dest {
|
||||
height: 2000px;
|
||||
width: 100%;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: top;
|
||||
}
|
||||
|
||||
#image-container #page-num {
|
||||
position: static;
|
||||
font-size: 14pt;
|
||||
left: 10px;
|
||||
bottom: 5px;
|
||||
font-weight: bold;
|
||||
opacity: 0.75;
|
||||
text-shadow: /* Duplicate the same shadow to make it very strong */
|
||||
0 0 2px #222,
|
||||
0 0 2px #222,
|
||||
0 0 2px #222;
|
||||
}
|
||||
BIN
doujinshi_dl/viewer/viewer/logo.png
Normal file
BIN
doujinshi_dl/viewer/viewer/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
331
doujinshi_dl/viewer/viewer/main.css
Normal file
331
doujinshi_dl/viewer/viewer/main.css
Normal file
@@ -0,0 +1,331 @@
|
||||
/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */
|
||||
a {
|
||||
background-color: transparent;
|
||||
-webkit-text-decoration-skip: objects
|
||||
}
|
||||
|
||||
img {
|
||||
border-style: none
|
||||
}
|
||||
|
||||
html {
|
||||
box-sizing: border-box
|
||||
}
|
||||
|
||||
*,:after,:before {
|
||||
box-sizing: inherit
|
||||
}
|
||||
|
||||
body,html {
|
||||
font-family: 'Noto Sans',sans-serif;
|
||||
font-size: 14px;
|
||||
line-height: 1.42857143;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
color: #34495e;
|
||||
background-color: #fff;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #34495e
|
||||
}
|
||||
|
||||
blockquote {
|
||||
border: 0
|
||||
}
|
||||
|
||||
.container {
|
||||
display: block;
|
||||
clear: both;
|
||||
margin-left: 15rem;
|
||||
margin-right: 0.5rem;
|
||||
margin-bottom: 5px;
|
||||
margin-top: 5px;
|
||||
padding: 4px;
|
||||
border-radius: 9px;
|
||||
background-color: #ecf0f1;
|
||||
width: 100% - 15rem;
|
||||
max-width: 1500px
|
||||
}
|
||||
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
display: inline-block;
|
||||
vertical-align: top
|
||||
}
|
||||
|
||||
.gallery img,.gallery-favorite img,.thumb-container img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto
|
||||
}
|
||||
|
||||
@media screen and (min-width: 980px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:19%;
|
||||
margin: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 979px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:24%;
|
||||
margin: 2px
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 772px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:32%;
|
||||
margin: 1.5px
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
.gallery,.gallery-favorite,.thumb-container {
|
||||
width:49%;
|
||||
margin: .5px
|
||||
}
|
||||
}
|
||||
|
||||
.gallery a,.gallery-favorite a {
|
||||
display: block
|
||||
}
|
||||
|
||||
.gallery a img,.gallery-favorite a img {
|
||||
position: absolute
|
||||
}
|
||||
|
||||
.caption {
|
||||
line-height: 15px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 100%;
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
max-height: 34px;
|
||||
padding: 3px;
|
||||
background-color: #fff;
|
||||
font-weight: 700;
|
||||
display: block;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
color: #34495e
|
||||
}
|
||||
|
||||
.gallery {
|
||||
position: relative;
|
||||
margin-bottom: 3em
|
||||
}
|
||||
|
||||
.gallery:hover .caption {
|
||||
max-height: 100%;
|
||||
box-shadow: 0 10px 20px rgba(100,100,100,.5)
|
||||
}
|
||||
|
||||
.gallery-favorite .gallery {
|
||||
width: 100%
|
||||
}
|
||||
|
||||
.sidenav {
|
||||
height: 100%;
|
||||
width: 15rem;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
top: 0;
|
||||
left: 0;
|
||||
background-color: #0d0d0d;
|
||||
overflow: hidden;
|
||||
|
||||
padding-top: 20px;
|
||||
-webkit-touch-callout: none; /* iOS Safari */
|
||||
-webkit-user-select: none; /* Safari */
|
||||
-khtml-user-select: none; /* Konqueror HTML */
|
||||
-moz-user-select: none; /* Old versions of Firefox */
|
||||
-ms-user-select: none; /* Internet Explorer/Edge */
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.sidenav a {
|
||||
background-color: #eee;
|
||||
padding: 5px 0px 5px 15px;
|
||||
text-decoration: none;
|
||||
font-size: 15px;
|
||||
color: #0d0d0d;
|
||||
display: block;
|
||||
text-align: left;
|
||||
}
|
||||
.sidenav img {
|
||||
width:100%;
|
||||
padding: 0px 5px 0px 5px;
|
||||
|
||||
}
|
||||
|
||||
.sidenav h1 {
|
||||
font-size: 1.5em;
|
||||
margin: 0px 0px 10px;
|
||||
}
|
||||
|
||||
.sidenav a:hover {
|
||||
color: white;
|
||||
background-color: #EC2754;
|
||||
}
|
||||
|
||||
.accordion {
|
||||
font-weight: bold;
|
||||
background-color: #eee;
|
||||
color: #444;
|
||||
padding: 10px 0px 5px 8px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
text-align: left;
|
||||
outline: none;
|
||||
font-size: 15px;
|
||||
transition: 0.4s;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.accordion:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.accordion.active{
|
||||
background-color:#ddd;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
font-weight: bold;
|
||||
background-color: #eee;
|
||||
color: #444;
|
||||
padding: 8px 8px 5px 9px;
|
||||
width: 100%;
|
||||
border: none;
|
||||
text-align: left;
|
||||
outline: none;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display:none;
|
||||
}
|
||||
|
||||
.nav-btn a{
|
||||
font-weight: normal;
|
||||
padding-right: 10px;
|
||||
border-radius: 15px;
|
||||
cursor: crosshair
|
||||
}
|
||||
|
||||
.options {
|
||||
display:block;
|
||||
padding: 0px 0px 0px 0px;
|
||||
background-color: #eee;
|
||||
max-height: 0;
|
||||
overflow: hidden;
|
||||
transition: max-height 0.2s ease-out;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.search{
|
||||
background-color: #eee;
|
||||
padding-right:40px;
|
||||
white-space: nowrap;
|
||||
padding-top: 5px;
|
||||
height:43px;
|
||||
|
||||
}
|
||||
|
||||
.search input{
|
||||
border-top-right-radius:10px;
|
||||
padding-top:0;
|
||||
padding-bottom:0;
|
||||
font-size:1em;
|
||||
width:100%;
|
||||
height:38px;
|
||||
vertical-align:top;
|
||||
}
|
||||
|
||||
.btn{
|
||||
border-top-left-radius:10px;
|
||||
color:#fff;
|
||||
font-size:100%;
|
||||
padding: 8px;
|
||||
width:38px;
|
||||
background-color:#ed2553;
|
||||
}
|
||||
|
||||
#tags{
|
||||
text-align:left;
|
||||
display: flex;
|
||||
width:15rem;
|
||||
justify-content: start;
|
||||
margin: 2px 2px 2px 0px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.btn-2{
|
||||
font-weight:700;
|
||||
padding-right:0.5rem;
|
||||
padding-left:0.5rem;
|
||||
color:#fff;
|
||||
border:0;
|
||||
font-size:100%;
|
||||
height:1.25rem;
|
||||
outline: 0;
|
||||
border-radius: 0.3rem;
|
||||
cursor: pointer;
|
||||
margin:0.15rem;
|
||||
transition: all 1s linear;
|
||||
}
|
||||
|
||||
.btn-2#parody{
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.btn-2#character{
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.btn-2#tag{
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.btn-2#artist{
|
||||
background-color: fuchsia;
|
||||
}
|
||||
|
||||
.btn-2#group{
|
||||
background-color: teal;
|
||||
}
|
||||
|
||||
.btn-2.hover{
|
||||
filter: saturate(20%)
|
||||
}
|
||||
|
||||
input,input:focus{
|
||||
border:none;
|
||||
outline:0;
|
||||
}
|
||||
|
||||
html.theme-black,html.theme-black body {
|
||||
color: #d9d9d9;
|
||||
background-color: #0d0d0d
|
||||
}
|
||||
|
||||
html.theme-black #thumbnail-container,html.theme-black .container {
|
||||
background-color: #1f1f1f
|
||||
}
|
||||
|
||||
html.theme-black .gallery:hover .caption {
|
||||
box-shadow: 0 10px 20px rgba(0,0,0,.5)
|
||||
}
|
||||
|
||||
html.theme-black .caption {
|
||||
background-color: #404040;
|
||||
color: #d9d9d9
|
||||
}
|
||||
51
doujinshi_dl/viewer/viewer/main.html
Normal file
51
doujinshi_dl/viewer/viewer/main.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!doctype html>
|
||||
<html lang="en" class=" theme-black">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="theme-color" content="#1f1f1f" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>Doujinshi Viewer</title>
|
||||
<script type="text/javascript" src="data.js"></script>
|
||||
<!-- <link rel="stylesheet" href="./main.css"> -->
|
||||
<style>
|
||||
{STYLES}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">
|
||||
<nav class="sidenav">
|
||||
<img src="logo.png">
|
||||
<h1>Doujinshi Viewer</h1>
|
||||
<button class="accordion">Language</button>
|
||||
<div class="options" id="language">
|
||||
<a>English</a>
|
||||
<a>Japanese</a>
|
||||
<a>Chinese</a>
|
||||
</div>
|
||||
<button class="accordion">Category</button>
|
||||
<div class="options" id ="category">
|
||||
<a>Doujinshi</a>
|
||||
<a>Manga</a>
|
||||
</div>
|
||||
<button class="nav-btn hidden">Filters</button>
|
||||
<div class="search">
|
||||
<input autocomplete="off" type="search" id="tagfilter" name="q" value="" autocapitalize="none" required="">
|
||||
<svg class="btn" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="white" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"/></svg>
|
||||
<div id="tags">
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container" id="favcontainer">
|
||||
|
||||
{PICTURE}
|
||||
|
||||
</div> <!-- container -->
|
||||
|
||||
</div>
|
||||
<script>
|
||||
{SCRIPTS}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
177
doujinshi_dl/viewer/viewer/main.js
Normal file
177
doujinshi_dl/viewer/viewer/main.js
Normal file
@@ -0,0 +1,177 @@
|
||||
//------------------------------------navbar script------------------------------------
|
||||
var menu = document.getElementsByClassName("accordion");
|
||||
for (var i = 0; i < menu.length; i++) {
|
||||
menu[i].addEventListener("click", function() {
|
||||
var panel = this.nextElementSibling;
|
||||
if (panel.style.maxHeight) {
|
||||
this.classList.toggle("active");
|
||||
panel.style.maxHeight = null;
|
||||
} else {
|
||||
panel.style.maxHeight = panel.scrollHeight + "px";
|
||||
this.classList.toggle("active");
|
||||
}
|
||||
});
|
||||
}
|
||||
var language = document.getElementById("language").children;
|
||||
for (var i = 0; i < language.length; i++){
|
||||
language[i].addEventListener("click", function() {
|
||||
toggler = document.getElementById("language")
|
||||
toggler.style.maxHeight = null;
|
||||
document.getElementsByClassName("accordion")[0].classList.toggle("active");
|
||||
filter_maker(this.innerText, "language");
|
||||
});
|
||||
}
|
||||
var category = document.getElementById("category").children;
|
||||
for (var i = 0; i < category.length; i++){
|
||||
category[i].addEventListener("click", function() {
|
||||
document.getElementById("category").style.maxHeight = null;
|
||||
document.getElementsByClassName("accordion")[1].classList.toggle("active");
|
||||
filter_maker(this.innerText, "category");
|
||||
});
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
//----------------------------------Tags Script--------------------------------------
|
||||
tag_maker(tags);
|
||||
|
||||
var tag = document.getElementsByClassName("btn-2");
|
||||
for (var i = 0; i < tag.length; i++){
|
||||
tag[i].addEventListener("click", function() {
|
||||
filter_maker(this.innerText, this.id);
|
||||
});
|
||||
}
|
||||
|
||||
var input = document.getElementById("tagfilter");
|
||||
input.addEventListener("input", function() {
|
||||
var tags = document.querySelectorAll(".btn-2");
|
||||
if (this.value.length > 0) {
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
var tag = tags[i];
|
||||
var nome = tag.innerText;
|
||||
var exp = new RegExp(this.value, "i");;
|
||||
if (exp.test(nome)) {
|
||||
tag.classList.remove("hidden");
|
||||
}
|
||||
else {
|
||||
tag.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
var tag = tags[i];
|
||||
tag.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
input.addEventListener('keypress', function (e) {
|
||||
enter_search(e, this.value);
|
||||
});
|
||||
//-----------------------------------------------------------------------------------
|
||||
//------------------------------------Functions--------------------------------------
|
||||
function enter_search(e, input){
|
||||
var count = 0;
|
||||
var key = e.which || e.keyCode;
|
||||
if (key === 13 && input.length > 0) {
|
||||
var all_tags = document.getElementById("tags").children;
|
||||
for(i = 0; i < all_tags.length; i++){
|
||||
if (!all_tags[i].classList.contains("hidden")){
|
||||
count++;
|
||||
var tag_name = all_tags[i].innerText;
|
||||
var tag_id = all_tags[i].id;
|
||||
if (count>1){break}
|
||||
}
|
||||
}
|
||||
if (count == 1){
|
||||
filter_maker(tag_name, tag_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
function filter_maker(text, class_value){
|
||||
var check = filter_checker(text);
|
||||
var nav_btn = document.getElementsByClassName("nav-btn")[0];
|
||||
if (nav_btn.classList.contains("hidden")){
|
||||
nav_btn.classList.toggle("hidden");
|
||||
}
|
||||
if (check == true){
|
||||
var node = document.createElement("a");
|
||||
var textnode = document.createTextNode(text);
|
||||
node.appendChild(textnode);
|
||||
node.classList.add(class_value);
|
||||
nav_btn.appendChild(node);
|
||||
filter_searcher();
|
||||
}
|
||||
}
|
||||
|
||||
function filter_searcher(){
|
||||
var verifier = null;
|
||||
var tags_filter = [];
|
||||
var doujinshi_id = [];
|
||||
var filter_tag = document.getElementsByClassName("nav-btn")[0].children;
|
||||
filter_tag[filter_tag.length-1].addEventListener("click", function() {
|
||||
this.remove();
|
||||
try{
|
||||
filter_searcher();
|
||||
}
|
||||
catch{
|
||||
var gallery = document.getElementsByClassName("gallery-favorite");
|
||||
for (var i = 0; i < gallery.length; i++){
|
||||
gallery[i].classList.remove("hidden");
|
||||
}
|
||||
}
|
||||
});
|
||||
for (var i=0; i < filter_tag.length; i++){
|
||||
var fclass = filter_tag[i].className;
|
||||
var fname = filter_tag[i].innerText.toLowerCase();
|
||||
tags_filter.push([fclass, fname])
|
||||
}
|
||||
for (var i=0; i < data.length; i++){
|
||||
for (var j=0; j < tags_filter.length; j++){
|
||||
try{
|
||||
if(data[i][tags_filter[j][0]].includes(tags_filter[j][1])){
|
||||
verifier = true;
|
||||
}
|
||||
else{
|
||||
verifier = false;
|
||||
break
|
||||
}
|
||||
}
|
||||
catch{
|
||||
verifier = false;
|
||||
break
|
||||
}
|
||||
}
|
||||
if (verifier){doujinshi_id.push(data[i].Folder.replace("_", " "));}
|
||||
}
|
||||
var gallery = document.getElementsByClassName("gallery-favorite");
|
||||
for (var i = 0; i < gallery.length; i++){
|
||||
gtext = gallery [i].children[0].children[0].children[1].innerText;
|
||||
if(doujinshi_id.includes(gtext)){
|
||||
gallery[i].classList.remove("hidden");
|
||||
}
|
||||
else{
|
||||
gallery[i].classList.add("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filter_checker(text){
|
||||
var filter_tags = document.getElementsByClassName("nav-btn")[0].children;
|
||||
if (filter_tags == null){return true;}
|
||||
for (var i=0; i < filter_tags.length; i++){
|
||||
if (filter_tags[i].innerText == text){return false;}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function tag_maker(data){
|
||||
for (i in data){
|
||||
for (j in data[i]){
|
||||
var node = document.createElement("button");
|
||||
var textnode = document.createTextNode(data[i][j]);
|
||||
node.appendChild(textnode);
|
||||
node.classList.add("btn-2");
|
||||
node.setAttribute('id', i);
|
||||
node.classList.add("hidden");
|
||||
document.getElementById("tags").appendChild(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
doujinshi_dl/viewer/viewer/minimal/index.html
Normal file
25
doujinshi_dl/viewer/viewer/minimal/index.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, viewport-fit=cover" />
|
||||
<title>{TITLE}</title>
|
||||
<style>
|
||||
{STYLES}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav id="list" hidden=true>
|
||||
{IMAGES}</nav>
|
||||
|
||||
<div id="image-container">
|
||||
<div id="dest"></div>
|
||||
<span id="page-num"></span>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
{SCRIPTS}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
79
doujinshi_dl/viewer/viewer/minimal/scripts.js
Normal file
79
doujinshi_dl/viewer/viewer/minimal/scripts.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const pages = Array.from(document.querySelectorAll('img.image-item'));
|
||||
let currentPage = 0;
|
||||
|
||||
function changePage(pageNum) {
|
||||
const previous = pages[currentPage];
|
||||
const current = pages[pageNum];
|
||||
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
previous.classList.remove('current');
|
||||
current.classList.add('current');
|
||||
|
||||
currentPage = pageNum;
|
||||
|
||||
const display = document.getElementById('dest');
|
||||
display.style.backgroundImage = `url("${current.src}")`;
|
||||
|
||||
scroll(0,0)
|
||||
|
||||
document.getElementById('page-num')
|
||||
.innerText = [
|
||||
(pageNum + 1).toLocaleString(),
|
||||
pages.length.toLocaleString()
|
||||
].join('\u200a/\u200a');
|
||||
}
|
||||
|
||||
changePage(0);
|
||||
|
||||
document.getElementById('image-container').onclick = event => {
|
||||
const width = document.getElementById('image-container').clientWidth;
|
||||
const clickPos = event.clientX / width;
|
||||
|
||||
if (clickPos < 0.5) {
|
||||
changePage(currentPage - 1);
|
||||
} else {
|
||||
changePage(currentPage + 1);
|
||||
}
|
||||
};
|
||||
|
||||
document.onkeypress = event => {
|
||||
switch (event.key.toLowerCase()) {
|
||||
// Previous Image
|
||||
case 'w':
|
||||
scrollBy(0, -40);
|
||||
break;
|
||||
case 'a':
|
||||
changePage(currentPage - 1);
|
||||
break;
|
||||
// Return to previous page
|
||||
case 'q':
|
||||
window.history.go(-1);
|
||||
break;
|
||||
// Next Image
|
||||
case ' ':
|
||||
case 's':
|
||||
scrollBy(0, 40);
|
||||
break;
|
||||
case 'd':
|
||||
changePage(currentPage + 1);
|
||||
break;
|
||||
}// remove arrow cause it won't work
|
||||
};
|
||||
|
||||
document.onkeydown = event =>{
|
||||
switch (event.keyCode) {
|
||||
case 37: //left
|
||||
changePage(currentPage - 1);
|
||||
break;
|
||||
case 38: //up
|
||||
break;
|
||||
case 39: //right
|
||||
changePage(currentPage + 1);
|
||||
break;
|
||||
case 40: //down
|
||||
break;
|
||||
}
|
||||
};
|
||||
75
doujinshi_dl/viewer/viewer/minimal/styles.css
Normal file
75
doujinshi_dl/viewer/viewer/minimal/styles.css
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
*, *::after, *::before {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
img {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
html, body {
|
||||
display: flex;
|
||||
background-color: #e8e6e6;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#list {
|
||||
height: 2000px;
|
||||
overflow: scroll;
|
||||
width: 260px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#list img {
|
||||
width: 200px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin: 15px 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#list img.current {
|
||||
background: #0003;
|
||||
}
|
||||
|
||||
#image-container {
|
||||
flex: auto;
|
||||
height: 100%;
|
||||
background: rgb(0, 0, 0);
|
||||
color: rgb(100, 100, 100);
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#image-container #dest {
|
||||
height: 2000px;
|
||||
width: 100%;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
background-position: top;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 100%;
|
||||
max-height: 100vh;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
#image-container #page-num {
|
||||
position: static;
|
||||
font-size: 9pt;
|
||||
left: 10px;
|
||||
bottom: 5px;
|
||||
font-weight: bold;
|
||||
opacity: 0.9;
|
||||
text-shadow: /* Duplicate the same shadow to make it very strong */
|
||||
0 0 2px #222,
|
||||
0 0 2px #222,
|
||||
0 0 2px #222;
|
||||
}
|
||||
Reference in New Issue
Block a user