Files
AEmotionStudio-ComfyUI-Disc…/shared/filename_utils.py
T
AEmotionStudioandClaude Opus 4.5 a208cd482b refactor(phase2): extract shared utilities and reduce node duplication
- Create shared/filename_utils.py for date/time/dimension filename building
- Create shared/path_utils.py for output directory handling
- Create shared/discord/message_builder.py for Discord message construction
- Create shared/discord/cdn_extractor.py for CDN URL extraction
- Refactor image_node.py to use shared utilities (-161 lines, 16.3%)
- Refactor video_node.py to use shared utilities (-361 lines, 23.1%)
- Fix setup_logging missing from logging_config.py
- Fix test imports to use new module paths (nodes.* instead of discord_*_node)
- Total reduction: 522 lines (20.5%), exceeding PRD target of ~200 lines

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 23:33:10 -08:00

84 lines
2.5 KiB
Python

"""
Filename utilities for ComfyUI-DiscordSend
Provides functions for building filenames with date, time, and dimension metadata.
"""
import time
from typing import Dict, Optional, Tuple, Any
def build_filename_with_metadata(
prefix: str,
add_date: bool = False,
add_time: bool = False,
add_dimensions: bool = False,
width: Optional[int] = None,
height: Optional[int] = None,
info_dict: Optional[Dict[str, Any]] = None
) -> Tuple[str, Dict[str, Any]]:
"""
Build a filename with optional date, time, and dimension suffixes.
Args:
prefix: The base filename prefix
add_date: Whether to add the current date (YYYY-MM-DD)
add_time: Whether to add the current time (HH-MM-SS)
add_dimensions: Whether to add dimensions (WxH)
width: Image/video width (required if add_dimensions is True)
height: Image/video height (required if add_dimensions is True)
info_dict: Optional dict to update with metadata (creates new if None)
Returns:
Tuple of (modified_prefix, info_dict with metadata)
"""
if info_dict is None:
info_dict = {}
metadata_parts = []
if add_date:
current_date = time.strftime("%Y-%m-%d")
metadata_parts.append(current_date)
info_dict["date"] = current_date
print(f"Adding date to filename: {current_date}")
if add_time:
current_time = time.strftime("%H-%M-%S")
metadata_parts.append(current_time)
info_dict["time"] = current_time
print(f"Adding time to filename: {current_time}")
if add_dimensions and width is not None and height is not None:
dim_text = f"{width}x{height}"
metadata_parts.append(dim_text)
info_dict["dimensions"] = dim_text
print(f"Adding dimensions to filename: {dim_text}")
modified_prefix = prefix
if metadata_parts:
metadata_suffix = "_" + "_".join(metadata_parts)
modified_prefix += metadata_suffix
print(f"Final metadata suffix: {metadata_suffix}")
return modified_prefix, info_dict
def get_timestamp_string(include_date: bool = True, include_time: bool = True) -> str:
"""
Get a formatted timestamp string.
Args:
include_date: Include date in format YYYY-MM-DD
include_time: Include time in format HH-MM-SS
Returns:
Formatted timestamp string
"""
parts = []
if include_date:
parts.append(time.strftime("%Y-%m-%d"))
if include_time:
parts.append(time.strftime("%H-%M-%S"))
return "_".join(parts) if parts else ""