use os.path.sep as path separator

This commit is contained in:
ricterz 2025-01-11 08:48:43 +08:00
parent 6b4c4bdc70
commit 8944ece4a8
4 changed files with 16 additions and 7 deletions

View File

@ -11,6 +11,7 @@ from optparse import OptionParser
from nhentai import __version__
from nhentai.utils import generate_html, generate_main_html, DB
from nhentai.logger import logger
from nhentai.constant import PATH_SEPARATOR
def banner():
@ -64,7 +65,8 @@ def cmd_parser():
# operation options
parser.add_option('--download', '-D', dest='is_download', action='store_true',
help='download doujinshi (for search results)')
parser.add_option('--show', '-S', dest='is_show', action='store_true', help='just show the doujinshi information')
parser.add_option('--show', '-S', dest='is_show', action='store_true',
help='just show the doujinshi information')
# doujinshi options
parser.add_option('--id', dest='id', action='callback', callback=callback,
@ -86,7 +88,8 @@ def cmd_parser():
choices=['recent', 'popular', 'popular-today', 'popular-week', 'date'])
# download options
parser.add_option('--output', '-o', type='string', dest='output_dir', action='store', default='./',
parser.add_option('--output', '-o', type='string', dest='output_dir', action='store',
default=f'.{PATH_SEPARATOR}',
help='output dir')
parser.add_option('--threads', '-t', type='int', dest='threads', action='store', default=5,
help='thread count for downloading doujinshi')
@ -96,7 +99,8 @@ def cmd_parser():
help='slow down between downloading every doujinshi')
parser.add_option('--proxy', type='string', dest='proxy', action='store',
help='store a proxy, for example: -p "http://127.0.0.1:1080"')
parser.add_option('--file', '-f', type='string', dest='file', action='store', help='read gallery IDs from file.')
parser.add_option('--file', '-f', type='string', dest='file', action='store',
help='read gallery IDs from file.')
parser.add_option('--format', type='string', dest='name_format', action='store',
help='format the saved folder name', default='[%i][%a][%t]')
parser.add_option('--dry-run', action='store_true', dest='dryrun', help='Dry run, skip file download')

View File

@ -35,6 +35,8 @@ LOGIN_URL = f'{BASE_URL}/login/'
CHALLENGE_URL = f'{BASE_URL}/challenge'
FAV_URL = f'{BASE_URL}/favorites/'
PATH_SEPARATOR = os.path.sep
IMAGE_URL = f'{urlparse(BASE_URL).scheme}://i.{urlparse(BASE_URL).hostname}/galleries'
IMAGE_URL_MIRRORS = [

View File

@ -1,6 +1,8 @@
# coding: utf-8
import json
import os
from nhentai.constant import PATH_SEPARATOR
from xml.sax.saxutils import escape
from nhentai.constant import LANGUAGE_ISO
@ -82,7 +84,7 @@ def xml_write_simple_tag(f, name, val, indent=1):
def merge_json():
lst = []
output_dir = "./"
output_dir = f".{PATH_SEPARATOR}"
os.chdir(output_dir)
doujinshi_dirs = next(os.walk('.'))[1]
for folder in doujinshi_dirs:

View File

@ -14,6 +14,7 @@ from typing import Tuple
from requests.structures import CaseInsensitiveDict
from nhentai import constant
from nhentai.constant import PATH_SEPARATOR
from nhentai.logger import logger
from nhentai.serializer import serialize_json, serialize_comic_xml, set_js_database
@ -100,7 +101,7 @@ def parse_doujinshi_obj(
file_type: str = ''
) -> Tuple[str, str]:
filename = f'./doujinshi.{file_type}'
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}'
@ -113,7 +114,7 @@ def parse_doujinshi_obj(
filename = os.path.join(output_dir, _filename)
else:
doujinshi_dir = './'
doujinshi_dir = f'.{PATH_SEPARATOR}'
return doujinshi_dir, filename
@ -178,7 +179,7 @@ def move_to_folder(output_dir='.', doujinshi_obj=None, file_type=None):
shutil.move(filename, os.path.join(doujinshi_dir, os.path.basename(filename)))
def generate_main_html(output_dir='./'):
def generate_main_html(output_dir=f'.{PATH_SEPARATOR}'):
"""
Generate a main html to show all the contains doujinshi.
With a link to their `index.html`.