Skip to main content
Glama

parse_media_info

Extract technical metadata from media files, including video duration and resolution or image dimensions, to support automated video editing workflows in JianYing (CapCut).

Instructions

解析媒体文件信息

Args: media_path: 媒体文件路径或URL,支持本地文件和网络URL,不论任何类型的文件都可以,视频可返回时长、分辨率,图片可返回尺寸

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
media_pathYes

Implementation Reference

  • The main handler function for the 'parse_media_info' tool. Decorated with @mcp.tool(), it processes the media_path, calls the helper from media_parser, handles errors, and returns a ToolResponse with media information.
    @mcp.tool() def parse_media_info(media_path: str) -> ToolResponse: """ 解析媒体文件信息 Args: media_path: 媒体文件路径或URL,支持本地文件和网络URL,不论任何类型的文件都可以,视频可返回时长、分辨率,图片可返回尺寸 """ try: from jianyingdraft.utils.media_parser import parse_media_info as parse_func # 调用解析函数 media_info = parse_func(media_path) if media_info is None: return ToolResponse( success=False, message=f"无法解析媒体文件: {media_path}" ) # 构建返回数据 response_data = { "media_path": media_path, "media_info": media_info } # 提取关键信息用于消息 media_type = media_info.get("type", "未知") duration = media_info.get("duration") resolution = media_info.get("resolution") message_parts = [f"成功解析 {media_type} 文件"] if duration: message_parts.append(f"时长: {duration}") if resolution: message_parts.append(f"分辨率: {resolution}") return ToolResponse( success=True, message=", ".join(message_parts), data=response_data ) except Exception as e: return ToolResponse( success=False, message=f"解析媒体文件失败: {str(e)}" )
  • Registration of utility tools, including parse_media_info, by calling utility_tools(mcp) on the FastMCP server instance.
    utility_tools(mcp)
  • Helper function imported and called by the handler. Creates MediaParser instance and invokes its parse_media_info method to handle local and remote media parsing.
    def parse_media_info(media_path: str) -> Optional[Dict[str, Any]]: """ 解析媒体文件信息的便捷函数 Args: media_path: 媒体文件路径或URL Returns: Dict: 媒体信息,解析失败返回None """ parser = MediaParser() try: return parser.parse_media_info(media_path) finally: parser.cleanup_all_temp_files()
  • Core parsing method in MediaParser class. Determines if URL or local file and delegates to appropriate parser, using pymediainfo for extraction.
    def parse_media_info(self, media_path: str) -> Optional[Dict[str, Any]]: """ 解析媒体文件信息 Args: media_path: 媒体文件路径或URL Returns: Dict: 媒体信息,包含duration等字段,解析失败返回None """ try: if self._is_url(media_path): return self._parse_url_media(media_path) else: return self._parse_local_media(media_path) except Exception as e: print(f"解析媒体信息失败: {e}") return None

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/hey-jian-wei/jianying-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server