Skip to content

Adapter: YouTube video pages (title, channel, duration, view count) #7

Description

@New1Direction

What

Add a youtube.js adapter that turns a YouTube watch URL into read-only tools: get_video (title, channel, published date, duration, view count), get_description, and get_thumbnail.

Why it's valuable

From ADAPTERS_WANTED.md (Easy column): agents that summarize or queue content need video metadata. The approach is OpenGraph meta tags plus a parse of the ytInitialData blob embedded in the page — read-only, no auth, no cart.

Where to start

  1. Copy adapters/_templateadapters/youtube.js, ID = "youtube" (see adapters/CONTRACT.md).
  2. detect() (sync, no network): match youtube.com/watch?v=<id> and youtu.be/<id> (handle m.youtube.com too). Reject channel/playlist/shorts-listing pages if you only support watch pages in v1. Return { adapter: ID, videoId, url }.
  3. extract(): prefer the meta already passed in ctx (the chain pre-parses OG/twitter meta — see detect input shape in CONTRACT.md and how jsonld.js reads ctx.meta). For view count/duration that aren't in OG, fetch the watch page with CHROME_UA + credentials: "omit" and parse the inline ytInitialData / ytInitialPlayerResponse JSON. Wrap parsing in try/catch and degrade gracefully to OG-only fields rather than throwing.
  4. Read-only adapter: export const actions = {}.
  5. Add a fixture in _fixtures/ (a watch page, trimmed under ~200KB per _fixtures/README.md) and a detect() + extract() test in _test/run.mjs. Run node adapters/_test/run.mjs. Register in worker/src/index.ts.

Acceptance criteria

  • detect() matches watch?v=, youtu.be/, m.youtube.com and returns null for non-video URLs.
  • extract() returns { product, variants: [], tools } with at least get_video and get_description.
  • Falls back to OG meta when the ytInitialData parse fails (no hard crash on layout changes).
  • Fixture + test in place; node adapters/_test/run.mjs passes; registered in worker/src/index.ts.
  • Honors the anti-features list in ADAPTERS_WANTED.md — read-only public metadata only.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions