wechatdownload

repository·main·Indexed 27 days ago

https://github.com/qiye45/wechatdownload

A batch downloading tool for WeChat Official Account articles supporting Windows and MacOS. It allows users to download historical messages, comments, and collections in formats including HTML, MD, PDF, DOCX, MHTML, and CSV. The tool supports media downloads (images, video, audio), metadata export (view counts, likes, shares), and integrates with the Model Context Protocol (MCP) for tool calls and automation.

Tokens
3.1K
Snippets
6
Records
15
Agent score
93%

What's inside wechatdownload

  1. Overview of WeChat Official Account Batch Downloader

    main

    A tool designed for batch downloading content from WeChat Official Accounts. It supports Windows and MacOS and does not require manual certificate installation.

    Key Features:

    • Download historical messages from Official Accounts.
    • Supported formats: html, mhtml, md, pdf, docx, and csv tables.
    • Supports downloading comments, collections (columns), images, videos, and audio files.
    • Supports MCP (Model Context Protocol) and Skill calls.
    • Can export article data including view counts, likes, shares, and comment counts.
  2. How to download WeChat Official Account articles

    main

    Follow these steps to download content:

    1. Get the Official Account ID:

      • Open any article from the target Official Account.
      • Copy the article link.
      • Paste the link into the software and click 获取公众号id (Get Official Account ID).
    2. Obtain the Secret Key (Automatic):

      • Send the copied link to your 'File Transfer Assistant' (文件传输助手) in WeChat.
      • Open the link within the WeChat built-in browser.
      • Wait for a moment; the software will automatically capture the required secret key.
    3. Start Downloading:

      • Once the ID and key are acquired, you can proceed to download the articles using the software interface.

    Important Note: You MUST use the WeChat built-in browser to open the link for the key capture to work.

  3. Verify Local MCP Server Status

    main

    Before performing advanced tasks like batch downloading or exporting data, verify that the local MCP server is running at http://127.0.0.1:4545/mcp.

    If the service is unavailable, you must:

    1. Open the WeChat article download tool.
    2. Check the '启动MCP' checkbox to start the MCP service.
    3. Wait for the confirmation message indicating the service is running on port 4545.
    import requests
    
    LOCAL_MCP_ENDPOINT = "http://127.0.0.1:4545/mcp"
    
    def check_local_mcp():
        response = requests.post(
            LOCAL_MCP_ENDPOINT,
            json={"jsonrpc": "2.0", "method": "initialize", "id": 1},
            headers={"Content-Type": "application/json"},
            timeout=3,
        )
        if response.status_code != 200:
            raise RuntimeError("Local MCP is not available")
        return LOCAL_MCP_ENDPOINT
  4. Obtain Public Account Credentials (Local Only)

    main

    Before you can perform batch downloads or exports, you must obtain the public account credentials using the local get_public_account_id tool.

    Required User Action:

    1. Call the get_public_account_id tool.
    2. Copy the generated link from the tool's log window.
    3. Open the link in the WeChat desktop client (not a web browser).
    4. Wait for the tool to display the message '获取密钥成功' (credentials obtained successfully).
    def get_account_credentials():
        payload = {
            "jsonrpc": "2.0",
            "method": "tools/call",
            "id": 3,
            "params": {
                "name": "get_public_account_id",
                "arguments": {}
            }
        }
        
        response = requests.post('http://127.0.0.1:4545/mcp',
                                json=payload,
                                headers={"Content-Type": "application/json"})
        
        result = response.json()
        return result
    
    result = get_account_credentials()
    print(result)
  5. MCP and Skill Integration

    main
    The tool supports MCP (Model Context Protocol) and Skill calls. In version 4.6, MCP functionality was updated to support listening on the 0.0.0.0 address, which enables calls from WSL (Windows Subsystem for Linux).
  6. Batch Download Articles (Local Only)

    main

    Once credentials have been successfully obtained, use the batch_download_articles tool via the local MCP server to download all articles from a specific public account. The tool will download articles based on the date range and filters configured in the tool's interface and organize them by public account name.

    def batch_download_articles():
        payload = {
            "jsonrpc": "2.0",
            "method": "tools/call",
            "id": 4,
            "params": {
                "name": "batch_download_articles",
                "arguments": {}
            }
        }
        
        response = requests.post('http://127.0.0.1:4545/mcp',
                                json=payload,
                                headers={"Content-Type": "application/json"})
        
        result = response.json()
        return result
    
    result = batch_download_articles()
    print(result)
  7. Export Article Metadata to CSV (Local Only)

    main

    To export article metadata (such as titles, URLs, publish dates, read counts, and like counts) to a CSV file, use the export_article_data tool via the local MCP server. The resulting CSV file will be saved in the tool's download directory.

    def export_article_data():
        payload = {
            "jsonrpc": "2.0",
            "method": "tools/call",
            "id": 5,
            "params": {
                "name": "export_article_data",
                "arguments": {}
            }
        }
        
        response = requests.post('http://127.0.0.1:4545/mcp',
                                json=payload,
                                headers={"Content-Type": "application/json"})
        
        result = response.json()
        return result
    
    result = export_article_data()
    print(result)
  8. Download a Single WeChat Article

    main

    You can download a single article using either the local MCP tool or a remote fallback.

    Local Method: Uses the single_article_download tool via http://127.0.0.1:4545/mcp.

    Remote Fallback: If local MCP is unavailable, use the wechat tool via https://changfengbox.top/api/mcp. The remote tool accepts a config object with the following keys:

    • 保存离线网页 (Boolean)
    • HTML (Boolean)
    • MD (Boolean)
    • PDF (Boolean)
    • WORD (Boolean)
    • TXT (Boolean)
    • MHTML (Boolean)
    • 文件开头添加日期 (Boolean)
    import requests
    
    LOCAL_MCP_ENDPOINT = "http://127.0.0.1:4545/mcp"
    FALLBACK_DOWNLOAD_MCP_ENDPOINT = "https://changfengbox.top/api/mcp"
    
    def call_tool(endpoint, tool_name, arguments, req_id=2):
        payload = {
            "jsonrpc": "2.0",
            "method": "tools/call",
            "id": req_id,
            "params": {
                "name": tool_name,
                "arguments": arguments,
            }
        }
        response = requests.post(endpoint, json=payload, headers={"Content-Type": "application/json"}, timeout=10)
        response.raise_for_status()
        return response.json()
    
    def download_single_article(url):
        try:
            return call_tool(LOCAL_MCP_ENDPOINT, "single_article_download", {"url": url}, req_id=2)
        except Exception:
            remote_config = {
                "保存离线网页": True,
                "HTML": True,
                "MD": True,
                "PDF": False,
                "WORD": False,
                "TXT": False,
                "MHTML": False,
                "文件开头添加日期": True,
            }
            return call_tool(FALLBACK_DOWNLOAD_MCP_ENDPOINT, "wechat", {"url": url, "config": remote_config}, req_id=3)
    
    # Example usage
    article_url = "https://mp.weixin.qq.com/s/xxxxx"
    result = download_single_article(article_url)
    print(result)
  9. Download a WeChat Collection (appmsgalbum)

    main

    To download a collection of articles, use the remote fallback MCP (https://changfengbox.top/api/mcp) with the tool name wechat_collection. This requires a collection URL passed in the arguments.

    def download_collection(collection_url):
        payload = {
            "jsonrpc": "2.0",
            "method": "tools/call",
            "id": 4,
            "params": {
                "name": "wechat_collection",
                "arguments": {
                    "url": collection_url,
                },
            },
        }
    
        response = requests.post(
            "https://changfengbox.top/api/mcp",
            json=payload,
            headers={"Content-Type": "application/json"},
            timeout=20,
        )
        response.raise_for_status()
        return response.json()
  10. Perform OCR using Ollama or Gemini

    main

    There are two primary open-source approaches for web-based OCR (Optical Character Recognition) using large vision models:

    1. Ollama OCR for web: An open-source tool that includes a built-in Web frontend.
    2. Gemini-based OCR: An alternative implementation leveraging Google's Gemini models for recognition.