Skip to content

feat(imdb): add IMDb adapter with 6 commands#472

Merged
jackwener merged 3 commits intojackwener:mainfrom
Astro-Han:feat/imdb-adapter
Mar 26, 2026
Merged

feat(imdb): add IMDb adapter with 6 commands#472
jackwener merged 3 commits intojackwener:mainfrom
Astro-Han:feat/imdb-adapter

Conversation

@Astro-Han
Copy link
Contributor

Description

Add a public IMDb adapter using browser-based JSON-LD and __NEXT_DATA__ extraction. Covers the most common movie/TV lookup scenarios where CLI data is self-sufficient.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🌐 New site adapter
  • 📝 Documentation
  • ♻️ Refactor
  • 🔧 CI / build / tooling

Summary

Commands

Command Description Data Source
imdb search <query> Search movies, TV shows, and people __NEXT_DATA__ + DOM fallback
imdb title <id> Movie/show details (field/value) JSON-LD (schema.org)
imdb top IMDb Top 250 chart JSON-LD ItemList
imdb trending Most Popular Movies JSON-LD ItemList
imdb person <id> Actor/director info + filmography JSON-LD + __NEXT_DATA__
imdb reviews <id> User reviews (first page, max 25) DOM selectors

All 6 commands use Strategy.PUBLIC with browser: true. No API key required.

Design Decisions

  • JSON-LD first: IMDb embeds schema.org structured data in every page. More stable than DOM selectors and survives redesigns.
  • strategy: public: All data is publicly accessible. No login needed, but browser is required to bypass IMDb's WAF.
  • All TypeScript: Unified challenge detection and code reuse via shared extractJsonLd(). No YAML.
  • TV Series handling: title detects @type (Movie, TVSeries, TVEpisode, TVMiniseries, TVMovie, TVSpecial, etc.) and adjusts output (creator vs director, seasons/episodes, year range for ongoing series).

Shared Utils

utils.ts centralizes cross-cutting concerns:

  • normalizeImdbId() — bare IDs, full URLs, mobile URLs, locale-prefixed URLs
  • extractJsonLd() — type array filtering, @graph nesting, multi-script iteration
  • isChallengePage() — anti-bot verification detection
  • forceEnglishUrl() — consistent English output regardless of browser locale
  • formatDuration() — ISO 8601 (PT2H28M) to human-readable (2h 28m)

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Documentation (if adding/modifying an adapter)

  • Added doc page under docs/adapters/ (if new adapter)
  • Updated docs/adapters/index.md table (if new adapter)
  • Updated sidebar in docs/.vitepress/config.mts (if new adapter)
  • Updated README.md / README.zh-CN.md when command discoverability changed
  • Used positional args for the command's primary subject unless a named flag is clearly better
  • Normalized expected adapter failures to CliError subclasses instead of raw Error

Test plan

  • npx tsc --noEmit — zero errors
  • npx vitest run src/clis/imdb/ — 9/9 unit tests pass
  • imdb top --limit 5 — returns Top 250 chart
  • imdb trending --limit 5 — returns Most Popular Movies
  • imdb search "inception" --limit 5 — returns search results
  • imdb search "你好世界" --limit 3 — Unicode search works
  • imdb title tt1375666 — Inception (Movie)
  • imdb title tt0903747 — Breaking Bad (TVSeries, creator, no director)
  • imdb title tt0108778 — Friends (TVSeries, dual creators)
  • imdb title "https://www.imdb.com/title/tt1375666/" — full URL input
  • imdb title tt99999999 — not found error
  • imdb title invalid — format validation error
  • imdb person nm0634240 --limit 3 — Christopher Nolan + filmography
  • imdb person nm0000199 --limit 3 — Al Pacino + filmography
  • imdb reviews tt1375666 --limit 5 — deduplicated reviews
  • imdb top -f json — JSON output format
  • E2E tests added to browser-public.test.ts (3 cases: top, search, title)

Screenshots / Output

imdb top --limit 5

┌──────┬──────────────────────────┬────────┬─────────┬──────────────────────┬───────────────────────────────────────┐
│ Rank │ Title                    │ Rating │ Votes   │ Genre                │ Url                                   │
├──────┼──────────────────────────┼────────┼─────────┼──────────────────────┼───────────────────────────────────────┤
│ 1    │ The Shawshank Redemption │ 9.3    │ 3171309 │ Drama                │ https://www.imdb.com/title/tt0111161/ │
│ 2    │ The Godfather            │ 9.2    │ 2215687 │ Crime, Drama         │ https://www.imdb.com/title/tt0068646/ │
│ 3    │ The Dark Knight          │ 9.1    │ 3149909 │ Action, Crime, Drama │ https://www.imdb.com/title/tt0468569/ │
│ 4    │ The Godfather Part II    │ 9      │ 1488776 │ Crime, Drama         │ https://www.imdb.com/title/tt0071562/ │
│ 5    │ 12 Angry Men             │ 9      │ 978616  │ Crime, Drama         │ https://www.imdb.com/title/tt0050083/ │
└──────┴──────────────────────────┴────────┴─────────┴──────────────────────┴───────────────────────────────────────┘

imdb title tt1375666 (Movie)

┌───────────────┬──────────────────────────────────────────────────────────────────────────┐
│ Field         │ Value                                                                    │
├───────────────┼──────────────────────────────────────────────────────────────────────────┤
│ title         │ Inception                                                                │
│ type          │ Movie                                                                    │
│ year          │ 2010                                                                     │
│ rating        │ 8.8                                                                      │
│ votes         │ 2799913                                                                  │
│ genre         │ Action, Adventure, Sci-Fi                                                │
│ director      │ Christopher Nolan                                                        │
│ cast          │ Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page                      │
│ duration      │ 2h 28m                                                                   │
│ contentRating │ PG-13                                                                    │
│ plot          │ A thief who steals corporate secrets through the use of dream-sharing... │
│ url           │ https://www.imdb.com/title/tt1375666/                                    │
└───────────────┴──────────────────────────────────────────────────────────────────────────┘

imdb title tt0903747 (TV Series)

┌───────────────┬─────────────────────────────────────────────────────────────────────────┐
│ Field         │ Value                                                                   │
├───────────────┼─────────────────────────────────────────────────────────────────────────┤
│ title         │ Breaking Bad                                                            │
│ type          │ TVSeries                                                                │
│ year          │ 2008                                                                    │
│ rating        │ 9.5                                                                     │
│ genre         │ Crime, Drama, Thriller                                                  │
│ creator       │ Vince Gilligan                                                          │
│ cast          │ Bryan Cranston, Aaron Paul, Anna Gunn                                   │
│ contentRating │ TV-MA                                                                   │
│ plot          │ A chemistry teacher diagnosed with inoperable lung cancer turns to...   │
│ url           │ https://www.imdb.com/title/tt0903747/                                   │
└───────────────┴─────────────────────────────────────────────────────────────────────────┘

imdb search "inception" --limit 5

┌──────┬───────────┬───────────────────────────────────────┬──────┬───────┬───────────────────────────────────────┐
│ Rank │ Id        │ Title                                 │ Year │ Type  │ Url                                   │
├──────┼───────────┼───────────────────────────────────────┼──────┼───────┼───────────────────────────────────────┤
│ 1    │ tt1375666 │ Inception                             │ 2010 │       │ https://www.imdb.com/title/tt1375666/ │
│ 2    │ tt7321322 │ Inception                             │ 2014 │ Short │ https://www.imdb.com/title/tt7321322/ │
│ 3    │ tt1790736 │ Inception: The Cobol Job              │ 2010 │ Video │ https://www.imdb.com/title/tt1790736/ │
│ 4    │ tt5295990 │ Inception: Jump Right Into the Action │ 2010 │ Video │ https://www.imdb.com/title/tt5295990/ │
│ 5    │ tt8269586 │ Bikini Inception                      │ 2015 │       │ https://www.imdb.com/title/tt8269586/ │
└──────┴───────────┴───────────────────────────────────────┴──────┴───────┴───────────────────────────────────────┘

imdb person nm0634240 --limit 3

┌───────────────────────┬──────────────────────────────────────────────────────────────┐
│ Field                 │ Value                                                        │
├───────────────────────┼──────────────────────────────────────────────────────────────┤
│ birthDate             │ July 30, 1970                                                │
│ description           │ Best known for his cerebral, often nonlinear, storytelling... │
│ name                  │ Christopher Nolan                                            │
│ url                   │ https://www.imdb.com/name/nm0634240/                         │
│ filmography           │                                                              │
│ Tenet                 │ (2020) [produced by]                                         │
│ The Dark Knight Rises │ (2012) [producer]                                            │
│ Inception             │ (2010) [producer]                                            │
└───────────────────────┴──────────────────────────────────────────────────────────────┘

imdb reviews tt1375666 --limit 3

┌──────┬─────────────────────────────────────────────────────────┬────────┬──────────────────┬──────────────┬─────────────────────────────────────┐
│ Rank │ Title                                                   │ Rating │ Author           │ Date         │ Text                                │
├──────┼─────────────────────────────────────────────────────────┼────────┼──────────────────┼──────────────┼─────────────────────────────────────┤
│ 1    │ The one that stays with you long after the movie ended. │ 10     │ Didako1221       │ Jul 1, 2025  │ Few films leave you genuinely...    │
│ 2    │ A one-of-a-kind mind-blowing masterpiece!               │ 10     │ adrien_ngoc_1701 │ Mar 1, 2019  │                                     │
│ 3    │ Matrix but in dreamworld? Nah.                          │ 9      │ clipturnity      │ Aug 22, 2010 │                                     │
└──────┴─────────────────────────────────────────────────────────┴────────┴──────────────────┴──────────────┴─────────────────────────────────────┘

Astro-Han and others added 3 commits March 26, 2026 22:17
Add a public IMDb adapter using browser-based JSON-LD and __NEXT_DATA__
extraction. All commands use Strategy.PUBLIC with browser: true.

Commands:
- imdb search <query> — search movies, TV shows, and people
- imdb title <id> — get movie/show details (Movie, TVSeries, TVEpisode, TVMiniseries, TVMovie, etc.)
- imdb top — IMDb Top 250 chart
- imdb trending — Most Popular Movies
- imdb person <id> — actor/director info with filmography
- imdb reviews <id> — user reviews (first page, max 25)

Shared utils: ID normalization, ISO 8601 duration formatting, locale
forcing, JSON-LD extraction (supports type array filtering), and
anti-bot challenge detection.
@jackwener jackwener merged commit 0773616 into jackwener:main Mar 26, 2026
25 checks passed
@jackwener jackwener mentioned this pull request Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants