Skip to main content
Glama

parse_douyin_video_info

Extract video metadata from Douyin share links to access details like title, author, and URL for analysis or integration.

Instructions

解析抖音分享链接,获取视频基本信息

参数:
- share_link: 抖音分享链接或包含链接的文本

返回:
- 视频信息(JSON格式字符串)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
share_linkYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'parse_douyin_video_info' tool, decorated with @mcp.tool() for registration. It creates a DouyinProcessor instance and calls parse_share_url to extract video information from the share link, returning JSON.
    @mcp.tool()
    def parse_douyin_video_info(share_link: str) -> str:
        """
        解析抖音分享链接,获取视频基本信息
        
        参数:
        - share_link: 抖音分享链接或包含链接的文本
        
        返回:
        - 视频信息(JSON格式字符串)
        """
        try:
            processor = DouyinProcessor("")  # 不需要API密钥来解析链接
            video_info = processor.parse_share_url(share_link)
            
            return json.dumps({
                "video_id": video_info["video_id"],
                "title": video_info["title"],
                "download_url": video_info["url"],
                "status": "success"
            }, ensure_ascii=False, indent=2)
            
        except Exception as e:
            return json.dumps({
                "status": "error",
                "error": str(e)
            }, ensure_ascii=False, indent=2)
  • Helper method in DouyinProcessor class that performs the actual parsing of the Douyin share URL to extract video ID, title, and no-watermark URL. This is the core implementation logic called by the tool handler.
    def parse_share_url(self, share_text: str) -> dict:
        """从分享文本中提取无水印视频链接"""
        # 提取分享链接
        urls = re.findall(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', share_text)
        if not urls:
            raise ValueError("未找到有效的分享链接")
        
        share_url = urls[0]
        share_response = requests.get(share_url, headers=HEADERS)
        video_id = share_response.url.split("?")[0].strip("/").split("/")[-1]
        share_url = f'https://www.iesdouyin.com/share/video/{video_id}'
        
        # 获取视频页面内容
        response = requests.get(share_url, headers=HEADERS)
        response.raise_for_status()
        
        pattern = re.compile(
            pattern=r"window\._ROUTER_DATA\s*=\s*(.*?)</script>",
            flags=re.DOTALL,
        )
        find_res = pattern.search(response.text)
    
        if not find_res or not find_res.group(1):
            raise ValueError("从HTML中解析视频信息失败")
    
        # 解析JSON数据
        json_data = json.loads(find_res.group(1).strip())
        VIDEO_ID_PAGE_KEY = "video_(id)/page"
        NOTE_ID_PAGE_KEY = "note_(id)/page"
        
        if VIDEO_ID_PAGE_KEY in json_data["loaderData"]:
            original_video_info = json_data["loaderData"][VIDEO_ID_PAGE_KEY]["videoInfoRes"]
        elif NOTE_ID_PAGE_KEY in json_data["loaderData"]:
            original_video_info = json_data["loaderData"][NOTE_ID_PAGE_KEY]["videoInfoRes"]
        else:
            raise Exception("无法从JSON中解析视频或图集信息")
    
        data = original_video_info["item_list"][0]
    
        # 获取视频信息
        video_url = data["video"]["play_addr"]["url_list"][0].replace("playwm", "play")
        desc = data.get("desc", "").strip() or f"douyin_{video_id}"
        
        # 替换文件名中的非法字符
        desc = re.sub(r'[\\/:*?"<>|]', '_', desc)
        
        return {
            "url": video_url,
            "title": desc,
            "video_id": video_id
        }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions parsing links and returning JSON-formatted video information, but lacks details on error handling, rate limits, authentication needs, or what specific video fields are included. For a tool with no annotation coverage, this leaves significant gaps in understanding its operational behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with a clear purpose statement followed by brief sections for parameters and returns. Each sentence adds value without redundancy. Minor improvements could include bullet points or more structured formatting, but it remains efficient and well-organized.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter, no nested objects) and the presence of an output schema (which handles return values), the description is reasonably complete. It covers the purpose, parameter semantics, and output format. However, it lacks behavioral details like error cases or performance considerations, which would enhance completeness for a tool with no annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful context beyond the input schema, which has 0% coverage. It explains that 'share_link' can be a Douyin share link or text containing a link, clarifying the parameter's purpose and acceptable formats. With only one parameter and no schema descriptions, this compensation is effective, though not exhaustive (e.g., no examples or validation rules).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '解析抖音分享链接,获取视频基本信息' (Parse Douyin share links to obtain basic video information). It specifies the verb ('解析' - parse) and resource ('抖音分享链接' - Douyin share links), and distinguishes from siblings like 'extract_douyin_text' and 'get_douyin_download_link' by focusing on video metadata rather than text extraction or download links. However, it doesn't explicitly contrast with siblings, keeping it at 4 instead of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools ('extract_douyin_text' or 'get_douyin_download_link') or specify scenarios where this tool is preferred, such as for metadata retrieval versus content extraction. Usage is implied by the purpose but lacks explicit context or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/yzfly/douyin-mcp-server'

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