支持Docker容器化部署; 分离预设资源和自定义资源;
This commit is contained in:
@@ -10,6 +10,12 @@ from typing import Optional, List, Dict, Any
|
||||
from comfykit import ComfyKit
|
||||
from loguru import logger
|
||||
|
||||
from pixelle_video.utils.os_util import (
|
||||
get_resource_path,
|
||||
list_resource_files,
|
||||
list_resource_dirs
|
||||
)
|
||||
|
||||
|
||||
class ComfyBaseService:
|
||||
"""
|
||||
@@ -47,7 +53,7 @@ class ComfyBaseService:
|
||||
|
||||
def _scan_workflows(self) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Scan workflows/source/*.json files from all source directories
|
||||
Scan workflows/source/*.json files from all source directories (merged from workflows/ and data/workflows/)
|
||||
|
||||
Returns:
|
||||
List of workflow info dicts
|
||||
@@ -70,28 +76,34 @@ class ComfyBaseService:
|
||||
]
|
||||
"""
|
||||
workflows = []
|
||||
workflows_dir = Path(self.WORKFLOWS_DIR)
|
||||
|
||||
if not workflows_dir.exists():
|
||||
logger.warning(f"Workflows directory not found: {workflows_dir}")
|
||||
# Get all workflow source directories (merged from workflows/ and data/workflows/)
|
||||
source_dirs = list_resource_dirs("workflows")
|
||||
|
||||
if not source_dirs:
|
||||
logger.warning("No workflow source directories found")
|
||||
return workflows
|
||||
|
||||
# Scan subdirectories (selfhost, runninghub, etc.)
|
||||
for source_dir in workflows_dir.iterdir():
|
||||
if not source_dir.is_dir():
|
||||
logger.debug(f"Skipping non-directory: {source_dir}")
|
||||
continue
|
||||
# Scan each source directory for workflow files
|
||||
for source_name in source_dirs:
|
||||
# Get all JSON files for this source (merged from both locations)
|
||||
workflow_files = list_resource_files("workflows", source_name)
|
||||
|
||||
source_name = source_dir.name
|
||||
# Filter to only files matching the prefix
|
||||
matching_files = [
|
||||
f for f in workflow_files
|
||||
if f.startswith(self.WORKFLOW_PREFIX) and f.endswith('.json')
|
||||
]
|
||||
|
||||
# Scan workflow files in this source directory
|
||||
for file_path in source_dir.glob(f"{self.WORKFLOW_PREFIX}*.json"):
|
||||
for filename in matching_files:
|
||||
try:
|
||||
# Get actual file path (custom > default)
|
||||
file_path = Path(get_resource_path("workflows", source_name, filename))
|
||||
workflow_info = self._parse_workflow_file(file_path, source_name)
|
||||
workflows.append(workflow_info)
|
||||
logger.debug(f"Found workflow: {workflow_info['key']}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to parse workflow {file_path}: {e}")
|
||||
logger.error(f"Failed to parse workflow {source_name}/{filename}: {e}")
|
||||
|
||||
# Sort by key (source/name)
|
||||
return sorted(workflows, key=lambda w: w["key"])
|
||||
|
||||
@@ -21,6 +21,12 @@ from typing import List, Literal, Optional
|
||||
import ffmpeg
|
||||
from loguru import logger
|
||||
|
||||
from pixelle_video.utils.os_util import (
|
||||
get_resource_path,
|
||||
list_resource_files,
|
||||
resource_exists
|
||||
)
|
||||
|
||||
|
||||
def check_ffmpeg() -> None:
|
||||
"""
|
||||
@@ -509,11 +515,16 @@ class VideoService:
|
||||
|
||||
def _resolve_bgm_path(self, bgm_path: str) -> str:
|
||||
"""
|
||||
Resolve BGM path (filename or custom path)
|
||||
Resolve BGM path (filename or custom path) with custom override support
|
||||
|
||||
Search priority:
|
||||
1. Direct path (absolute or relative)
|
||||
2. data/bgm/{filename} (custom)
|
||||
3. bgm/{filename} (default)
|
||||
|
||||
Args:
|
||||
bgm_path: Can be:
|
||||
- Filename with extension (e.g., "default.mp3", "happy.mp3"): auto-resolved from bgm/ directory
|
||||
- Filename with extension (e.g., "default.mp3", "happy.mp3"): auto-resolved from bgm/ or data/bgm/
|
||||
- Custom file path (absolute or relative)
|
||||
|
||||
Returns:
|
||||
@@ -526,15 +537,14 @@ class VideoService:
|
||||
if os.path.exists(bgm_path):
|
||||
return os.path.abspath(bgm_path)
|
||||
|
||||
# Try as filename in bgm/ directory
|
||||
preset_path = f"bgm/{bgm_path}"
|
||||
if os.path.exists(preset_path):
|
||||
return os.path.abspath(preset_path)
|
||||
# Try as filename in resource directories (custom > default)
|
||||
if resource_exists("bgm", bgm_path):
|
||||
return get_resource_path("bgm", bgm_path)
|
||||
|
||||
# Not found - provide helpful error message
|
||||
tried_paths = [
|
||||
os.path.abspath(bgm_path),
|
||||
os.path.abspath(preset_path)
|
||||
f"data/bgm/{bgm_path} or bgm/{bgm_path}"
|
||||
]
|
||||
|
||||
# List available BGM files
|
||||
@@ -551,20 +561,19 @@ class VideoService:
|
||||
|
||||
def _list_available_bgm(self) -> list[str]:
|
||||
"""
|
||||
List available BGM files in bgm/ directory
|
||||
List available BGM files (merged from bgm/ and data/bgm/)
|
||||
|
||||
Returns:
|
||||
List of filenames (with extensions)
|
||||
List of filenames (with extensions), sorted
|
||||
"""
|
||||
bgm_dir = "bgm"
|
||||
if not os.path.exists(bgm_dir):
|
||||
return []
|
||||
|
||||
try:
|
||||
files = os.listdir(bgm_dir)
|
||||
# Return all audio files (mp3, wav, ogg, flac, etc.)
|
||||
# Use resource API to get merged list
|
||||
all_files = list_resource_files("bgm")
|
||||
|
||||
# Filter to audio files only
|
||||
audio_extensions = ('.mp3', '.wav', '.ogg', '.flac', '.m4a', '.aac')
|
||||
return [f for f in files if f.lower().endswith(audio_extensions)]
|
||||
except Exception:
|
||||
return sorted([f for f in all_files if f.lower().endswith(audio_extensions)])
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to list BGM files: {e}")
|
||||
return []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user