CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-jmcomic

Python API for accessing and downloading content from JMComic with Cloudflare bypass and plugin system.

Pending
Overview
Eval results
Files

command-line-interface.mddocs/

Command Line Interface

Command-line interface for interactive downloads and batch operations with environment variable support and user-friendly interaction patterns.

Types

from typing import List, Dict, Any, Optional, Union

Capabilities

Main CLI Class

Interactive 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 Entry Point

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 --version

Environment Variable Helper

Utility 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')

CLI Features

Interactive Mode

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):

Configuration Management

The CLI supports various configuration sources in order of precedence:

  1. Command-line arguments
  2. Environment variables
  3. Configuration files
  4. Interactive prompts
  5. Default values

Batch Processing

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 -

Progress Display

The CLI provides visual progress indicators:

  • Overall progress for batch operations
  • Individual download progress
  • Speed and ETA information
  • Error summary and statistics

Logging and Output

Output levels can be controlled:

  • Normal: Standard progress and completion messages
  • Quiet (--quiet): Minimal output, errors only
  • Verbose (--verbose): Detailed operation logs
  • Debug: Full debugging information

Environment Variables

The 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

Integration Examples

Shell Script Integration

#!/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
fi

Python Integration

import 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)

Configuration File Integration

# 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}"

Error Handling in CLI

The CLI provides user-friendly error messages and recovery options:

  • Network errors: Suggest checking connection and retrying
  • Authentication errors: Prompt for credential verification
  • Configuration errors: Show specific validation failures
  • Partial failures: Display success/failure summary with options to retry failed items
  • Interrupt handling: Graceful shutdown on Ctrl+C with cleanup

Install with Tessl CLI

npx tessl i tessl/pypi-jmcomic

docs

client-system.md

command-line-interface.md

configuration-management.md

content-entities.md

core-download-api.md

download-system.md

exception-handling.md

index.md

plugin-system.md

text-data-processing.md

tile.json