diff --git a/python_core/services/scene_detection/__init__.py b/python_core/services/scene_detection/__init__.py new file mode 100644 index 0000000..2d0d796 --- /dev/null +++ b/python_core/services/scene_detection/__init__.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +""" +场景检测服务模块 +""" + +from .types import ( + DetectorType, SceneInfo, VideoSceneResult, + BatchDetectionConfig, BatchDetectionResult, DetectionStats +) +from .detector import SceneDetectionService +from .cli import SceneDetectionCommander + +__all__ = [ + # 数据类型 + "DetectorType", + "SceneInfo", + "VideoSceneResult", + "BatchDetectionConfig", + "BatchDetectionResult", + "DetectionStats", + + # 服务 + "SceneDetectionService", + + # 命令行接口 + "SceneDetectionCommander" +] diff --git a/python_core/services/scene_detection/types.py b/python_core/services/scene_detection/types.py new file mode 100644 index 0000000..a567fb6 --- /dev/null +++ b/python_core/services/scene_detection/types.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +""" +场景检测相关的数据类型定义 +""" + +from dataclasses import dataclass +from typing import List, Optional +from enum import Enum + +class DetectorType(Enum): + """检测器类型""" + CONTENT = "content" + THRESHOLD = "threshold" + ADAPTIVE = "adaptive" + +@dataclass +class SceneInfo: + """场景信息""" + index: int + start_time: float + end_time: float + duration: float + confidence: float = 0.0 + frame_count: int = 0 + thumbnail_path: Optional[str] = None + +@dataclass +class VideoSceneResult: + """单个视频的场景检测结果""" + video_path: str + filename: str + success: bool + total_scenes: int + total_duration: float + scenes: List[SceneInfo] + detection_time: float + detector_type: str + threshold: float + error: Optional[str] = None + +@dataclass +class BatchDetectionConfig: + """批量检测配置""" + detector_type: DetectorType = DetectorType.CONTENT + threshold: float = 30.0 + min_scene_length: float = 1.0 + adaptive_threshold: bool = False + generate_thumbnails: bool = False + output_format: str = "json" # json, csv, txt + save_scenes: bool = False + +@dataclass +class BatchDetectionResult: + """批量检测结果""" + total_files: int + processed_files: int + failed_files: int + total_scenes: int + total_duration: float + average_scenes_per_video: float + detection_time: float + results: List[VideoSceneResult] + failed_list: List[dict] + config: BatchDetectionConfig + +@dataclass +class DetectionStats: + """检测统计信息""" + total_videos: int + total_scenes: int + total_duration: float + average_duration_per_scene: float + shortest_scene: float + longest_scene: float + most_scenes_video: str + least_scenes_video: str diff --git a/src-tauri/src/commands/media.rs b/src-tauri/src/commands/media.rs index 5227c62..b67fc2d 100644 --- a/src-tauri/src/commands/media.rs +++ b/src-tauri/src/commands/media.rs @@ -69,7 +69,7 @@ pub async fn get_segments_by_video_id(app: AppHandle, video_id: String) -> Resul pub async fn upload_video_file(app: AppHandle, request: UploadVideoRequest) -> Result { let mut args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "upload_video_file".to_string(), request.source_path, ]; @@ -96,7 +96,7 @@ pub async fn upload_video_file(app: AppHandle, request: UploadVideoRequest) -> R pub async fn batch_upload_video_files(app: AppHandle, request: BatchUploadVideoRequest) -> Result { let mut args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "batch_upload_video_files".to_string(), request.source_directory, ]; @@ -120,7 +120,7 @@ pub async fn add_segment_tags(app: AppHandle, request: TagsRequest) -> Result Result let args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "remove_segment_tags".to_string(), request.segment_id, tags_json, @@ -151,7 +151,7 @@ pub async fn remove_segment_tags(app: AppHandle, request: TagsRequest) -> Result pub async fn increment_segment_usage(app: AppHandle, segment_id: String) -> Result { let args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "increment_segment_usage".to_string(), segment_id, ]; @@ -170,7 +170,7 @@ pub async fn get_segments_by_tags(app: AppHandle, request: SearchTagsRequest) -> let args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "get_segments_by_tags".to_string(), tags_json, match_all_json, @@ -184,7 +184,7 @@ pub async fn get_segments_by_tags(app: AppHandle, request: SearchTagsRequest) -> pub async fn get_popular_segments(app: AppHandle, limit: Option) -> Result { let mut args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "get_popular_segments".to_string(), ]; @@ -200,7 +200,7 @@ pub async fn get_popular_segments(app: AppHandle, limit: Option) -> Result< pub async fn search_segments(app: AppHandle, keyword: String) -> Result { let args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "pypython_core.services.media_manager.cli".to_string(), "search_segments".to_string(), keyword, ]; @@ -213,7 +213,7 @@ pub async fn search_segments(app: AppHandle, keyword: String) -> Result Result { let args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "delete_segment".to_string(), segment_id, ]; @@ -226,7 +226,7 @@ pub async fn delete_segment(app: AppHandle, segment_id: String) -> Result Result { let args = vec![ "-m".to_string(), - "python_core.services.media_manager".to_string(), + "python_core.services.media_manager.cli".to_string(), "delete_original_video".to_string(), video_id, ];