Skip to main content
Glama
yangbuyiya

Short Video MCP Server

by yangbuyiya

share_text_parse_tool_wrapper

Extract video content from TikTok share links and convert speech to text using specified API parameters.

Instructions

      提取视频内容,需要传递apikey,否则无法使用视频内容提取功能!
      参数:
      - text: 抖音分享文本,包含分享链接
      - api_base_url: API基础URL,默认使用siliconflow.cn
      - model: 语音识别模型,默认使用FunAudioLLM/SenseVoiceSmall
      

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
api_base_urlNo
modelNo

Implementation Reference

  • Registration of the MCP tool 'share_text_parse_tool_wrapper' using @mcp.tool decorator. The description string defines the tool schema including parameters and usage.
    @mcp.tool(
        description="""
              提取视频内容,需要传递apikey,否则无法使用视频内容提取功能!
              参数:
              - text: 抖音分享文本,包含分享链接
              - api_base_url: API基础URL,默认使用siliconflow.cn
              - model: 语音识别模型,默认使用FunAudioLLM/SenseVoiceSmall
              """
    )
  • The handler function that implements the logic for 'share_text_parse_tool_wrapper'. It delegates to the core 'share_text_parse_tool' utility function in utils/tools.py.
    async def share_text_parse_tool_wrapper(
        text: str,
        api_base_url: Optional[str] = None,
        model: Optional[str] = None,
        ctx: Context = None,
    ) -> Dict[str, Any]:
        """
        解析抖音分享链接,提取无水印视频地址
        下载无水印视频
        提取音频
        转换音频为文本
        清理临时文件
    
        参数:
        - text: 抖音分享文本,包含分享链接
        - api_base_url: API基础URL,默认使用SiliconFlow
        - model: 语音识别模型,默认使用SenseVoiceSmall
        """
        return await share_text_parse_tool(text, api_base_url, model, ctx)
  • Core helper function 'share_text_parse_tool' that contains the main implementation logic for parsing share text, downloading video, extracting audio, transcribing to text, and cleanup. Called by the wrapper handler.
    async def share_text_parse_tool(
        text: str,
        api_base_url: Optional[str] = None,
        model: Optional[str] = None,
        ctx: Context = None,
    ) -> Dict[str, Any]:
        """
        解析抖音分享链接,提取无水印视频地址
        下载无水印视频
        提取音频
        转换音频为文本
        清理临时文件
    
        参数:
        - text: 抖音分享文本,包含分享链接
        - api_base_url: API基础URL,默认使用SiliconFlow
        - model: 语音识别模型,默认使用SenseVoiceSmall
        """
        if not text or not isinstance(text, str):
            return create_error_response("文本参数不能为空")
        
        try:
            # 获取配置参数
            api_key, api_base_url, model = get_api_configuration(ctx, api_base_url, model)
            
            if not api_key:
                error_msg = "没有传递apikey,请通过参数传入apikey或请求头传入apikey,或者设置环境变量API_KEY,否则无法使用视频内容提取功能!"
                logger.error(error_msg)
                return create_error_response(error_msg)
    
            processor = VideoProcessor(api_key, api_base_url, model)
    
            # 解析视频链接
            video_share_url = extract_url_from_text(text)
            if not video_share_url:
                error_msg = f"无法从文本中提取视频链接: {text}"
                logger.error(error_msg)
                return create_error_response(error_msg)
    
            video_obj = await parse_video_share_url(video_share_url)
            video_info = create_success_response("解析成功", video_obj.__dict__)
    
            # 处理视频下载和文本提取
            try:
                download_video_info = {
                    "url": video_info["data"]["video_url"],
                    "title": video_info["data"]["title"],
                    "video_id": str(int(time.time())),
                }
                
                logger.info(f"开始下载视频: {download_video_info['title']}")
                video_path = await processor.download_video(download_video_info)
                ctx.info(f"视频下载地址: {video_path}")
                
                logger.info("开始提取音频")
                audio_path = processor.extract_audio(video_path)
                ctx.info(f"音频提取地址: {audio_path}")
                
                logger.info("开始转换音频为文本")
                text_content = processor.extract_text_from_audio(audio_path)
                ctx.info(f"文本提取内容: {text_content}")
                
                logger.info("清理临时文件")
                processor.cleanup_files(video_path, audio_path)
                ctx.info(f"临时文件清理: {video_path}, {audio_path}")
                
                return {
                    "code": DEFAULT_RESPONSE_CODES['SUCCESS'],
                    "msg": "解析成功",
                    "data": video_info["data"],
                    "text_content": text_content,
                }
            except Exception as processing_err:
                logger.error(f"视频处理失败: {processing_err}")
                # 确保清理可能存在的临时文件
                try:
                    if 'video_path' in locals() and 'audio_path' in locals():
                        processor.cleanup_files(video_path, audio_path)
                except Exception:
                    pass
                raise processing_err
        except ValueError as err:
            logger.error(f"参数错误: {err}")
            if ctx:
                ctx.error(f"参数错误: {str(err)}")
            return create_error_response(str(err))
        except Exception as err:
            logger.error(f"未知错误: {err}")
            if ctx:
                ctx.error(f"解析失败: {str(err)}")
            return create_error_response(f"解析失败: {str(err)}") 

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/yangbuyiya/yby6-crawling-short-video-mcp'

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