Repository navigation
fix(youtube): date a video by its upload date - #869
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe JSON-LD helper now ignores comment properties during fuzzy traversal. YouTube tests add a comment-bearing fixture and verify that metadata uses the video upload date. ChangesYouTube date extraction coverage
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/metascraper-date/src/index.js`:
- Around line 25-29: Reorder the date extraction rules so the HTML
itemprop="uploaddate" content and title checks run before the dateCreated
fallback, while keeping the JSON-LD uploadDate rule adjacent to them. Add a
regression test covering nested JSON-LD Comment.dateCreated alongside an HTML
itemprop="uploadDate", asserting the HTML upload date is selected.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8dfec389-7cce-4856-ac20-696b9c5b486e
⛔ Files ignored due to path filters (1)
packages/metascraper-youtube/test/snapshots/index.js.snapis excluded by!**/*.snap
📒 Files selected for processing (6)
packages/metascraper-date/package.jsonpackages/metascraper-date/src/index.jspackages/metascraper-date/test/helpers.jspackages/metascraper-date/test/index.jspackages/metascraper-youtube/test/index.jspackages/metascraper-youtube/test/snapshots/index.js.md
|
Pushed a second commit covering The package declared no {
'@type': 'VideoObject',
uploadDate: '2016-04-06T09:59:35-07:00',
comment: [{ '@type': 'Comment', dateModified: '2024-01-01T00:00:00.000Z' }]
}
// metascraper-date alone => 2024-01-01T00:00:00.000Z
Two tests added, and both were verified to fail when the rule is removed:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/metascraper-youtube/test/fixtures/youtube-video-comments.html`:
- Around line 18-25: Sanitize the comment fixture’s user-generated data by
removing or replacing the YouTube handle, display name, profile URL, full
comment text, and upvoteCount while preserving the comment object and timestamp
fields required by the date regression. Confirm the replacement content complies
with the repository privacy policy.
In `@packages/metascraper-youtube/test/index.js`:
- Around line 24-32: Add a separate YouTube fixture containing only an
itemprop="uploadDate" value, with no JSON-LD or competing metadata, and add a
dedicated test alongside the existing test that loads it and asserts the
expected date. Keep the current JSON-LD/comments scenario unchanged so the
itemprop selector is verified independently.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 99c2e441-07d2-4568-9b41-9928394ac313
📒 Files selected for processing (3)
packages/metascraper-youtube/src/index.jspackages/metascraper-youtube/test/fixtures/youtube-video-comments.htmlpackages/metascraper-youtube/test/index.js
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/metascraper-helpers/test/index.js (1)
453-483: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winCover the downstream
author.namequery.
packages/metascraper-author/src/index.jscalls$jsonld('author.name'), but this test only checks$jsonld('author'). Add assertions for the property path used by the author scraper.Suggested test additions
t.is($jsonld('author')($), undefined) + t.is($jsonld('author.name')($), undefined) t.deepEqual($jsonld('author')($), { name: 'the writer' }) + t.is($jsonld('author.name')($), 'the writer')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/metascraper-helpers/test/index.js` around lines 453 - 483, Add assertions in the existing `$jsonld does not answer with what an audience said` test for `$jsonld('author.name')`, covering the reviewer/comment author cases and the article’s writer author path used by `packages/metascraper-author/src/index.js`. Preserve the current `$jsonld('author')` assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/metascraper-helpers/test/index.js`:
- Around line 453-483: Add assertions in the existing `$jsonld does not answer
with what an audience said` test for `$jsonld('author.name')`, covering the
reviewer/comment author cases and the article’s writer author path used by
`packages/metascraper-author/src/index.js`. Preserve the current
`$jsonld('author')` assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9f5b95fe-66b3-47ef-add3-fc7c539d2b58
📒 Files selected for processing (7)
packages/metascraper-date/src/index.jspackages/metascraper-date/test/index.jspackages/metascraper-helpers/src/index.jspackages/metascraper-helpers/test/index.jspackages/metascraper-youtube/test/fixtures/youtube-video-comments.htmlpackages/metascraper-youtube/test/fixtures/youtube-video-itemprop-only.htmlpackages/metascraper-youtube/test/index.js
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/metascraper-youtube/test/fixtures/youtube-video-comments.html
- packages/metascraper-date/src/index.js
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e5c5335. Configure here.
057fd4f to
74b0bae
Compare
metascraper-youtube owned title, author, publisher and image but left
date to the generic rules, where `$jsonld('dateCreated')` searches the
JSON-LD tree recursively, walks into `comment[]` and answers with a
viewer's timestamp:
https://www.youtube.com/watch?v=arj7oStGLkU
2020-05-11T19:29:04.000Z <- a comment
2016-04-06T16:59:35.000Z <- the upload
Declare `date` here like the other fields, read from the `uploadDate`
the watch page carries. Vendor rules run before the generic ones, so
YouTube no longer depends on how the shared date rules are ordered.
The fixture is the watch page's own JSON-LD, comment included, with the
commenter's details replaced. Removing the rule fails it with the exact
production value. The snapshot test alongside it destructured `date`
out and asserted only that it was a string, so it could not have caught
this; pin it.
The recursive search reaching into comments is a wider bug that also
affects `review` nodes. It belongs in its own change, against
@metascraper/helpers.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01DiDJXMPg2e98kgL3drjg6f
74b0bae to
8013fd9
Compare
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [metascraper](https://metascraper.js.org) ([source](https://github.com/microlinkhq/metascraper)) | [`5.51.1` → `5.58.4`](https://renovatebot.com/diffs/npm/metascraper/5.51.1/5.58.4) |  |  | --- ### Release Notes <details> <summary>microlinkhq/metascraper (metascraper)</summary> ### [`v5.58.4`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5584-2026-10-09) [Compare Source](microlinkhq/metascraper@v5.58.1...v5.58.4) **Note:** Version bump only for package metascraper ### [`v5.58.1`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5581-2026-09-17) [Compare Source](microlinkhq/metascraper@v5.56.2...v5.58.1) ##### Bug Fixes - **metascraper-instagram:** prefer 180px apple-touch logo ([#​882](microlinkhq/metascraper#882)) ([a586af5](microlinkhq/metascraper@a586af5)) - use [@​kikobeats/got](https://github.com/kikobeats/got) to support Node.js 24.20 ([#​881](microlinkhq/metascraper#881)) ([41a626b](microlinkhq/metascraper@41a626b)), closes [nodejs/node#64847](nodejs/node#64847) ### [`v5.56.2`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5570-2026-08-19) [Compare Source](microlinkhq/metascraper@v5.56.1...v5.56.2) ##### Features - add metascraper-imdb ([#​876](microlinkhq/metascraper#876)) ([b10eabb](microlinkhq/metascraper@b10eabb)) #### [5.56.2](microlinkhq/metascraper@v5.56.1...v5.56.2) (2026-08-17) **Note:** Version bump only for package metascraper #### [5.56.1](microlinkhq/metascraper@v5.56.0...v5.56.1) (2026-08-17) ##### Bug Fixes - **author:** fall back to twitter:creator ([#​874](microlinkhq/metascraper#874)) ([d1ec557](microlinkhq/metascraper@d1ec557)), closes [#author-group](https://github.com/microlinkhq/metascraper/issues/author-group) [#author-group](https://github.com/microlinkhq/metascraper/issues/author-group) ### [`v5.56.1`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5570-2026-08-19) [Compare Source](microlinkhq/metascraper@v5.55.2...v5.56.1) ##### Features - add metascraper-imdb ([#​876](microlinkhq/metascraper#876)) ([b10eabb](microlinkhq/metascraper@b10eabb)) #### [5.56.2](microlinkhq/metascraper@v5.56.1...v5.56.2) (2026-08-17) **Note:** Version bump only for package metascraper #### [5.56.1](microlinkhq/metascraper@v5.56.0...v5.56.1) (2026-08-17) ##### Bug Fixes - **author:** fall back to twitter:creator ([#​874](microlinkhq/metascraper#874)) ([d1ec557](microlinkhq/metascraper@d1ec557)), closes [#author-group](https://github.com/microlinkhq/metascraper/issues/author-group) [#author-group](https://github.com/microlinkhq/metascraper/issues/author-group) ### [`v5.55.2`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5560-2026-08-15) [Compare Source](microlinkhq/metascraper@v5.55.1...v5.55.2) ##### Features - add metascraper-citation ([#​873](microlinkhq/metascraper#873)) ([31bceb1](microlinkhq/metascraper@31bceb1)) #### [5.55.2](microlinkhq/metascraper@v5.55.1...v5.55.2) (2026-08-13) ##### Bug Fixes - **helpers:** keep CGI + in query strings ([#​872](microlinkhq/metascraper#872)) ([4743562](microlinkhq/metascraper@4743562)) #### [5.55.1](microlinkhq/metascraper@v5.55.0...v5.55.1) (2026-08-10) ##### Bug Fixes - **youtube:** date a video by its upload date ([#​869](microlinkhq/metascraper#869)) ([7040d5c](microlinkhq/metascraper@7040d5c)) ### [`v5.55.1`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5560-2026-08-15) [Compare Source](microlinkhq/metascraper@v5.55.0...v5.55.1) ##### Features - add metascraper-citation ([#​873](microlinkhq/metascraper#873)) ([31bceb1](microlinkhq/metascraper@31bceb1)) #### [5.55.2](microlinkhq/metascraper@v5.55.1...v5.55.2) (2026-08-13) ##### Bug Fixes - **helpers:** keep CGI + in query strings ([#​872](microlinkhq/metascraper#872)) ([4743562](microlinkhq/metascraper@4743562)) #### [5.55.1](microlinkhq/metascraper@v5.55.0...v5.55.1) (2026-08-10) ##### Bug Fixes - **youtube:** date a video by its upload date ([#​869](microlinkhq/metascraper#869)) ([7040d5c](microlinkhq/metascraper@7040d5c)) ### [`v5.55.0`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5560-2026-08-15) [Compare Source](microlinkhq/metascraper@v5.54.1...v5.55.0) ##### Features - add metascraper-citation ([#​873](microlinkhq/metascraper#873)) ([31bceb1](microlinkhq/metascraper@31bceb1)) #### [5.55.2](microlinkhq/metascraper@v5.55.1...v5.55.2) (2026-08-13) ##### Bug Fixes - **helpers:** keep CGI + in query strings ([#​872](microlinkhq/metascraper#872)) ([4743562](microlinkhq/metascraper@4743562)) #### [5.55.1](microlinkhq/metascraper@v5.55.0...v5.55.1) (2026-08-10) ##### Bug Fixes - **youtube:** date a video by its upload date ([#​869](microlinkhq/metascraper#869)) ([7040d5c](microlinkhq/metascraper@7040d5c)) ### [`v5.54.1`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5550-2026-08-09) [Compare Source](microlinkhq/metascraper@v5.54.0...v5.54.1) ##### Features - **helpers:** pass propName to validate ([#​868](microlinkhq/metascraper#868)) ([8e0a75f](microlinkhq/metascraper@8e0a75f)) #### [5.54.1](microlinkhq/metascraper@v5.54.0...v5.54.1) (2026-08-07) **Note:** Version bump only for package metascraper ### [`v5.54.0`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5550-2026-08-09) [Compare Source](microlinkhq/metascraper@v5.53.0...v5.54.0) ##### Features - **helpers:** pass propName to validate ([#​868](microlinkhq/metascraper#868)) ([8e0a75f](microlinkhq/metascraper@8e0a75f)) #### [5.54.1](microlinkhq/metascraper@v5.54.0...v5.54.1) (2026-08-07) **Note:** Version bump only for package metascraper ### [`v5.53.0`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5540-2026-08-07) [Compare Source](microlinkhq/metascraper@v5.52.1...v5.53.0) ##### Features - **helpers:** add rule-level validate (like test) ([#​866](microlinkhq/metascraper#866)) ([d40856b](microlinkhq/metascraper@d40856b)) #### [5.53.1](microlinkhq/metascraper@v5.53.0...v5.53.1) (2026-08-02) ##### Bug Fixes - keep the favicon body under reachable-url v2 ([#​865](microlinkhq/metascraper#865)) ([ce4536f](microlinkhq/metascraper@ce4536f)) ### [`v5.52.1`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5530-2026-07-30) [Compare Source](microlinkhq/metascraper@v5.52.0...v5.52.1) ##### Features - **helpers:** read the declared protocol instead of resolving it ([#​864](microlinkhq/metascraper#864)) ([2d72298](microlinkhq/metascraper@2d72298)) #### [5.52.1](microlinkhq/metascraper@v5.52.0...v5.52.1) (2026-07-29) **Note:** Version bump only for package metascraper ### [`v5.52.0`](https://github.com/microlinkhq/metascraper/blob/HEAD/CHANGELOG.md#5530-2026-07-30) [Compare Source](microlinkhq/metascraper@v5.51.1...v5.52.0) ##### Features - **helpers:** read the declared protocol instead of resolving it ([#​864](microlinkhq/metascraper#864)) ([2d72298](microlinkhq/metascraper@2d72298)) #### [5.52.1](microlinkhq/metascraper@v5.52.0...v5.52.1) (2026-07-29) **Note:** Version bump only for package metascraper </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 9am on tuesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjEzMy4wIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==--> Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1815

The bug
$jsonld('dateCreated')searches the JSON-LD graph recursively, so on a schema.orgVideoObjectit descends intocomment[]and returns a comment's timestamp. YouTube emits no top-leveldatePublished, so every YouTube URL was dated by whichever comment the page happened to embed.Reproducible on the live page:
Found while auditing metadata quality for a citation-generator customer, where a wrong publication date is worse than no date at all.
The fix
uploadDateis the publication date of aVideoObject, so read it before falling back todateCreated, and accept theitempropform YouTube also emits. Order is otherwise untouched:dateModifiedanddatePublishedstill win, and a top-leveldateCreatedis still used when nothing better exists — all four covered by tests.Why it went unnoticed
Two gaps, both closed here:
metascraper-dateshipped with"test": "exit 0"and no test suite. Added one.metascraper-youtube's test destructureddateout of the snapshot and asserted onlytypeof date === 'string', so any wrong date passed. Pinned it.Reverting
src/index.jsmakes the new test fail with exactly the production value:Verification
metascraper-date, all passingmetascraper-youtube8/8 passing with the date now pinned in the snapshotmetascraper-logo-faviconDNS,metascraperaudiense favicon fallback). Both verified to fail identically onmasterwithout this change.date: '2016-04-06T16:59:35.000Z'Known follow-up (not in this PR)
The underlying
$jsonldrecursion intocomment[]/review[]is still there. WithuploadDateahead of it YouTube is fixed, but aVideoObjectthat omitsuploadDateand carries comments could still be mis-dated. Containing that means changingsearchSchemaResultstraversal in@metascraper/helpers, which is a wider blast radius and deserves its own PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01DiDJXMPg2e98kgL3drjg6f
Note
Low Risk
Scoped change to YouTube date extraction with regression tests; no auth, security, or broad behavioral changes beyond correct dates on YouTube URLs.
Overview
Fixes YouTube watch pages being dated by embedded comment timestamps instead of the video’s upload time when generic JSON-LD
dateCreatedwalks intocomment[].metascraper-youtube now defines a
daterule that readsitemprop="uploadDate"(via the shareddatehelper) so the YouTube plugin supplies the correct publication date for video URLs.Adds a regression fixture (VideoObject JSON-LD plus nested comments) and a test that expects
2016-04-06T16:59:35.000Z. The image-size snapshot includesdateinstead of only checkingtypeof date === 'string'.Reviewed by Cursor Bugbot for commit 8013fd9. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
Bug Fixes
Tests