@pencil-agent/nano-pencil 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +267 -267
  2. package/dist/build-meta.json +3 -3
  3. package/dist/core/export-html/AGENT.md +11 -11
  4. package/dist/core/export-html/template.css +971 -971
  5. package/dist/core/export-html/template.html +54 -54
  6. package/dist/core/mcp/mcp-client.d.ts +3 -1
  7. package/dist/core/mcp/mcp-client.js +6 -6
  8. package/dist/core/mcp/mcp-config.d.ts +3 -3
  9. package/dist/core/mcp/mcp-config.js +1 -1
  10. package/dist/core/mcp/mcp-manager.d.ts +5 -1
  11. package/dist/core/mcp/mcp-manager.js +1 -1
  12. package/dist/core/platform/config/resource-loader.d.ts +2 -0
  13. package/dist/core/platform/config/resource-loader.js +2 -2
  14. package/dist/core/runtime/agent-session.d.ts +12 -0
  15. package/dist/core/runtime/agent-session.js +8 -8
  16. package/dist/core/runtime/sdk.d.ts +8 -0
  17. package/dist/core/runtime/sdk.js +1 -1
  18. package/dist/extensions/builtin/AGENT.md +115 -115
  19. package/dist/extensions/builtin/browser/AGENT.md +17 -17
  20. package/dist/extensions/builtin/browser/agent-workspace/agent_helpers.py +12 -12
  21. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/amazon/product-search.md +198 -198
  22. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/archive-org/scraping.md +341 -341
  23. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/arxiv/scraping.md +311 -311
  24. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/arxiv-bulk/scraping.md +333 -333
  25. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/atlas/overview.md +70 -70
  26. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/booking-com/scraping.md +578 -578
  27. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/capterra/scraping.md +440 -440
  28. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/centilebrain/generate-estimates.md +110 -110
  29. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coingecko/scraping.md +325 -325
  30. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coinmarketcap/scraping.md +463 -463
  31. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/coursera/scraping.md +360 -360
  32. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/craigslist/scraping.md +390 -390
  33. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/crossref/scraping.md +568 -568
  34. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/dev-to/scraping.md +323 -323
  35. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/duckduckgo/scraping.md +349 -349
  36. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/ebay/scraping.md +435 -435
  37. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/etsy/scraping.md +506 -506
  38. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/eventbrite/scraping.md +363 -363
  39. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/expedia/automation.md +168 -168
  40. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/facebook/groups.md +236 -236
  41. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/facebook/pages.md +295 -295
  42. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/framer/editor.md +108 -108
  43. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/fred/scraping.md +493 -493
  44. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/g2/scraping.md +580 -580
  45. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/genius/scraping.md +511 -511
  46. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/github/repo-actions.md +65 -65
  47. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/github/scraping.md +184 -184
  48. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/glassdoor/scraping.md +543 -543
  49. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/gmail/compose.md +122 -122
  50. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/goodreads/scraping.md +461 -461
  51. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/gutenberg/scraping.md +383 -383
  52. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/hackernews/scraping.md +243 -243
  53. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/howlongtobeat/scraping.md +473 -473
  54. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/imdb/scraping.md +271 -271
  55. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/itch-io/scraping.md +436 -436
  56. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/job-boards/indeed-glassdoor.md +1021 -1021
  57. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/letterboxd/scraping.md +349 -349
  58. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/linkedin/invitation-manager.md +109 -109
  59. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/loom/folder-enumeration.md +170 -170
  60. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/macrotrends/scraping.md +537 -537
  61. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/medium/article-hydration.md +120 -120
  62. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/medium/scraping.md +414 -414
  63. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/metacritic/scraping.md +477 -477
  64. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/musicbrainz/scraping.md +478 -478
  65. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/nasa/scraping.md +339 -339
  66. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/news-aggregation/multi-source.md +205 -205
  67. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/open-library/scraping.md +472 -472
  68. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/openalex/scraping.md +470 -470
  69. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/openstreetmap/scraping.md +490 -490
  70. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/package-registries/npm-pypi.md +478 -478
  71. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/polymarket/scraping.md +234 -234
  72. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/producthunt/scraping.md +307 -307
  73. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/pubmed/scraping.md +421 -421
  74. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/quora/scraping.md +364 -364
  75. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/rawg/scraping.md +352 -352
  76. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/reddit/scraping.md +124 -124
  77. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/rest-countries/scraping.md +233 -233
  78. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/sec-edgar/scraping.md +361 -361
  79. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/README.md +36 -36
  80. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/embedded-apps.md +72 -72
  81. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/knowledge-base.md +109 -109
  82. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/shopify-admin/polaris-inputs.md +137 -137
  83. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/soundcloud/scraping.md +362 -362
  84. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/spotify/scraping.md +339 -339
  85. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/stackoverflow/scraping.md +435 -435
  86. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/steam/scraping.md +575 -575
  87. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/substack/scraping.md +338 -338
  88. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/thetechgeeks/pricing.md +52 -52
  89. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/tiktok/upload.md +107 -107
  90. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/tradingview/scraping.md +309 -309
  91. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/trello/boards-and-lists.md +88 -88
  92. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/trustpilot/scraping.md +375 -375
  93. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/walmart/scraping.md +444 -444
  94. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/wayback-machine/scraping.md +306 -306
  95. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/weather/scraping.md +398 -398
  96. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/wellfound/scraping.md +596 -596
  97. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/world-bank/scraping.md +356 -356
  98. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/xiaohongshu/scraping.md +84 -84
  99. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/youtube/scraping.md +418 -418
  100. package/dist/extensions/builtin/browser/agent-workspace/domain-skills/zillow/scraping.md +433 -433
  101. package/dist/extensions/builtin/browser/browser.md +73 -73
  102. package/dist/extensions/builtin/browser/install.md +142 -142
  103. package/dist/extensions/builtin/browser/interaction-skills/connection.md +48 -48
  104. package/dist/extensions/builtin/browser/interaction-skills/cookies.md +3 -3
  105. package/dist/extensions/builtin/browser/interaction-skills/cross-origin-iframes.md +3 -3
  106. package/dist/extensions/builtin/browser/interaction-skills/dialogs.md +64 -64
  107. package/dist/extensions/builtin/browser/interaction-skills/downloads.md +3 -3
  108. package/dist/extensions/builtin/browser/interaction-skills/drag-and-drop.md +3 -3
  109. package/dist/extensions/builtin/browser/interaction-skills/dropdowns.md +3 -3
  110. package/dist/extensions/builtin/browser/interaction-skills/iframes.md +3 -3
  111. package/dist/extensions/builtin/browser/interaction-skills/network-requests.md +3 -3
  112. package/dist/extensions/builtin/browser/interaction-skills/print-as-pdf.md +3 -3
  113. package/dist/extensions/builtin/browser/interaction-skills/profile-sync.md +90 -90
  114. package/dist/extensions/builtin/browser/interaction-skills/screenshots.md +17 -17
  115. package/dist/extensions/builtin/browser/interaction-skills/scrolling.md +3 -3
  116. package/dist/extensions/builtin/browser/interaction-skills/shadow-dom.md +3 -3
  117. package/dist/extensions/builtin/browser/interaction-skills/tabs.md +69 -69
  118. package/dist/extensions/builtin/browser/interaction-skills/uploads.md +1 -1
  119. package/dist/extensions/builtin/browser/interaction-skills/viewport.md +3 -3
  120. package/dist/extensions/builtin/browser/src/browser_harness/AGENT.md +15 -15
  121. package/dist/extensions/builtin/browser/src/browser_harness/__init__.py +8 -8
  122. package/dist/extensions/builtin/browser/src/browser_harness/_ipc.py +90 -90
  123. package/dist/extensions/builtin/browser/src/browser_harness/admin.py +722 -722
  124. package/dist/extensions/builtin/browser/src/browser_harness/daemon.py +328 -328
  125. package/dist/extensions/builtin/browser/src/browser_harness/helpers.py +396 -396
  126. package/dist/extensions/builtin/browser/src/browser_harness/run.py +103 -103
  127. package/dist/extensions/builtin/discipline/skills/brainstorming/SKILL.md +33 -33
  128. package/dist/extensions/builtin/discipline/skills/executing-plans/SKILL.md +25 -25
  129. package/dist/extensions/builtin/discipline/skills/finishing-development-branch/SKILL.md +25 -25
  130. package/dist/extensions/builtin/discipline/skills/receiving-code-review/SKILL.md +22 -22
  131. package/dist/extensions/builtin/discipline/skills/requesting-code-review/SKILL.md +31 -31
  132. package/dist/extensions/builtin/discipline/skills/systematic-debugging/SKILL.md +28 -28
  133. package/dist/extensions/builtin/discipline/skills/test-driven-development/SKILL.md +32 -32
  134. package/dist/extensions/builtin/discipline/skills/using-git-worktrees/SKILL.md +25 -25
  135. package/dist/extensions/builtin/discipline/skills/verification-before-completion/SKILL.md +27 -27
  136. package/dist/extensions/builtin/discipline/skills/writing-plans/SKILL.md +26 -26
  137. package/dist/extensions/builtin/goal/README.md +67 -67
  138. package/dist/extensions/builtin/grub/README.md +112 -112
  139. package/dist/extensions/builtin/link-world/agent-workspace/README.md +16 -16
  140. package/dist/extensions/builtin/link-world/internet-search/internet-search.md +65 -65
  141. package/dist/extensions/builtin/link-world/link-world-agent.md +82 -82
  142. package/dist/extensions/builtin/link-world/linkworld.md +313 -313
  143. package/dist/extensions/builtin/link-world/network-routing/network-routing.md +67 -67
  144. package/dist/extensions/builtin/loop/README.md +92 -92
  145. package/dist/extensions/builtin/mcp/figma-design.md +68 -68
  146. package/dist/extensions/builtin/mcp/mcp-management.md +85 -85
  147. package/dist/extensions/builtin/recap/AGENT.md +15 -15
  148. package/dist/extensions/builtin/sal/README.md +72 -72
  149. package/dist/extensions/builtin/security-audit/README.md +289 -289
  150. package/dist/extensions/builtin/team/AGENT.md +112 -112
  151. package/dist/extensions/builtin/team/TESTING.md +299 -299
  152. package/dist/extensions/builtin/token-save/README.md +56 -56
  153. package/dist/extensions/optional/AGENT.md +10 -10
  154. package/dist/modes/interactive/interactive-mode.js +36 -36
  155. package/dist/modes/interactive/theme/dark.json +85 -85
  156. package/dist/modes/interactive/theme/light.json +84 -84
  157. package/dist/modes/interactive/theme/theme-schema.json +335 -335
  158. package/dist/modes/interactive/theme/warm.json +81 -81
  159. package/dist/node_modules/@pencil-agent/agent-core/dist/agent-loop.js +3 -2
  160. package/dist/node_modules/@pencil-agent/agent-core/dist/structured-adaptive-agent-loop.js +2 -1
  161. package/dist/node_modules/@pencil-agent/ai/dist/cli.js +0 -0
  162. package/docs/cc-agent-design.md +1297 -0
  163. package/docs/cc-tui-design.md +1333 -0
  164. package/docs/codex-goal-command-impl.md +1055 -1055
  165. package/docs/codex-goal-vs-grub.md +500 -500
  166. package/docs/custom-provider.md +27 -27
  167. package/docs/extensions.md +27 -27
  168. package/docs/keybindings.md +27 -27
  169. package/docs/loop /351/207/215/346/236/204/345/256/214/346/210/220/346/200/273/347/273/223.md" +250 -250
  170. package/docs/loop /351/207/215/346/236/204/345/256/214/346/210/220/346/212/245/345/221/212.md" +122 -122
  171. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210.md" +1222 -1222
  172. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210/345/256/236/347/216/260/346/212/245/345/221/212.md" +158 -158
  173. package/docs/loop /351/207/215/346/236/204/346/226/271/346/241/210/345/257/271/346/257/224/345/210/206/346/236/220.md" +128 -128
  174. package/docs/loop /351/207/215/346/236/204/350/256/241/345/210/222.md" +320 -320
  175. package/docs/loop-usage-examples.md +214 -214
  176. package/docs/models.md +27 -27
  177. package/docs/nanoPencil-/345/255/246/344/271/240/350/256/241/345/210/222.md +170 -0
  178. package/docs/packages.md +27 -27
  179. package/docs/pi-design-philosophy.md +457 -457
  180. package/docs/planmode.md +1987 -1987
  181. package/docs/prompt-templates.md +27 -27
  182. package/docs/providers.md +27 -27
  183. package/docs/scan-report.md +3820 -0
  184. package/docs/sdk.md +27 -27
  185. package/docs/skills.md +27 -27
  186. package/docs/themes.md +27 -27
  187. package/docs/tui.md +27 -27
  188. package/docs//345/257/271/346/240/207Claude-Code.md +1775 -0
  189. package/docs//351/230/277/351/207/214/345/267/264/345/267/264/350/264/242/346/212/245/345/210/206/346/236/220/344/271/246.md +261 -0
  190. package/package.json +190 -190
  191. package/docs/ACP/345/215/217/350/256/256/351/233/206/346/210/220/345/274/200/345/217/221/346/226/207/346/241/243.md +0 -851
  192. package/docs/SDK-TESTING.md +0 -364
  193. package/docs/mem-core/346/212/200/346/234/257/346/226/207/346/241/243.md +0 -593
  194. package/docs/startup-performance-optimization.md +0 -301
  195. package/docs//350/256/244/347/237/245/345/234/260/345/233/276.md +0 -47
@@ -1,477 +1,477 @@
1
- # Metacritic — Scraping & Data Extraction
2
-
3
- Field-tested against metacritic.com on 2026-04-18. All code blocks validated with live requests.
4
-
5
- ## Do this first
6
-
7
- **Use the backend API — it returns clean JSON with both scores in one call, no HTML parsing.**
8
-
9
- Metacritic's internal backend API is publicly accessible with a stable key embedded in every page. It covers games, movies, and TV shows.
10
-
11
- ```python
12
- import json
13
-
14
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
15
-
16
- def get_game_scores(slug):
17
- """slug = URL slug e.g. 'elden-ring', 'the-last-of-us'"""
18
- base = f"https://backend.metacritic.com"
19
- product = json.loads(http_get(
20
- f"{base}/games/metacritic/{slug}/web"
21
- f"?componentName=product&componentType=Product&apiKey={API_KEY}"
22
- ))
23
- user_stats = json.loads(http_get(
24
- f"{base}/reviews/metacritic/user/games/{slug}/stats/web"
25
- f"?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"
26
- ))
27
- item = product["data"]["item"]
28
- crit = item["criticScoreSummary"]
29
- user = user_stats["data"]["item"]
30
- return {
31
- "title": item["title"],
32
- "platform": item["platform"], # lead platform
33
- "platforms": item["platforms"], # list with per-platform scores
34
- "metascore": crit["score"], # int 0–100 or None
35
- "critic_reviews": crit["reviewCount"], # int
36
- "critic_sentiment": crit["sentiment"], # e.g. "Universal acclaim"
37
- "user_score": user["score"], # float 0.0–10.0 or None
38
- "user_reviews": user["reviewCount"], # int
39
- "user_sentiment": user["sentiment"],
40
- "release_date": item["releaseDate"], # "YYYY-MM-DD"
41
- }
42
-
43
- print(get_game_scores("the-last-of-us"))
44
- # {'title': 'The Last of Us', 'platform': 'PlayStation 3',
45
- # 'metascore': 95, 'critic_reviews': 98,
46
- # 'user_score': 9.2, 'user_reviews': 17207, ...}
47
- ```
48
-
49
- Use the browser **only** if you need music pages — `metacritic.com/music/*` returns HTTP 403 to `http_get` (Cloudflare blocks those routes). Games, movies, and TV all work with plain HTTP.
50
-
51
- ---
52
-
53
- ## Fastest approach: JSON-LD (critic score + review count only)
54
-
55
- If you only need the Metascore and critic review count and don't need the user score, JSON-LD is the single-call option — no API key, no separate request:
56
-
57
- ```python
58
- import json, re
59
-
60
- url = "https://www.metacritic.com/game/elden-ring/" # or /movie/ or /tv/
61
- html = http_get(url)
62
-
63
- block = re.findall(
64
- r'<script[^>]*type="application/ld\+json"[^>]*>(.*?)</script>',
65
- html, re.DOTALL
66
- )[0]
67
- ld = json.loads(block)
68
-
69
- agg = ld["aggregateRating"]
70
- print(ld["name"]) # "Elden Ring"
71
- print(agg["ratingValue"]) # 96 (metascore)
72
- print(agg["reviewCount"]) # 93 (critic reviews count)
73
- print(ld.get("gamePlatform")) # ['Xbox One', 'PC', 'PlayStation 4', 'Xbox Series X', 'PlayStation 5']
74
- print(ld.get("genre")) # "Action RPG"
75
- print(ld.get("contentRating")) # "M"
76
- print(ld.get("datePublished")) # "2022-02-25"
77
- ```
78
-
79
- **JSON-LD limitations:**
80
- - Only contains Metascore and critic review count — **no user score, no user review count**.
81
- - For multi-platform games, `ratingValue` is the lead platform score; all platforms are listed in `gamePlatform` but without individual scores.
82
- - `@type` is `VideoGame` for games, `Movie` for movies, `TVSeries` for TV shows.
83
-
84
- ---
85
-
86
- ## Common workflows
87
-
88
- ### Get scores for a single title (backend API)
89
-
90
- ```python
91
- import json
92
-
93
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
94
- BASE = "https://backend.metacritic.com"
95
-
96
- # Games
97
- def game_scores(slug):
98
- p = json.loads(http_get(f"{BASE}/games/metacritic/{slug}/web?componentName=product&componentType=Product&apiKey={API_KEY}"))
99
- u = json.loads(http_get(f"{BASE}/reviews/metacritic/user/games/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"))
100
- c = p["data"]["item"]["criticScoreSummary"]
101
- us = u["data"]["item"]
102
- return {"metascore": c["score"], "critic_reviews": c["reviewCount"],
103
- "user_score": us["score"], "user_reviews": us["reviewCount"]}
104
-
105
- # Movies
106
- def movie_scores(slug):
107
- p = json.loads(http_get(f"{BASE}/movies/metacritic/{slug}/web?componentName=product&componentType=Product&apiKey={API_KEY}"))
108
- u = json.loads(http_get(f"{BASE}/reviews/metacritic/user/movies/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"))
109
- c = p["data"]["item"]["criticScoreSummary"]
110
- us = u["data"]["item"]
111
- return {"metascore": c["score"], "critic_reviews": c["reviewCount"],
112
- "user_score": us["score"], "user_reviews": us["reviewCount"]}
113
-
114
- # TV shows
115
- def show_scores(slug):
116
- p = json.loads(http_get(f"{BASE}/shows/metacritic/{slug}/web?componentName=product&componentType=Product&apiKey={API_KEY}"))
117
- u = json.loads(http_get(f"{BASE}/reviews/metacritic/user/shows/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"))
118
- c = p["data"]["item"]["criticScoreSummary"]
119
- us = u["data"]["item"]
120
- return {"metascore": c["score"], "critic_reviews": c["reviewCount"],
121
- "user_score": us["score"], "user_reviews": us["reviewCount"]}
122
-
123
- # Verified results:
124
- print(game_scores("the-last-of-us"))
125
- # {'metascore': 95, 'critic_reviews': 98, 'user_score': 9.2, 'user_reviews': 17207}
126
- print(movie_scores("the-godfather"))
127
- # {'metascore': 100, 'critic_reviews': 16, 'user_score': 9.2, 'user_reviews': 4450}
128
- print(show_scores("breaking-bad"))
129
- # {'metascore': 87, 'critic_reviews': 98, 'user_score': 9.4, 'user_reviews': 19070}
130
- ```
131
-
132
- ### Parallel fetching (multiple titles at once)
133
-
134
- 10 API calls in 0.68s with 5 workers — no rate-limit errors:
135
-
136
- ```python
137
- import json
138
- from concurrent.futures import ThreadPoolExecutor
139
- import urllib.request, gzip
140
-
141
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
142
-
143
- def _fetch(url):
144
- h = {"User-Agent": "Mozilla/5.0", "Accept-Encoding": "gzip"}
145
- with urllib.request.urlopen(urllib.request.Request(url, headers=h), timeout=15) as r:
146
- data = r.read()
147
- if r.headers.get("Content-Encoding") == "gzip": data = gzip.decompress(data)
148
- return json.loads(data.decode())
149
-
150
- def batch_game_scores(slugs, workers=5):
151
- """Fetch critic+user scores for multiple game slugs in parallel."""
152
- BASE = "https://backend.metacritic.com"
153
- AK = f"apiKey={API_KEY}"
154
-
155
- def fetch_one(slug):
156
- c = _fetch(f"{BASE}/reviews/metacritic/critic/games/{slug}/stats/web?componentName=critic-score-summary&componentType=ScoreSummary&{AK}")
157
- u = _fetch(f"{BASE}/reviews/metacritic/user/games/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&{AK}")
158
- ci = c["data"]["item"]
159
- ui = u["data"]["item"]
160
- return {"slug": slug, "metascore": ci["score"], "critic_reviews": ci["reviewCount"],
161
- "user_score": ui["score"], "user_reviews": ui["reviewCount"]}
162
-
163
- with ThreadPoolExecutor(max_workers=workers) as ex:
164
- return list(ex.map(fetch_one, slugs))
165
-
166
- results = batch_game_scores([
167
- "the-last-of-us", "elden-ring", "god-of-war",
168
- "red-dead-redemption-2", "the-witcher-3-wild-hunt"
169
- ])
170
- # the-last-of-us: meta=95/98critics, user=9.2/17207
171
- # elden-ring: meta=96/86critics, user=8.4/23344
172
- # god-of-war: meta=94/118critics, user=9.0/30439
173
- # red-dead-redemption-2: meta=97/99critics, user=9.0/35306
174
- # the-witcher-3-wild-hunt: meta=92/79critics, user=9.1/19370
175
- ```
176
-
177
- ### Search by title
178
-
179
- ```python
180
- import json, urllib.parse
181
-
182
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
183
-
184
- def search(query, media_type=None, limit=10):
185
- """
186
- media_type: None='all', 'games' (mcoTypeId=13), 'movies' (2), 'shows' (1)
187
- Returns list of {title, type, slug, premiereYear, metascore, user_score}
188
- """
189
- type_map = {"games": 13, "movies": 2, "shows": 1}
190
- q = urllib.parse.quote(query)
191
- type_param = f"&mcoTypeId={type_map[media_type]}" if media_type else "&mcoTypeId=1%2C2%2C3%2C13"
192
- url = (
193
- f"https://backend.metacritic.com/finder/metacritic/search/{q}/web"
194
- f"?offset=0&limit={limit}&sortBy=META_SCORE&sortDirection=DESC"
195
- f"{type_param}&componentName=search&componentType=SearchResult"
196
- f"&apiKey={API_KEY}"
197
- )
198
- data = json.loads(http_get(url))
199
- items = data["data"]["items"]
200
- return [
201
- {
202
- "title": i["title"],
203
- "type": i["type"], # "game-title", "movie", "tv-show"
204
- "slug": i["slug"],
205
- "year": i.get("premiereYear"),
206
- "metascore": i.get("criticScoreSummary", {}).get("score"),
207
- "user_score": i.get("userScore"), # None in search results (use stats API for this)
208
- }
209
- for i in items
210
- ]
211
-
212
- results = search("elden ring", media_type="games")
213
- # [{'title': 'Elden Ring', 'type': 'game-title', 'slug': 'elden-ring', 'year': 2022, 'metascore': 96, ...}]
214
- ```
215
-
216
- **Note:** `userScore` is `None` in search results. Call the stats API with the `slug` to get it.
217
-
218
- ### Browse/list titles by score
219
-
220
- ```python
221
- import json
222
-
223
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
224
-
225
- def browse_games(sort_by="-metaScore", year_min=None, year_max=None, offset=0, limit=24):
226
- """
227
- sort_by: '-metaScore' | '-releaseDate' | '-popularityCount'
228
- Returns up to `limit` games with criticScoreSummary and userScore.
229
- Total available: ~14,160 games.
230
- """
231
- params = f"sortBy={sort_by}&mcoTypeId=13&offset={offset}&limit={limit}"
232
- if year_min: params += f"&releaseYearMin={year_min}"
233
- if year_max: params += f"&releaseYearMax={year_max}"
234
- url = f"https://backend.metacritic.com/finder/metacritic/web?{params}&componentName=finder&componentType=Finder&apiKey={API_KEY}"
235
- data = json.loads(http_get(url))
236
- total = data["data"]["totalResults"]
237
- items = data["data"]["items"]
238
- return total, [
239
- {
240
- "title": i["title"],
241
- "slug": i["slug"],
242
- "year": i.get("premiereYear"),
243
- "metascore": i.get("criticScoreSummary", {}).get("score"),
244
- "critic_reviews": i.get("criticScoreSummary", {}).get("reviewCount"),
245
- "user_score": i.get("userScore", {}).get("score") if isinstance(i.get("userScore"), dict) else i.get("userScore"),
246
- }
247
- for i in items
248
- ]
249
-
250
- total, games = browse_games(year_min=2023, year_max=2024)
251
- print(f"{total} games 2023-2024") # 953
252
- for g in games[:3]:
253
- print(g)
254
- # {'title': "Baldur's Gate 3", 'year': 2023, 'metascore': 96, 'user_score': 9.2}
255
- # {'title': 'The Legend of Zelda: Tears of the Kingdom', 'year': 2023, 'metascore': 96, ...}
256
- ```
257
-
258
- Finder API totals (confirmed 2026-04-18):
259
- - Games (mcoTypeId=13): 14,160
260
- - Movies (mcoTypeId=2): 17,152
261
- - TV Shows (mcoTypeId=1): 3,392
262
-
263
- ### Get per-platform scores for multi-platform games
264
-
265
- ```python
266
- import json
267
-
268
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
269
-
270
- def game_platforms(slug):
271
- url = (
272
- f"https://backend.metacritic.com/games/metacritic/{slug}/web"
273
- f"?componentName=product&componentType=Product&apiKey={API_KEY}"
274
- )
275
- data = json.loads(http_get(url))
276
- platforms = data["data"]["item"]["platforms"]
277
- return [
278
- {
279
- "name": p["name"],
280
- "slug": p["slug"],
281
- "is_lead": p["isLeadPlatform"],
282
- "metascore": p["criticScoreSummary"]["score"], # None if <4 reviews
283
- "critic_reviews": p["criticScoreSummary"]["reviewCount"],
284
- "release_date": p["releaseDate"],
285
- }
286
- for p in platforms
287
- ]
288
-
289
- print(game_platforms("elden-ring"))
290
- # [{'name': 'Xbox One', 'slug': 'xbox-one', 'is_lead': False, 'metascore': None, ...},
291
- # {'name': 'PC', 'slug': 'pc', 'is_lead': False, 'metascore': 94, 'critic_reviews': 63},
292
- # {'name': 'PlayStation 4', 'slug': 'playstation-4', 'is_lead': False, 'metascore': None, 'critic_reviews': 1},
293
- # {'name': 'Xbox Series X', 'slug': 'xbox-series-x', 'is_lead': False, 'metascore': 96, 'critic_reviews': 19},
294
- # {'name': 'PlayStation 5', 'slug': 'playstation-5', 'is_lead': True, 'metascore': 96, 'critic_reviews': 93}]
295
- ```
296
-
297
- ### Get critic reviews (paginated)
298
-
299
- ```python
300
- import json
301
-
302
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
303
-
304
- def get_critic_reviews(slug, media="games", offset=0, limit=10, sort="date"):
305
- """sort: 'date' | 'score' | 'publication'"""
306
- url = (
307
- f"https://backend.metacritic.com/reviews/metacritic/critic/{media}/{slug}/web"
308
- f"?offset={offset}&limit={limit}&sort={sort}"
309
- f"&componentName=latest-critic-reviews&componentType=CriticReviewList&apiKey={API_KEY}"
310
- )
311
- data = json.loads(http_get(url))
312
- total = data["data"]["totalResults"] # e.g. 98
313
- items = data["data"]["items"]
314
- return total, [
315
- {
316
- "score": r["score"], # int 0–100
317
- "publication": r["publicationName"],
318
- "quote": r["quote"],
319
- "date": r["date"],
320
- "url": r.get("url"),
321
- }
322
- for r in items
323
- ]
324
-
325
- total, reviews = get_critic_reviews("the-last-of-us", sort="score")
326
- print(f"{total} critic reviews") # 98
327
- print(reviews[0])
328
- # {'score': 97, 'publication': 'GamingXP', 'quote': 'Flawless in its ambition...', 'date': '...'}
329
- ```
330
-
331
- ### Get user reviews (paginated)
332
-
333
- ```python
334
- import json
335
-
336
- API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
337
-
338
- def get_user_reviews(slug, media="games", offset=0, limit=10, order_by="score", order_type="desc"):
339
- """order_by: 'score' | 'date' | 'helpfulness'"""
340
- url = (
341
- f"https://backend.metacritic.com/reviews/metacritic/user/{media}/{slug}/web"
342
- f"?offset={offset}&limit={limit}&orderBy={order_by}&orderType={order_type}"
343
- f"&componentName=top-user-reviews&componentType=UserReviewList&apiKey={API_KEY}"
344
- )
345
- data = json.loads(http_get(url))
346
- total = data["data"]["totalResults"] # e.g. 2983 for The Last of Us
347
- items = data["data"]["items"]
348
- return total, [
349
- {
350
- "score": r["score"], # int 0–10
351
- "quote": r["quote"],
352
- "date": r["date"],
353
- "spoiler": r.get("spoiler", False),
354
- }
355
- for r in items
356
- ]
357
-
358
- total, reviews = get_user_reviews("the-last-of-us")
359
- print(f"{total} user reviews") # 2983
360
- ```
361
-
362
- ### NUXT_DATA extraction (alternative, no API key)
363
-
364
- If you need to avoid the backend API (e.g., the API key rotates), the HTML page embeds all score data in `<script id="__NUXT_DATA__">` as a flat pool with integer cross-references. This is more fragile but requires no API key:
365
-
366
- ```python
367
- import json, re
368
-
369
- url = "https://www.metacritic.com/game/the-last-of-us/"
370
- html = http_get(url)
371
-
372
- pool = json.loads(
373
- re.search(r'<script[^>]*id="__NUXT_DATA__"[^>]*>(.*?)</script>', html, re.DOTALL).group(1)
374
- )
375
-
376
- def deref(pool, idx, depth=0, visited=None):
377
- if visited is None: visited = set()
378
- if not isinstance(idx, int) or idx in visited or depth > 4: return idx
379
- visited.add(idx)
380
- val = pool[idx]
381
- if isinstance(val, dict):
382
- return {k: deref(pool, v, depth+1, visited) if isinstance(v, int) else v for k, v in val.items()}
383
- elif isinstance(val, list) and len(val) == 2 and isinstance(val[0], str) and val[0] in ('Ref','Reactive','ShallowReactive','ShallowRef'):
384
- return deref(pool, val[1], depth+1, visited)
385
- elif isinstance(val, list):
386
- return [deref(pool, v, depth+1, visited) if isinstance(v, int) else v for v in val]
387
- return val
388
-
389
- # Find components
390
- components_idx = next(
391
- pool[i] for i, v in enumerate(pool)
392
- if isinstance(v, list) and len(v) > 3 and all(isinstance(x, int) for x in v[:3])
393
- and isinstance(pool[v[0]], dict) and 'data' in pool[v[0]] and 'meta' in pool[v[0]]
394
- )
395
-
396
- def find_component(pool, name):
397
- for i, val in enumerate(pool):
398
- if not isinstance(val, dict) or 'data' not in val or 'meta' not in val: continue
399
- meta = pool[val['meta']] if isinstance(val.get('meta'), int) else {}
400
- if not isinstance(meta, dict): continue
401
- cname = pool[meta.get('componentName')] if isinstance(meta.get('componentName'), int) else ''
402
- if cname == name: return deref(pool, val['data'])
403
- return None
404
-
405
- critic = find_component(pool, 'critic-score-summary')
406
- user = find_component(pool, 'user-score-summary')
407
- print("Metascore:", critic['item']['score']) # 95
408
- print("Critic reviews:", critic['item']['reviewCount']) # 98
409
- print("User score:", user['item']['score']) # 9.2
410
- print("User reviews:", user['item']['reviewCount']) # 17207
411
- ```
412
-
413
- ---
414
-
415
- ## URL slug patterns
416
-
417
- Metacritic slugs are lowercased, spaces replaced with hyphens, special chars dropped:
418
-
419
- | Title | Slug |
420
- |-------|------|
421
- | `The Last of Us` | `the-last-of-us` |
422
- | `Baldur's Gate 3` | `baldurs-gate-3` |
423
- | `Elden Ring: Shadow of the Erdtree` | `elden-ring-shadow-of-the-erdtree` |
424
- | `Breaking Bad` | `breaking-bad` |
425
- | `The Godfather` | `the-godfather` |
426
-
427
- Derive slug from the page URL: everything between the media-type path and the trailing slash.
428
-
429
- ```python
430
- import re
431
-
432
- def slug_from_url(url):
433
- # Works for /game/, /movie/, /tv/
434
- m = re.search(r'/(?:game|movie|tv)/([^/]+)/', url)
435
- return m.group(1) if m else None
436
-
437
- slug_from_url("https://www.metacritic.com/game/the-last-of-us/") # "the-last-of-us"
438
- ```
439
-
440
- ---
441
-
442
- ## Anti-bot measures
443
-
444
- - **Cloudflare** is in front of both `metacritic.com` and `backend.metacritic.com` (confirmed via `CF-Ray` and `Server: cloudflare` headers).
445
- - **Frontend pages** (`metacritic.com/*`): Require a non-empty User-Agent. `Mozilla/5.0` works. `python-requests/...` or empty UA returns HTTP 403.
446
- - **Backend API** (`backend.metacritic.com`): Same rule — any non-empty User-Agent works, including `curl/7.84.0` and `python-requests/2.31.0`. Only truly empty UA gets 403.
447
- - **Music pages** (`metacritic.com/music/*`): HTTP 403 even with valid User-Agent — Cloudflare blocks that path category. The backend API for music also 404s. Use the browser via CDP for music pages.
448
- - **Cache**: Frontend pages are Cloudflare-cached (10 minute TTL, `Cache-Control: public, max-age=600`). Backend API responses are not cached (`CF-Cache-Status: MISS`).
449
- - **No CAPTCHA** observed during testing with any of the approaches above.
450
- - **No rate limit** hit during testing: 10 sequential calls at 3.6 calls/sec, 10 parallel calls in 0.68s — all succeeded.
451
- - **PerimeterX**: Not detected in response headers or HTML.
452
-
453
- ---
454
-
455
- ## Gotchas
456
-
457
- - **API key is embedded in every Metacritic page HTML** — find it by searching for `apiKey=` in `backend.metacritic.com` URLs. The key `1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u` was confirmed active as of 2026-04-18. If it rotates, fetch any Metacritic page and extract it: `re.search(r'apiKey=([A-Za-z0-9]+)', html).group(1)`.
458
-
459
- - **userScore is None in search results** — the `/finder/metacritic/search/` endpoint returns `userScore: null` for all results. Call the stats API separately with the slug to get user score + review count.
460
-
461
- - **Metascore None means < 4 reviews** — the backend API returns `score: null` (not 0) when a title has fewer than 4 critic reviews. Always check `if score is not None` before using.
462
-
463
- - **Multi-platform games: JSON-LD shows lead platform score** — for a game on PS5 and Xbox, `aggregateRating.ratingValue` in JSON-LD is the lead platform's score (the platform marked `isLeadPlatform: True` in the backend API). All platforms are listed in `gamePlatform` but without individual scores. Use the product API's `platforms` array for per-platform breakdown.
464
-
465
- - **Music is blocked** — `metacritic.com/music/*` returns HTTP 403 even with a real browser User-Agent. The backend API for albums (`/albums/metacritic/...`) also returns 404. Music data requires a real browser session via CDP.
466
-
467
- - **NUXT_DATA pool deref is fragile** — the pool structure is a flat array where every value is either a primitive or an integer index pointing elsewhere in the array. Component locations shift between page loads but the component names (`critic-score-summary`, `user-score-summary`) are stable.
468
-
469
- - **`http_get` default UA is `Mozilla/5.0`** — this works for Metacritic. No need to override it.
470
-
471
- - **Backend API `componentName` and `componentType` params are required** — omitting them returns HTTP 400. Use the exact values shown in the code examples above.
472
-
473
- - **Finder `userScore` format**: In finder/browse results, `userScore` is `{"score": 9.1}` (a dict with just `score`). In the stats API, it's a full object with `reviewCount`, `sentiment`, etc. In search results, it's `null`.
474
-
475
- - **Media type URL paths**: games=`/games/`, movies=`/movies/`, TV shows=`/shows/`. There is no `/tv/` path in the backend API (the frontend uses `/tv/` but the API uses `/shows/`).
476
-
477
- - **Finder API does not support free-text search** — the `q=` param is silently ignored and returns 0 results. Use the `/finder/metacritic/search/{query}/web` endpoint for title search.
1
+ # Metacritic — Scraping & Data Extraction
2
+
3
+ Field-tested against metacritic.com on 2026-04-18. All code blocks validated with live requests.
4
+
5
+ ## Do this first
6
+
7
+ **Use the backend API — it returns clean JSON with both scores in one call, no HTML parsing.**
8
+
9
+ Metacritic's internal backend API is publicly accessible with a stable key embedded in every page. It covers games, movies, and TV shows.
10
+
11
+ ```python
12
+ import json
13
+
14
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
15
+
16
+ def get_game_scores(slug):
17
+ """slug = URL slug e.g. 'elden-ring', 'the-last-of-us'"""
18
+ base = f"https://backend.metacritic.com"
19
+ product = json.loads(http_get(
20
+ f"{base}/games/metacritic/{slug}/web"
21
+ f"?componentName=product&componentType=Product&apiKey={API_KEY}"
22
+ ))
23
+ user_stats = json.loads(http_get(
24
+ f"{base}/reviews/metacritic/user/games/{slug}/stats/web"
25
+ f"?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"
26
+ ))
27
+ item = product["data"]["item"]
28
+ crit = item["criticScoreSummary"]
29
+ user = user_stats["data"]["item"]
30
+ return {
31
+ "title": item["title"],
32
+ "platform": item["platform"], # lead platform
33
+ "platforms": item["platforms"], # list with per-platform scores
34
+ "metascore": crit["score"], # int 0–100 or None
35
+ "critic_reviews": crit["reviewCount"], # int
36
+ "critic_sentiment": crit["sentiment"], # e.g. "Universal acclaim"
37
+ "user_score": user["score"], # float 0.0–10.0 or None
38
+ "user_reviews": user["reviewCount"], # int
39
+ "user_sentiment": user["sentiment"],
40
+ "release_date": item["releaseDate"], # "YYYY-MM-DD"
41
+ }
42
+
43
+ print(get_game_scores("the-last-of-us"))
44
+ # {'title': 'The Last of Us', 'platform': 'PlayStation 3',
45
+ # 'metascore': 95, 'critic_reviews': 98,
46
+ # 'user_score': 9.2, 'user_reviews': 17207, ...}
47
+ ```
48
+
49
+ Use the browser **only** if you need music pages — `metacritic.com/music/*` returns HTTP 403 to `http_get` (Cloudflare blocks those routes). Games, movies, and TV all work with plain HTTP.
50
+
51
+ ---
52
+
53
+ ## Fastest approach: JSON-LD (critic score + review count only)
54
+
55
+ If you only need the Metascore and critic review count and don't need the user score, JSON-LD is the single-call option — no API key, no separate request:
56
+
57
+ ```python
58
+ import json, re
59
+
60
+ url = "https://www.metacritic.com/game/elden-ring/" # or /movie/ or /tv/
61
+ html = http_get(url)
62
+
63
+ block = re.findall(
64
+ r'<script[^>]*type="application/ld\+json"[^>]*>(.*?)</script>',
65
+ html, re.DOTALL
66
+ )[0]
67
+ ld = json.loads(block)
68
+
69
+ agg = ld["aggregateRating"]
70
+ print(ld["name"]) # "Elden Ring"
71
+ print(agg["ratingValue"]) # 96 (metascore)
72
+ print(agg["reviewCount"]) # 93 (critic reviews count)
73
+ print(ld.get("gamePlatform")) # ['Xbox One', 'PC', 'PlayStation 4', 'Xbox Series X', 'PlayStation 5']
74
+ print(ld.get("genre")) # "Action RPG"
75
+ print(ld.get("contentRating")) # "M"
76
+ print(ld.get("datePublished")) # "2022-02-25"
77
+ ```
78
+
79
+ **JSON-LD limitations:**
80
+ - Only contains Metascore and critic review count — **no user score, no user review count**.
81
+ - For multi-platform games, `ratingValue` is the lead platform score; all platforms are listed in `gamePlatform` but without individual scores.
82
+ - `@type` is `VideoGame` for games, `Movie` for movies, `TVSeries` for TV shows.
83
+
84
+ ---
85
+
86
+ ## Common workflows
87
+
88
+ ### Get scores for a single title (backend API)
89
+
90
+ ```python
91
+ import json
92
+
93
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
94
+ BASE = "https://backend.metacritic.com"
95
+
96
+ # Games
97
+ def game_scores(slug):
98
+ p = json.loads(http_get(f"{BASE}/games/metacritic/{slug}/web?componentName=product&componentType=Product&apiKey={API_KEY}"))
99
+ u = json.loads(http_get(f"{BASE}/reviews/metacritic/user/games/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"))
100
+ c = p["data"]["item"]["criticScoreSummary"]
101
+ us = u["data"]["item"]
102
+ return {"metascore": c["score"], "critic_reviews": c["reviewCount"],
103
+ "user_score": us["score"], "user_reviews": us["reviewCount"]}
104
+
105
+ # Movies
106
+ def movie_scores(slug):
107
+ p = json.loads(http_get(f"{BASE}/movies/metacritic/{slug}/web?componentName=product&componentType=Product&apiKey={API_KEY}"))
108
+ u = json.loads(http_get(f"{BASE}/reviews/metacritic/user/movies/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"))
109
+ c = p["data"]["item"]["criticScoreSummary"]
110
+ us = u["data"]["item"]
111
+ return {"metascore": c["score"], "critic_reviews": c["reviewCount"],
112
+ "user_score": us["score"], "user_reviews": us["reviewCount"]}
113
+
114
+ # TV shows
115
+ def show_scores(slug):
116
+ p = json.loads(http_get(f"{BASE}/shows/metacritic/{slug}/web?componentName=product&componentType=Product&apiKey={API_KEY}"))
117
+ u = json.loads(http_get(f"{BASE}/reviews/metacritic/user/shows/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&apiKey={API_KEY}"))
118
+ c = p["data"]["item"]["criticScoreSummary"]
119
+ us = u["data"]["item"]
120
+ return {"metascore": c["score"], "critic_reviews": c["reviewCount"],
121
+ "user_score": us["score"], "user_reviews": us["reviewCount"]}
122
+
123
+ # Verified results:
124
+ print(game_scores("the-last-of-us"))
125
+ # {'metascore': 95, 'critic_reviews': 98, 'user_score': 9.2, 'user_reviews': 17207}
126
+ print(movie_scores("the-godfather"))
127
+ # {'metascore': 100, 'critic_reviews': 16, 'user_score': 9.2, 'user_reviews': 4450}
128
+ print(show_scores("breaking-bad"))
129
+ # {'metascore': 87, 'critic_reviews': 98, 'user_score': 9.4, 'user_reviews': 19070}
130
+ ```
131
+
132
+ ### Parallel fetching (multiple titles at once)
133
+
134
+ 10 API calls in 0.68s with 5 workers — no rate-limit errors:
135
+
136
+ ```python
137
+ import json
138
+ from concurrent.futures import ThreadPoolExecutor
139
+ import urllib.request, gzip
140
+
141
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
142
+
143
+ def _fetch(url):
144
+ h = {"User-Agent": "Mozilla/5.0", "Accept-Encoding": "gzip"}
145
+ with urllib.request.urlopen(urllib.request.Request(url, headers=h), timeout=15) as r:
146
+ data = r.read()
147
+ if r.headers.get("Content-Encoding") == "gzip": data = gzip.decompress(data)
148
+ return json.loads(data.decode())
149
+
150
+ def batch_game_scores(slugs, workers=5):
151
+ """Fetch critic+user scores for multiple game slugs in parallel."""
152
+ BASE = "https://backend.metacritic.com"
153
+ AK = f"apiKey={API_KEY}"
154
+
155
+ def fetch_one(slug):
156
+ c = _fetch(f"{BASE}/reviews/metacritic/critic/games/{slug}/stats/web?componentName=critic-score-summary&componentType=ScoreSummary&{AK}")
157
+ u = _fetch(f"{BASE}/reviews/metacritic/user/games/{slug}/stats/web?componentName=user-score-summary&componentType=ScoreSummary&{AK}")
158
+ ci = c["data"]["item"]
159
+ ui = u["data"]["item"]
160
+ return {"slug": slug, "metascore": ci["score"], "critic_reviews": ci["reviewCount"],
161
+ "user_score": ui["score"], "user_reviews": ui["reviewCount"]}
162
+
163
+ with ThreadPoolExecutor(max_workers=workers) as ex:
164
+ return list(ex.map(fetch_one, slugs))
165
+
166
+ results = batch_game_scores([
167
+ "the-last-of-us", "elden-ring", "god-of-war",
168
+ "red-dead-redemption-2", "the-witcher-3-wild-hunt"
169
+ ])
170
+ # the-last-of-us: meta=95/98critics, user=9.2/17207
171
+ # elden-ring: meta=96/86critics, user=8.4/23344
172
+ # god-of-war: meta=94/118critics, user=9.0/30439
173
+ # red-dead-redemption-2: meta=97/99critics, user=9.0/35306
174
+ # the-witcher-3-wild-hunt: meta=92/79critics, user=9.1/19370
175
+ ```
176
+
177
+ ### Search by title
178
+
179
+ ```python
180
+ import json, urllib.parse
181
+
182
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
183
+
184
+ def search(query, media_type=None, limit=10):
185
+ """
186
+ media_type: None='all', 'games' (mcoTypeId=13), 'movies' (2), 'shows' (1)
187
+ Returns list of {title, type, slug, premiereYear, metascore, user_score}
188
+ """
189
+ type_map = {"games": 13, "movies": 2, "shows": 1}
190
+ q = urllib.parse.quote(query)
191
+ type_param = f"&mcoTypeId={type_map[media_type]}" if media_type else "&mcoTypeId=1%2C2%2C3%2C13"
192
+ url = (
193
+ f"https://backend.metacritic.com/finder/metacritic/search/{q}/web"
194
+ f"?offset=0&limit={limit}&sortBy=META_SCORE&sortDirection=DESC"
195
+ f"{type_param}&componentName=search&componentType=SearchResult"
196
+ f"&apiKey={API_KEY}"
197
+ )
198
+ data = json.loads(http_get(url))
199
+ items = data["data"]["items"]
200
+ return [
201
+ {
202
+ "title": i["title"],
203
+ "type": i["type"], # "game-title", "movie", "tv-show"
204
+ "slug": i["slug"],
205
+ "year": i.get("premiereYear"),
206
+ "metascore": i.get("criticScoreSummary", {}).get("score"),
207
+ "user_score": i.get("userScore"), # None in search results (use stats API for this)
208
+ }
209
+ for i in items
210
+ ]
211
+
212
+ results = search("elden ring", media_type="games")
213
+ # [{'title': 'Elden Ring', 'type': 'game-title', 'slug': 'elden-ring', 'year': 2022, 'metascore': 96, ...}]
214
+ ```
215
+
216
+ **Note:** `userScore` is `None` in search results. Call the stats API with the `slug` to get it.
217
+
218
+ ### Browse/list titles by score
219
+
220
+ ```python
221
+ import json
222
+
223
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
224
+
225
+ def browse_games(sort_by="-metaScore", year_min=None, year_max=None, offset=0, limit=24):
226
+ """
227
+ sort_by: '-metaScore' | '-releaseDate' | '-popularityCount'
228
+ Returns up to `limit` games with criticScoreSummary and userScore.
229
+ Total available: ~14,160 games.
230
+ """
231
+ params = f"sortBy={sort_by}&mcoTypeId=13&offset={offset}&limit={limit}"
232
+ if year_min: params += f"&releaseYearMin={year_min}"
233
+ if year_max: params += f"&releaseYearMax={year_max}"
234
+ url = f"https://backend.metacritic.com/finder/metacritic/web?{params}&componentName=finder&componentType=Finder&apiKey={API_KEY}"
235
+ data = json.loads(http_get(url))
236
+ total = data["data"]["totalResults"]
237
+ items = data["data"]["items"]
238
+ return total, [
239
+ {
240
+ "title": i["title"],
241
+ "slug": i["slug"],
242
+ "year": i.get("premiereYear"),
243
+ "metascore": i.get("criticScoreSummary", {}).get("score"),
244
+ "critic_reviews": i.get("criticScoreSummary", {}).get("reviewCount"),
245
+ "user_score": i.get("userScore", {}).get("score") if isinstance(i.get("userScore"), dict) else i.get("userScore"),
246
+ }
247
+ for i in items
248
+ ]
249
+
250
+ total, games = browse_games(year_min=2023, year_max=2024)
251
+ print(f"{total} games 2023-2024") # 953
252
+ for g in games[:3]:
253
+ print(g)
254
+ # {'title': "Baldur's Gate 3", 'year': 2023, 'metascore': 96, 'user_score': 9.2}
255
+ # {'title': 'The Legend of Zelda: Tears of the Kingdom', 'year': 2023, 'metascore': 96, ...}
256
+ ```
257
+
258
+ Finder API totals (confirmed 2026-04-18):
259
+ - Games (mcoTypeId=13): 14,160
260
+ - Movies (mcoTypeId=2): 17,152
261
+ - TV Shows (mcoTypeId=1): 3,392
262
+
263
+ ### Get per-platform scores for multi-platform games
264
+
265
+ ```python
266
+ import json
267
+
268
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
269
+
270
+ def game_platforms(slug):
271
+ url = (
272
+ f"https://backend.metacritic.com/games/metacritic/{slug}/web"
273
+ f"?componentName=product&componentType=Product&apiKey={API_KEY}"
274
+ )
275
+ data = json.loads(http_get(url))
276
+ platforms = data["data"]["item"]["platforms"]
277
+ return [
278
+ {
279
+ "name": p["name"],
280
+ "slug": p["slug"],
281
+ "is_lead": p["isLeadPlatform"],
282
+ "metascore": p["criticScoreSummary"]["score"], # None if <4 reviews
283
+ "critic_reviews": p["criticScoreSummary"]["reviewCount"],
284
+ "release_date": p["releaseDate"],
285
+ }
286
+ for p in platforms
287
+ ]
288
+
289
+ print(game_platforms("elden-ring"))
290
+ # [{'name': 'Xbox One', 'slug': 'xbox-one', 'is_lead': False, 'metascore': None, ...},
291
+ # {'name': 'PC', 'slug': 'pc', 'is_lead': False, 'metascore': 94, 'critic_reviews': 63},
292
+ # {'name': 'PlayStation 4', 'slug': 'playstation-4', 'is_lead': False, 'metascore': None, 'critic_reviews': 1},
293
+ # {'name': 'Xbox Series X', 'slug': 'xbox-series-x', 'is_lead': False, 'metascore': 96, 'critic_reviews': 19},
294
+ # {'name': 'PlayStation 5', 'slug': 'playstation-5', 'is_lead': True, 'metascore': 96, 'critic_reviews': 93}]
295
+ ```
296
+
297
+ ### Get critic reviews (paginated)
298
+
299
+ ```python
300
+ import json
301
+
302
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
303
+
304
+ def get_critic_reviews(slug, media="games", offset=0, limit=10, sort="date"):
305
+ """sort: 'date' | 'score' | 'publication'"""
306
+ url = (
307
+ f"https://backend.metacritic.com/reviews/metacritic/critic/{media}/{slug}/web"
308
+ f"?offset={offset}&limit={limit}&sort={sort}"
309
+ f"&componentName=latest-critic-reviews&componentType=CriticReviewList&apiKey={API_KEY}"
310
+ )
311
+ data = json.loads(http_get(url))
312
+ total = data["data"]["totalResults"] # e.g. 98
313
+ items = data["data"]["items"]
314
+ return total, [
315
+ {
316
+ "score": r["score"], # int 0–100
317
+ "publication": r["publicationName"],
318
+ "quote": r["quote"],
319
+ "date": r["date"],
320
+ "url": r.get("url"),
321
+ }
322
+ for r in items
323
+ ]
324
+
325
+ total, reviews = get_critic_reviews("the-last-of-us", sort="score")
326
+ print(f"{total} critic reviews") # 98
327
+ print(reviews[0])
328
+ # {'score': 97, 'publication': 'GamingXP', 'quote': 'Flawless in its ambition...', 'date': '...'}
329
+ ```
330
+
331
+ ### Get user reviews (paginated)
332
+
333
+ ```python
334
+ import json
335
+
336
+ API_KEY = "1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u"
337
+
338
+ def get_user_reviews(slug, media="games", offset=0, limit=10, order_by="score", order_type="desc"):
339
+ """order_by: 'score' | 'date' | 'helpfulness'"""
340
+ url = (
341
+ f"https://backend.metacritic.com/reviews/metacritic/user/{media}/{slug}/web"
342
+ f"?offset={offset}&limit={limit}&orderBy={order_by}&orderType={order_type}"
343
+ f"&componentName=top-user-reviews&componentType=UserReviewList&apiKey={API_KEY}"
344
+ )
345
+ data = json.loads(http_get(url))
346
+ total = data["data"]["totalResults"] # e.g. 2983 for The Last of Us
347
+ items = data["data"]["items"]
348
+ return total, [
349
+ {
350
+ "score": r["score"], # int 0–10
351
+ "quote": r["quote"],
352
+ "date": r["date"],
353
+ "spoiler": r.get("spoiler", False),
354
+ }
355
+ for r in items
356
+ ]
357
+
358
+ total, reviews = get_user_reviews("the-last-of-us")
359
+ print(f"{total} user reviews") # 2983
360
+ ```
361
+
362
+ ### NUXT_DATA extraction (alternative, no API key)
363
+
364
+ If you need to avoid the backend API (e.g., the API key rotates), the HTML page embeds all score data in `<script id="__NUXT_DATA__">` as a flat pool with integer cross-references. This is more fragile but requires no API key:
365
+
366
+ ```python
367
+ import json, re
368
+
369
+ url = "https://www.metacritic.com/game/the-last-of-us/"
370
+ html = http_get(url)
371
+
372
+ pool = json.loads(
373
+ re.search(r'<script[^>]*id="__NUXT_DATA__"[^>]*>(.*?)</script>', html, re.DOTALL).group(1)
374
+ )
375
+
376
+ def deref(pool, idx, depth=0, visited=None):
377
+ if visited is None: visited = set()
378
+ if not isinstance(idx, int) or idx in visited or depth > 4: return idx
379
+ visited.add(idx)
380
+ val = pool[idx]
381
+ if isinstance(val, dict):
382
+ return {k: deref(pool, v, depth+1, visited) if isinstance(v, int) else v for k, v in val.items()}
383
+ elif isinstance(val, list) and len(val) == 2 and isinstance(val[0], str) and val[0] in ('Ref','Reactive','ShallowReactive','ShallowRef'):
384
+ return deref(pool, val[1], depth+1, visited)
385
+ elif isinstance(val, list):
386
+ return [deref(pool, v, depth+1, visited) if isinstance(v, int) else v for v in val]
387
+ return val
388
+
389
+ # Find components
390
+ components_idx = next(
391
+ pool[i] for i, v in enumerate(pool)
392
+ if isinstance(v, list) and len(v) > 3 and all(isinstance(x, int) for x in v[:3])
393
+ and isinstance(pool[v[0]], dict) and 'data' in pool[v[0]] and 'meta' in pool[v[0]]
394
+ )
395
+
396
+ def find_component(pool, name):
397
+ for i, val in enumerate(pool):
398
+ if not isinstance(val, dict) or 'data' not in val or 'meta' not in val: continue
399
+ meta = pool[val['meta']] if isinstance(val.get('meta'), int) else {}
400
+ if not isinstance(meta, dict): continue
401
+ cname = pool[meta.get('componentName')] if isinstance(meta.get('componentName'), int) else ''
402
+ if cname == name: return deref(pool, val['data'])
403
+ return None
404
+
405
+ critic = find_component(pool, 'critic-score-summary')
406
+ user = find_component(pool, 'user-score-summary')
407
+ print("Metascore:", critic['item']['score']) # 95
408
+ print("Critic reviews:", critic['item']['reviewCount']) # 98
409
+ print("User score:", user['item']['score']) # 9.2
410
+ print("User reviews:", user['item']['reviewCount']) # 17207
411
+ ```
412
+
413
+ ---
414
+
415
+ ## URL slug patterns
416
+
417
+ Metacritic slugs are lowercased, spaces replaced with hyphens, special chars dropped:
418
+
419
+ | Title | Slug |
420
+ |-------|------|
421
+ | `The Last of Us` | `the-last-of-us` |
422
+ | `Baldur's Gate 3` | `baldurs-gate-3` |
423
+ | `Elden Ring: Shadow of the Erdtree` | `elden-ring-shadow-of-the-erdtree` |
424
+ | `Breaking Bad` | `breaking-bad` |
425
+ | `The Godfather` | `the-godfather` |
426
+
427
+ Derive slug from the page URL: everything between the media-type path and the trailing slash.
428
+
429
+ ```python
430
+ import re
431
+
432
+ def slug_from_url(url):
433
+ # Works for /game/, /movie/, /tv/
434
+ m = re.search(r'/(?:game|movie|tv)/([^/]+)/', url)
435
+ return m.group(1) if m else None
436
+
437
+ slug_from_url("https://www.metacritic.com/game/the-last-of-us/") # "the-last-of-us"
438
+ ```
439
+
440
+ ---
441
+
442
+ ## Anti-bot measures
443
+
444
+ - **Cloudflare** is in front of both `metacritic.com` and `backend.metacritic.com` (confirmed via `CF-Ray` and `Server: cloudflare` headers).
445
+ - **Frontend pages** (`metacritic.com/*`): Require a non-empty User-Agent. `Mozilla/5.0` works. `python-requests/...` or empty UA returns HTTP 403.
446
+ - **Backend API** (`backend.metacritic.com`): Same rule — any non-empty User-Agent works, including `curl/7.84.0` and `python-requests/2.31.0`. Only truly empty UA gets 403.
447
+ - **Music pages** (`metacritic.com/music/*`): HTTP 403 even with valid User-Agent — Cloudflare blocks that path category. The backend API for music also 404s. Use the browser via CDP for music pages.
448
+ - **Cache**: Frontend pages are Cloudflare-cached (10 minute TTL, `Cache-Control: public, max-age=600`). Backend API responses are not cached (`CF-Cache-Status: MISS`).
449
+ - **No CAPTCHA** observed during testing with any of the approaches above.
450
+ - **No rate limit** hit during testing: 10 sequential calls at 3.6 calls/sec, 10 parallel calls in 0.68s — all succeeded.
451
+ - **PerimeterX**: Not detected in response headers or HTML.
452
+
453
+ ---
454
+
455
+ ## Gotchas
456
+
457
+ - **API key is embedded in every Metacritic page HTML** — find it by searching for `apiKey=` in `backend.metacritic.com` URLs. The key `1MOZgmNFxvmljaQR1X9KAij9Mo4xAY3u` was confirmed active as of 2026-04-18. If it rotates, fetch any Metacritic page and extract it: `re.search(r'apiKey=([A-Za-z0-9]+)', html).group(1)`.
458
+
459
+ - **userScore is None in search results** — the `/finder/metacritic/search/` endpoint returns `userScore: null` for all results. Call the stats API separately with the slug to get user score + review count.
460
+
461
+ - **Metascore None means < 4 reviews** — the backend API returns `score: null` (not 0) when a title has fewer than 4 critic reviews. Always check `if score is not None` before using.
462
+
463
+ - **Multi-platform games: JSON-LD shows lead platform score** — for a game on PS5 and Xbox, `aggregateRating.ratingValue` in JSON-LD is the lead platform's score (the platform marked `isLeadPlatform: True` in the backend API). All platforms are listed in `gamePlatform` but without individual scores. Use the product API's `platforms` array for per-platform breakdown.
464
+
465
+ - **Music is blocked** — `metacritic.com/music/*` returns HTTP 403 even with a real browser User-Agent. The backend API for albums (`/albums/metacritic/...`) also returns 404. Music data requires a real browser session via CDP.
466
+
467
+ - **NUXT_DATA pool deref is fragile** — the pool structure is a flat array where every value is either a primitive or an integer index pointing elsewhere in the array. Component locations shift between page loads but the component names (`critic-score-summary`, `user-score-summary`) are stable.
468
+
469
+ - **`http_get` default UA is `Mozilla/5.0`** — this works for Metacritic. No need to override it.
470
+
471
+ - **Backend API `componentName` and `componentType` params are required** — omitting them returns HTTP 400. Use the exact values shown in the code examples above.
472
+
473
+ - **Finder `userScore` format**: In finder/browse results, `userScore` is `{"score": 9.1}` (a dict with just `score`). In the stats API, it's a full object with `reviewCount`, `sentiment`, etc. In search results, it's `null`.
474
+
475
+ - **Media type URL paths**: games=`/games/`, movies=`/movies/`, TV shows=`/shows/`. There is no `/tv/` path in the backend API (the frontend uses `/tv/` but the API uses `/shows/`).
476
+
477
+ - **Finder API does not support free-text search** — the `q=` param is silently ignored and returns 0 results. Use the `/finder/metacritic/search/{query}/web` endpoint for title search.