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

plugin-system.mddocs/

Plugin System

Extensible plugin framework with 18+ built-in plugins covering login, monitoring, notifications, content processing, and advanced download features. Provides a comprehensive system for extending and customizing JMComic functionality.

Types

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

Capabilities

Base Plugin Framework

Foundation classes for creating and managing plugins with validation, logging, and lifecycle management.

class JmOptionPlugin:
    """
    Base plugin class with validation, logging, and file operations.
    
    All plugins inherit from this base class and implement specific
    functionality through hook methods and configuration.
    
    Attributes:
    - option: JmOption - Configuration options
    - enabled: bool - Whether plugin is enabled
    - priority: int - Plugin execution priority
    - plugin_key: str - Unique plugin identifier
    
    Methods:
    - validate(): Validate plugin configuration
    - before_album(album): Hook called before album processing
    - after_album(album): Hook called after album processing
    - before_photo(photo): Hook called before photo processing
    - after_photo(photo): Hook called after photo processing
    - before_image(image): Hook called before image processing
    - after_image(image): Hook called after image processing
    - on_error(exception, context): Hook called on errors
    """
    
    def __init__(self, option: 'JmOption'):
        """
        Initialize plugin with configuration.
        
        Parameters:
        - option: JmOption - Configuration options
        """
    
    def validate(self):
        """
        Validate plugin configuration and requirements.
        
        Raises:
        PluginValidationException - If configuration is invalid
        """
    
    def before_album(self, album: 'JmAlbumDetail'):
        """
        Hook called before album processing starts.
        
        Parameters:
        - album: JmAlbumDetail - Album being processed
        """
    
    def after_album(self, album: 'JmAlbumDetail'):
        """
        Hook called after album processing completes.
        
        Parameters:
        - album: JmAlbumDetail - Processed album
        """
    
    def before_photo(self, photo: 'JmPhotoDetail'):
        """
        Hook called before photo processing starts.
        
        Parameters:
        - photo: JmPhotoDetail - Photo being processed
        """
    
    def after_photo(self, photo: 'JmPhotoDetail'):
        """
        Hook called after photo processing completes.
        
        Parameters:
        - photo: JmPhotoDetail - Processed photo
        """

class PluginValidationException(Exception):
    """
    Exception raised when plugin configuration validation fails.
    
    Attributes:
    - plugin_name: str - Name of the plugin that failed validation
    - message: str - Validation error message
    """

Authentication and Login Plugins

Plugins for handling user authentication and session management.

class JmLoginPlugin(JmOptionPlugin):
    """
    Automated login and cookie management plugin.
    
    Handles user authentication, session management, and automatic
    cookie refreshing for accessing protected content.
    
    Configuration:
    - username: str - Login username/email
    - password: str - Login password
    - auto_login: bool - Whether to login automatically
    - save_cookies: bool - Whether to save session cookies
    - cookie_file: str - Path to cookie storage file
    """
    
    def login(self) -> bool:
        """
        Perform login with configured credentials.
        
        Returns:
        bool - True if login successful
        """
    
    def is_logged_in(self) -> bool:
        """
        Check if currently logged in.
        
        Returns:
        bool - True if valid session exists
        """
    
    def refresh_session(self):
        """Refresh authentication session."""

class AutoSetBrowserCookiesPlugin(JmOptionPlugin):
    """
    Import cookies from installed browsers for automatic authentication.
    
    Supports importing cookies from Chrome, Firefox, Edge, and other
    browsers to avoid manual login.
    
    Configuration:
    - browser: str - Browser to import from ('chrome', 'firefox', etc.)
    - profile: str - Browser profile name (optional)
    """

Monitoring and Logging Plugins

Plugins for system monitoring, resource tracking, and logging management.

class UsageLogPlugin(JmOptionPlugin):
    """
    System resource usage monitoring and reporting plugin.
    
    Tracks CPU usage, memory consumption, disk I/O, and network
    traffic during download operations.
    
    Configuration:
    - log_file: str - Path to usage log file
    - log_interval: int - Logging interval in seconds
    - include_system_stats: bool - Include system-wide statistics
    """
    
    def get_current_usage(self) -> Dict[str, Any]:
        """
        Get current system resource usage.
        
        Returns:
        dict - Resource usage statistics
        """

class LogTopicFilterPlugin(JmOptionPlugin):
    """
    Filter log messages by topic/category for cleaner logs.
    
    Configuration:
    - allowed_topics: List[str] - Topics to include in logs
    - blocked_topics: List[str] - Topics to exclude from logs
    - log_level: str - Minimum log level ('DEBUG', 'INFO', 'WARNING', 'ERROR')
    """

Content Processing Plugins

Plugins for processing downloaded content including archiving, format conversion, and organization.

class ZipPlugin(JmOptionPlugin):
    """
    Archive downloaded content with optional password encryption.
    
    Creates ZIP archives of downloaded albums with compression
    and optional password protection.
    
    Configuration:
    - enabled: bool - Whether to create archives
    - password: str - Archive password (optional)
    - compression_level: int - Compression level (0-9)
    - archive_per_album: bool - Create separate archive per album
    - delete_original: bool - Delete original files after archiving
    """
    
    def create_archive(self, album: 'JmAlbumDetail') -> str:
        """
        Create ZIP archive for album.
        
        Parameters:
        - album: JmAlbumDetail - Album to archive
        
        Returns:
        str - Path to created archive file
        """

class Img2pdfPlugin(JmOptionPlugin):
    """
    Convert images to PDF with optional encryption.
    
    Creates PDF documents from downloaded images with support
    for password protection and metadata.
    
    Configuration:
    - enabled: bool - Whether to create PDFs
    - password: str - PDF password (optional)
    - quality: str - Image quality ('high', 'medium', 'low')
    - pdf_per_photo: bool - Create PDF per photo vs per album
    """

class LongImgPlugin(JmOptionPlugin):
    """
    Merge images into long scrolling format for mobile viewing.
    
    Concatenates images vertically to create long scroll images
    suitable for mobile comic readers.
    
    Configuration:
    - enabled: bool - Whether to create long images
    - max_height: int - Maximum image height
    - spacing: int - Spacing between images in pixels
    """

Download Enhancement Plugins

Plugins that enhance and customize the download process.

class FindUpdatePlugin(JmOptionPlugin):
    """
    Find and download new chapters for existing albums.
    
    Monitors albums for new content and automatically downloads
    new chapters when they become available.
    
    Configuration:
    - check_interval: int - Check interval in hours
    - album_ids: List[str] - Albums to monitor
    - auto_download: bool - Automatically download new chapters
    """
    
    def check_for_updates(self) -> List['JmAlbumDetail']:
        """
        Check monitored albums for updates.
        
        Returns:
        List[JmAlbumDetail] - Albums with new content
        """

class SubscribeAlbumUpdatePlugin(JmOptionPlugin):
    """
    Monitor albums for new chapter updates with notifications.
    
    Configuration:
    - subscribed_albums: List[str] - Album IDs to monitor
    - check_frequency: int - Check frequency in hours
    - notification_method: str - Notification method ('email', 'webhook')
    """

class ClientProxyPlugin(JmOptionPlugin):
    """
    Proxy client requests through other clients for failover.
    
    Provides client redundancy by routing requests through
    multiple client implementations.
    
    Configuration:
    - primary_client: str - Primary client type
    - fallback_clients: List[str] - Fallback client types
    - switch_threshold: int - Error threshold for client switching
    """

class AdvancedRetryPlugin(JmOptionPlugin):
    """
    Enhanced retry mechanisms with backoff strategies.
    
    Configuration:
    - max_retries: int - Maximum retry attempts
    - backoff_strategy: str - Backoff strategy ('exponential', 'linear')
    - retry_delay: float - Base retry delay in seconds
    """

Content Filtering Plugins

Plugins for filtering and selecting content based on various criteria.

class ImageSuffixFilterPlugin(JmOptionPlugin):
    """
    Filter downloads by image format/extension.
    
    Configuration:
    - allowed_formats: List[str] - Allowed image formats
    - blocked_formats: List[str] - Blocked image formats
    - convert_formats: Dict[str, str] - Format conversion mapping
    """

class SkipPhotoWithFewImagesPlugin(JmOptionPlugin):
    """
    Skip chapters with insufficient images.
    
    Configuration:
    - min_images: int - Minimum number of images required
    - skip_action: str - Action for skipped photos ('skip', 'mark', 'log')
    """

Notification and Integration Plugins

Plugins for external notifications and system integration.

class SendQQEmailPlugin(JmOptionPlugin):
    """
    Email notification system for download completion.
    
    Sends email notifications when downloads complete or fail.
    
    Configuration:
    - smtp_server: str - SMTP server address
    - smtp_port: int - SMTP server port
    - username: str - Email username
    - password: str - Email password
    - to_email: str - Recipient email address
    - notify_on_complete: bool - Send notification on completion
    - notify_on_error: bool - Send notification on errors
    """
    
    def send_notification(self, subject: str, message: str):
        """
        Send email notification.
        
        Parameters:
        - subject: str - Email subject
        - message: str - Email message body
        """

class JmServerPlugin(JmOptionPlugin):
    """
    Built-in web server for viewing downloaded content.
    
    Starts a local web server to browse and view downloaded
    content through a web interface.
    
    Configuration:
    - port: int - Server port
    - host: str - Server host address
    - auto_start: bool - Start server automatically
    - enable_uploads: bool - Enable file uploads
    """
    
    def start_server(self):
        """Start the web server."""
    
    def stop_server(self):
        """Stop the web server."""

Utility Plugins

Plugins for file management and system utilities.

class DeleteDuplicatedFilesPlugin(JmOptionPlugin):
    """
    Remove duplicate files from downloads.
    
    Configuration:
    - check_method: str - Duplicate detection method ('hash', 'name', 'size')
    - delete_action: str - Action for duplicates ('delete', 'move', 'mark')
    """

class ReplacePathStringPlugin(JmOptionPlugin):
    """
    Modify file paths with pattern replacement.
    
    Configuration:
    - replacements: Dict[str, str] - Pattern replacement mapping
    - use_regex: bool - Whether to use regex patterns
    """

class FavoriteFolderExportPlugin(JmOptionPlugin):
    """
    Export user favorites data to files.
    
    Configuration:
    - export_format: str - Export format ('json', 'csv', 'txt')
    - output_file: str - Output file path
    - include_metadata: bool - Include full metadata
    """

Plugin Usage Examples

# Configure plugins in JmOption
option = JmOption.default()

# Enable login plugin
option.plugins['JmLoginPlugin'] = {
    'username': 'user@example.com',
    'password': 'password',
    'auto_login': True
}

# Enable ZIP archiving
option.plugins['ZipPlugin'] = {
    'enabled': True,
    'password': 'archive_password',
    'compression_level': 6
}

# Enable usage monitoring
option.plugins['UsageLogPlugin'] = {
    'log_file': 'usage.log',
    'log_interval': 60
}

# Use configured plugins
downloader = JmDownloader(option)
album = downloader.download_album("123456")
# Plugins automatically execute during download process

Custom Plugin Development

Create custom plugins by inheriting from JmOptionPlugin:

class MyCustomPlugin(JmOptionPlugin):
    def validate(self):
        # Validate plugin configuration
        required_config = self.option.plugins.get('MyCustomPlugin', {})
        if 'required_param' not in required_config:
            raise PluginValidationException("required_param is missing")
    
    def after_album(self, album):
        # Custom processing after album download
        print(f"Processed album: {album.title}")
        # Add custom logic here

# Register and use custom plugin
option.plugins['MyCustomPlugin'] = {
    'required_param': 'value'
}

Plugin Execution Order

Plugins execute in priority order during download lifecycle:

  1. Validation Phase: All plugins validate their configuration
  2. Before Album: Plugins execute before_album() hooks
  3. Before Photo: Plugins execute before_photo() hooks for each photo
  4. Before Image: Plugins execute before_image() hooks for each image
  5. After Image: Plugins execute after_image() hooks for each image
  6. After Photo: Plugins execute after_photo() hooks for each photo
  7. After Album: Plugins execute after_album() hooks
  8. Error Handling: Plugins handle errors via on_error() hooks

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