agentleFS
wujunwei928wujunwei928/parse-video-py/CLAUDE.md

parse-video-py

CLAUDE.md718 starsChanged 7 months agoMITView on GitHub

This is a Python-based video parsing service that extracts video information from multiple Chinese social media platforms. It removes watermarks and provides direct video URLs from 20+ platforms including Douyin, Kuaishou, Weibo, Xiaohongshu, and others. Source code lives under src/parse_video_py/ (hatchling build). BaseParser (src/parse_video_py/parser/base.py): - Abstract base class for all platform parsers - Defines VideoSource enum (25 platforms), VideoInfo, VideoAuthor, ImgInfo dataclasses - Subclasses must implement parse_share_url() and parse_video_id() Parser Routing (src/parse_video_py/parser/__init__.py): - video_source_info_mapping: VideoSource → domain_list + parser class…

  • Installs packages

The file

We split this CLAUDE.md into the rules it gives an agent

10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    isort: Import sorting (black-compatible profile)

    line 62
  2. Distinctive:

    All parsers must handle both share URLs and video IDs

    line 123
  3. Very specific:

    Default UA: fake_useragent.UserAgent(os="iOS").random (some parsers use os="windows")

    line 124
  4. Distinctive:

    Use app share links when possible.

    line 129
  5. Very specific:

    Create src/parse_video_py/parser/<name>.py inheriting from BaseParser

    line 134
  6. Very specific:

    Add enum value to VideoSource in base.py

    line 135
  7. Very specific:

    Update video_source_info_mapping in parser/__init__.py with domain list and parser class

    line 136
  8. Very specific:

    Add any platform API/short-link/redirect hosts beyond the share domains to UPSTREAM_DOMAINS in outbound.py (otherwise outbound requests get …

    line 137
  9. Very specific:

    Create HTTP clients via create_async_client(source=VideoSource.<Name>, ...) so requests go through the outbound boundary

    line 138
  10. Very specific:

    Add tests in tests/test_<name>.py

    line 140

≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

This is a Python-based video parsing service that extracts video information from multiple Chinese social media platforms. It removes watermarks and provides direct video URLs from 20+ platforms including Douyin, Kuaishou, Weibo, Xiaohongshu, and others.

Architecture

Source code lives under src/parse_video_py/ (hatchling build).

  • Web (src/parse_video_py/web.py): FastAPI app, routes, global Basic Auth middleware, MCP
  • Parsers (src/parse_video_py/parser/): 25 platform parsers inheriting BaseParser
  • Outbound boundary (src/parse_video_py/outbound.py): per-platform domain allowlist, public-IP and URL shape checks, sensitive-header stripping, response size limit (CheckedAsyncTransport); see docs/adr/0002
  • CLI (src/parse_video_py/cli/): Typer commands (parse/serve/version)
  • Utils (src/parse_video_py/utils.py): URL extraction, query param parsing, HTTP client factory with proxy/timeout defaults

Core Components

BaseParser (src/parse_video_py/parser/base.py):

  • Abstract base class for all platform parsers
  • Defines VideoSource enum (25 platforms), VideoInfo, VideoAuthor, ImgInfo dataclasses
  • Subclasses must implement parse_share_url() and parse_video_id()

Parser Routing (src/parse_video_py/parser/__init__.py):

  • video_source_info_mapping: VideoSource → domain_list + parser class
  • parse_video_share_url(): URL → domain match → parser → VideoInfo
  • parse_video_id(): VideoSource + ID → parser → VideoInfo

Development Commands

Local Development

# Create venv and install all dependencies (Python >= 3.12 required)
uv venv && uv pip install -e ".[all]"

# Install with optional groups
uv pip install -e ".[web]"      # Web server only
uv pip install -e ".[cli]"      # CLI only
uv pip install -e ".[all,dev]"  # With dev tools

# Activate venv
source .venv/bin/activate

# Run development server
uvicorn main:app --reload

# Run production server
uvicorn main:app --host 0.0.0.0 --port 8000

# CLI usage
parse-video-py parse "https://v.douyin.com/xxx"
parse-video-py parse "url1" "url2" --format json
parse-video-py parse -f urls.txt
parse-video-py serve --port 8000

Code Quality

The project uses pre-commit hooks with formatting tools:

  • Black: Code formatting (line length: 88)
  • isort: Import sorting (black-compatible profile)
  • flake8: Linting (max line length: 88)
# Install pre-commit hooks
pre-commit install

# Run formatting tools manually
black .
isort .
flake8 .

Note: The actual flake8 configuration in .pre-commit-config.yaml shows max line length as 88, but some development uses 79. Follow existing patterns in each file.

Testing

The project uses pytest with pytest-asyncio (asyncio_mode = "auto" in pyproject.toml):

# Run all tests
pytest tests/ -v --tb=short

# Run specific test files
pytest tests/test_main.py         # API endpoint tests
pytest tests/test_cli.py          # CLI command tests
pytest tests/test_utils.py        # Utility function tests
pytest tests/test_new_parsers_routing.py  # Parser routing tests
pytest tests/test_cctv.py         # Platform-specific parser tests
pytest tests/test_qqvideo.py
pytest tests/test_sohu.py
pytest tests/test_twitter.py

# Run tests with coverage
pytest --cov=parse_video_py

Docker

# Build and run
docker run -d -p 8000:8000 wujunwei928/parse-video-py

# Run with basic auth
docker run -d -p 8000:8000 -e PARSE_VIDEO_USERNAME=username -e PARSE_VIDEO_PASSWORD=password wujunwei928/parse-video-py

API Endpoints

  • GET /: Web interface
  • GET /video/share/url/parse?url=<share_url>: Parse video from share URL
  • GET /video/id/parse?source=<source>&video_id=<id>: Parse video by ID
  • MCP endpoint: http://localhost:8000/mcp (via FastAPI-MCP in web.py)

Basic Auth

Set environment variables to enable (unset = disabled):

export PARSE_VIDEO_USERNAME=username
export PARSE_VIDEO_PASSWORD=password

Important Notes

  • All parsers must handle both share URLs and video IDs
  • Default UA: fake_useragent.UserAgent(os="iOS").random (some parsers use os="windows")
  • Video URLs should be direct, watermark-free when possible
  • 25 platforms support video, 5 also support image albums (Douyin, Kuaishou, Xiaohongshu, Pipixia, Weibo)
  • LivePhoto support: Douyin and Xiaohongshu
  • Image parsers should prioritize highest quality: large > original > bmiddle > url
  • Use app share links when possible; desktop web versions may not be fully tested
  • Auth uses secrets.compare_digest() — do not replace with plain string comparison

Adding New Platforms

  1. Create src/parse_video_py/parser/<name>.py inheriting from BaseParser
  2. Add enum value to VideoSource in base.py
  3. Update video_source_info_mapping in parser/__init__.py with domain list and parser class
  4. Add any platform API/short-link/redirect hosts beyond the share domains to UPSTREAM_DOMAINS in outbound.py (otherwise outbound requests get rejected)
  5. Create HTTP clients via create_async_client(source=VideoSource.<Name>, ...) so requests go through the outbound boundary
  6. Implement parse_share_url() and parse_video_id()
  7. Add tests in tests/test_<name>.py

Direct Parser Usage

import asyncio
from parse_video_py import parse_video_share_url, parse_video_id, VideoSource

# Parse from share URL
video_info = asyncio.run(parse_video_share_url("share_url"))

# Parse from video ID
video_info = asyncio.run(parse_video_id(VideoSource.DouYin, "video_id"))

Agent skills

Issue tracker

Issues live in GitHub Issues for this repo. Use the gh CLI for all operations. See docs/agents/issue-tracker.md.

Triage labels

Uses the default five-role triage label vocabulary (needs-triage, needs-info, ready-for-agent, ready-for-human, wontfix). See docs/agents/triage-labels.md.

Domain docs

Single-context repo. Domain glossary at CONTEXT.md and ADRs at docs/adr/ in the repo root. See docs/agents/domain.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.