Python API for accessing and downloading content from JMComic with Cloudflare bypass and plugin system.
—
Command-line interface for interactive downloads and batch operations with environment variable support and user-friendly interaction patterns.
from typing import List, Dict, Any, Optional, UnionInteractive command-line interface for downloading content with user prompts and batch operations.
class JmcomicUI:
"""
Command-line interface for interactive JMComic downloads.
Provides a user-friendly CLI with interactive prompts, batch operations,
and configuration management for downloading albums and photos.
Attributes:
- option: JmOption - Configuration options for downloads
- downloader: JmDownloader - Downloader instance
- interactive_mode: bool - Whether to use interactive prompts
Methods:
- run(): Start interactive CLI session
- download_single(jm_id): Download single album or photo
- download_batch(jm_ids): Download multiple items
- configure_options(): Interactive option configuration
- show_help(): Display help information
- show_status(): Display current status and statistics
"""
def __init__(self, option: 'JmOption' = None, interactive_mode: bool = True):
"""
Initialize CLI interface.
Parameters:
- option: JmOption, optional - Configuration options
- interactive_mode: bool - Enable interactive prompts
"""
self.option = option or JmOption.default()
self.interactive_mode = interactive_mode
self.downloader = None
def run(self):
"""
Start interactive CLI session.
Presents main menu and handles user input for various operations
including downloads, configuration, and status display.
"""
def download_single(self, jm_id: Union[str, int]) -> bool:
"""
Download single album or photo with progress display.
Parameters:
- jm_id: str or int - JM ID to download
Returns:
bool - True if download successful
"""
def download_batch(self, jm_ids: List[Union[str, int]]) -> Dict[str, bool]:
"""
Download multiple albums or photos with progress tracking.
Parameters:
- jm_ids: list - List of JM IDs to download
Returns:
dict - Mapping of JM ID to success status
"""
def configure_options(self):
"""
Interactive configuration of download options.
Presents prompts for setting download directories, client preferences,
plugin configurations, and other options.
"""
def show_help(self):
"""Display help information and usage examples."""
def show_status(self):
"""
Display current status and download statistics.
Shows information about current configuration, recent downloads,
and system status.
"""Usage examples:
# Start interactive CLI
ui = JmcomicUI()
ui.run()
# Non-interactive usage
option = JmOption.from_file("config.yml")
ui = JmcomicUI(option, interactive_mode=False)
success = ui.download_single("123456")
# Batch download
jm_ids = ["123456", "789012", "345678"]
results = ui.download_batch(jm_ids)
for jm_id, success in results.items():
print(f"{jm_id}: {'Success' if success else 'Failed'}")Main function that serves as the primary entry point for the CLI application.
def main():
"""
Main entry point for the JMComic CLI application.
Handles command-line argument parsing, configuration loading,
and initialization of the CLI interface.
Command-line arguments:
- --config, -c: Path to configuration file
- --batch, -b: Batch mode with IDs from file or stdin
- --id: Single JM ID to download
- --help, -h: Show help information
- --version, -v: Show version information
- --interactive, -i: Force interactive mode
- --quiet, -q: Quiet mode with minimal output
"""Command-line usage examples:
# Interactive mode (default)
python -m jmcomic
# Download single album
python -m jmcomic --id 123456
# Download with custom config
python -m jmcomic --config custom_config.yml --id 123456
# Batch download from file
python -m jmcomic --batch album_ids.txt
# Batch download from stdin
echo "123456 789012 345678" | python -m jmcomic --batch -
# Quiet mode
python -m jmcomic --quiet --id 123456
# Show help
python -m jmcomic --help
# Show version
python -m jmcomic --versionUtility function for reading environment variables with default values.
def get_env(name: str, default: Any = None) -> Any:
"""
Get environment variable value with default fallback.
Provides consistent environment variable access across the
application with support for type conversion and defaults.
Parameters:
- name: str - Environment variable name
- default: Any - Default value if variable not set
Returns:
Any - Environment variable value or default
"""Usage examples:
# Get environment variables with defaults
config_path = get_env('JM_CONFIG_PATH', 'default_config.yml')
max_threads = get_env('JM_MAX_THREADS', 4)
debug_mode = get_env('JM_DEBUG', False)
# Boolean environment variables
debug_enabled = get_env('JM_DEBUG', 'false').lower() in ('true', '1', 'yes')When run in interactive mode, the CLI provides a menu-driven interface:
JMComic Downloader v2.6.6
=========================
1. Download single album/photo
2. Batch download
3. Configure options
4. View download history
5. Show status
6. Help
7. Exit
Select option (1-7):The CLI supports various configuration sources in order of precedence:
Batch mode supports multiple input formats:
# From file (one ID per line)
python -m jmcomic --batch ids.txt
# From stdin
echo "123456" | python -m jmcomic --batch -
# Multiple IDs in single line
echo "123456 789012 345678" | python -m jmcomic --batch -The CLI provides visual progress indicators:
Output levels can be controlled:
--quiet): Minimal output, errors only--verbose): Detailed operation logsThe CLI recognizes these environment variables:
# Configuration
export JM_CONFIG_PATH=/path/to/config.yml
export JM_OPTION_PATH=/path/to/options.yml
# Download settings
export JM_DOWNLOAD_DIR=/path/to/downloads
export JM_MAX_THREADS=8
# Client settings
export JM_RETRY_COUNT=3
export JM_TIMEOUT=30
export JM_USER_AGENT="Custom User Agent"
# Plugin settings
export JM_ENABLE_LOGIN=true
export JM_LOGIN_USERNAME=user@example.com
export JM_LOGIN_PASSWORD=password
# Output control
export JM_QUIET=false
export JM_DEBUG=false
export JM_LOG_FILE=/path/to/log.txt#!/bin/bash
# Download script with error handling
export JM_CONFIG_PATH="./production_config.yml"
export JM_QUIET=true
if python -m jmcomic --id "$1"; then
echo "Download successful: $1"
exit 0
else
echo "Download failed: $1"
exit 1
fiimport sys
from jmcomic.cl import JmcomicUI, get_env
# Programmatic CLI usage
def automated_download(album_ids):
config_path = get_env('JM_CONFIG_PATH', 'config.yml')
option = JmOption.from_file(config_path)
ui = JmcomicUI(option, interactive_mode=False)
results = ui.download_batch(album_ids)
return all(results.values())
# Use in scripts
if __name__ == "__main__":
album_ids = sys.argv[1:]
success = automated_download(album_ids)
sys.exit(0 if success else 1)# cli_config.yml
download:
base_dir: "/downloads"
max_threads: 6
cli:
default_mode: "interactive"
show_progress: true
confirm_downloads: true
save_history: true
history_file: "download_history.json"
logging:
level: "INFO"
file: "jmcomic.log"
format: "[{timestamp}] {level}: {message}"The CLI provides user-friendly error messages and recovery options:
Install with Tessl CLI
npx tessl i tessl/pypi-jmcomic