Files
Bacruru Sakaguchi 1ddfe375e5 feat(core): add recursive loading and analyzer tools
Add recursive thread loading method to load threads with all messages and images from the database.

Add support for image captions in the database schema and Image model.

Introduce new analyzer tools for thread management:
- Load thread names from database
- Group threads by similarity
- Merge thread groups

Update main menu to include new Analyzer submenu and options to process threads without downloading images.
2026-02-18 18:19:33 +00:00

60 lines
2.1 KiB
Python
Executable File

"""
Image data model for forum thread structure (2ch.life).
This module defines the Image entity for forum data.
"""
from dataclasses import dataclass
from typing import Optional
@dataclass
class Image:
"""
Represents an image or video attached to a message.
Attributes:
url: Full URL of the image/video
name: File name (e.g., "mocha00028.mp4")
type: File type (6=webm, 9=webp, 10=mp4)
width: Image width in pixels
height: Image height in pixels
size: File size in KB
duration: Video duration in format "HH:MM:SS" (optional)
caption: Optional caption text for the image (optional)
data: Downloaded file content as bytes (optional)
"""
ref_id: int
url: str
name: str
type: int # 6=webm, 9=webp, 10=mp4
width: int
height: int
size: int # File size in KB
duration: Optional[str] = None
caption: Optional[str] = None
data: Optional[bytes] = None
def __post_init__(self):
"""Validate image data after initialization."""
if not self.url or not isinstance(self.url, str):
raise ValueError("Image URL must be a non-empty string")
if not self.name or not isinstance(self.name, str):
raise ValueError("Image name must be a non-empty string")
if not isinstance(self.type, int):
raise ValueError("Image type must be an integer")
if not isinstance(self.width, int):
raise ValueError("Image width must be an integer")
if not isinstance(self.height, int):
raise ValueError("Image height must be an integer")
if not isinstance(self.size, int):
raise ValueError("Image size must be an integer")
if self.duration is not None and not isinstance(self.duration, str):
raise ValueError("Image duration must be a string or None")
if self.caption is not None and not isinstance(self.caption, str):
raise ValueError("Image caption must be a string or None")
if self.data is not None and not isinstance(self.data, bytes):
raise ValueError("Image data must be bytes or None")