feat(amp-youtube): add data-channelid to embed a channel's uploads - #40529
feat(amp-youtube): add data-channelid to embed a channel's uploads#40529mmustafasenoglu wants to merge 4 commits into
Conversation
Allows embedding a YouTube channel's uploads playlist via a new data-channelid attribute, mirroring the existing data-videoid and data-live-channelid datasources. The uploads playlist id is the channel id prefixed with "UU". - 0.1 (extensions/amp-youtube) and 1.0 (bento) now support data-channelid - validator: data-channelid added to the mandatory_oneof group - tests: 0.1 render test + updated datasource assertion + validator fixture - docs: documented data-channelid in amp-youtube.md Refs ampproject#26304
- EXAMPLE_CHANNELID_URL should use embed/? (baseUrl ends with slash) - update extensions/amp-youtube/1.0/test/validator-amp-youtube.out error messages to include data-channelid in the mandatory_oneof list
|
Hi @ampproject/wg-components, could you take a look when you get a chance? I added additional tests for the new
The CircleCI |
There was a problem hiding this comment.
Pull request overview
Adds first-class support for embedding a YouTube channel’s uploads feed via a new data-channelid datasource on <amp-youtube>, implemented across both the legacy (0.1) runtime and the Bento (1.0) component, with corresponding validator and documentation updates.
Changes:
- Add
data-channelid/channelidas a third mutually-exclusive datasource alongsidedata-videoidanddata-live-channelid. - Extend embed URL generation to support channel uploads playlist embedding.
- Update validator rules, fixtures, and tests/docs to recognize and enforce the new attribute.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/fixtures/errors.html | Updates expected runtime error substring to include data-channelid. |
| src/bento/components/bento-youtube/1.0/component.js | Adds channelid prop support, exclusivity checks, and channel embed URL construction. |
| src/bento/components/bento-youtube/1.0/base-element.js | Maps channelid prop to data-channelid attribute. |
| extensions/amp-youtube/validator-amp-youtube.protoascii | Extends mandatory_oneof validator group to include data-channelid. |
| extensions/amp-youtube/amp-youtube.md | Documents data-channelid behavior and example URL. |
| extensions/amp-youtube/1.0/test/validator-amp-youtube.out | Updates validator expected output to mention data-channelid in oneof lists. |
| extensions/amp-youtube/0.1/test/validator-amp-youtube.out | Updates validator expected output to mention data-channelid in oneof lists. |
| extensions/amp-youtube/0.1/test/test-amp-youtube.js | Adds render test and exclusivity tests for data-channelid, plus no-cookie coverage. |
| extensions/amp-youtube/0.1/amp-youtube.js | Implements data-channelid parsing, URL construction, and exclusivity assertion updates. |
Suppressed comments (1)
extensions/amp-youtube/0.1/test/test-amp-youtube.js:332
- This assertion matches the current (incorrect) UU + channelid behavior. If uploads playlist ids are derived by replacing leading "UC" with "UU", this should assert against the transformed id (e.g. 'UU' + channelid.slice(2)).
expect(iframe.src).to.contain('listType=playlist');
expect(iframe.src).to.contain('list=UU' + EXAMPLE_CHANNELID);
});
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| : // Channel embeds use the channel's uploads playlist. The uploads | ||
| // playlist id is the channel id prefixed with "UU". | ||
| `?listType=playlist&list=UU${encodeURIComponent(this.channelid_ || '')}&`; |
| // Channel embeds use the channel's uploads playlist. The uploads | ||
| // playlist id is the channel id prefixed with "UU". | ||
| descriptor = `?listType=playlist&list=UU${encodeURIComponent( | ||
| channelid || '' | ||
| )}&`; |
| * @param {string} liveChannelid | ||
| * @return {string} | ||
| * @private | ||
| */ | ||
| function getEmbedUrl(credentials, videoid, liveChannelid) { | ||
| function getEmbedUrl(credentials, videoid, liveChannelid, channelid) { |
| const EXAMPLE_CHANNELID = 'UCB8Kb4pxYzsDsHxzBfnid4Q'; | ||
| const EXAMPLE_VIDEOID_URL = `https://www.youtube.com/embed/${EXAMPLE_VIDEOID}?enablejsapi=1&=1&playsinline=1`; | ||
| const EXAMPLE_LIVE_CHANNELID_URL = `https://www.youtube.com/embed/live_stream?channel=${EXAMPLE_LIVE_CHANNELID}&enablejsapi=1&=1&playsinline=1`; | ||
| const EXAMPLE_CHANNELID_URL = `https://www.youtube.com/embed/?listType=playlist&list=UU${EXAMPLE_CHANNELID}&enablejsapi=1&=1&playsinline=1`; |
|
|
||
| ### data-channelid | ||
|
|
||
| The YouTube channel id whose uploads playlist should be embedded. For example, in this URL: `https://www.youtube.com/embed?listType=playlist&list=UUUB8Kb4pxYzsDsHxzBfnid4Q`, `UB8Kb4pxYzsDsHxzBfnid4Q` is the channel id (the uploads playlist id is the channel id prefixed with `UU`). You can provide a `data-channelid` instead of a `data-videoid` attribute to embed a channel's uploads instead of a single video. Channels do not come with default placeholders. You can provide a placeholder for the video per example 2 above. |
| function BentoYoutubeWithRef( | ||
| { | ||
| autoplay, | ||
| channelid, | ||
| credentials, |
What does this PR do?
Closes #26304. Adds a new
data-channelidattribute to<amp-youtube>so a YouTube channel's uploads can be embedded, mirroring the existingdata-videoidanddata-live-channeliddatasources.Why
The original request asked for a way to embed a YouTube channel. A channel embed is just its uploads playlist, whose id is the channel id prefixed with
UU(e.g.https://www.youtube.com/embed?listType=playlist&list=UU<channelId>). This PR implements that as a first-class datasource.How
extensions/amp-youtube/0.1/amp-youtube.js): addedchannelid_,getChannelId_(), extendedgetEmbedUrl_()to build?listType=playlist&list=UU<channelId>, and updatedassertDatasourceExists_()so exactly one ofdata-videoid/data-live-channelid/data-channelidis required.src/bento/components/bento-youtube/1.0/): same logic incomponent.js(getEmbedUrl) plus achannelidprop mapped todata-channelidinbase-element.js.extensions/amp-youtube/validator-amp-youtube.protoascii):data-channelidadded to themandatory_oneofgroup and as an allowed attribute.data-channelid, updated datasource assertion, updated validator.outmessages, andtest/fixtures/errors.htmlexpected error.data-channeliddocumented inamp-youtube.md.Notes
Checklist
data-channelidworks for both 0.1 and 1.0data-channelidand enforces exactly-one-of