Skip to content

Commit

Permalink
use os.path.sep as path separator
Browse files Browse the repository at this point in the history
  • Loading branch information
RicterZ committed Jan 11, 2025
1 parent 6b4c4bd commit 8944ece
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 7 additions & 3 deletions nhentai/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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():
Expand Down Expand Up @@ -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,
Expand All @@ -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')
Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions nhentai/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def get_nhentai_home() -> str:
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 = [
Expand Down
4 changes: 3 additions & 1 deletion nhentai/serializer.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions nhentai/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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

Expand Down Expand Up @@ -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}'
Expand All @@ -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

Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit 8944ece

Please sign in to comment.