Skip to content

Commit 044f1f5

Browse files
committed
Add embedWidth and embedHeight to sourceData, so clients can use the aspect ratio.
1 parent 882189c commit 044f1f5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ function normalizeMedia(video) {
5353
duration: parseYouTubeDuration(video.contentDetails.duration),
5454
thumbnail: getBestThumbnail(video.snippet.thumbnails),
5555
sourceData: {
56+
// Can be used by clients to determine the aspect ratio.
57+
embedWidth: video.player ? parseInt(video.player.embedWidth, 10) : null,
58+
embedHeight: video.player ? parseInt(video.player.embedHeight, 10) : null,
5659
blockedIn: getBlockedCountryCodes(video.contentDetails)
5760
}
5861
};
@@ -126,15 +129,21 @@ export default function youTubeSource(uw, opts = {}) {
126129
async function getPage(sourceIDs) {
127130
const result = await youTubeGet({
128131
...params,
129-
part: 'snippet,contentDetails',
132+
part: 'snippet,contentDetails,player',
130133
fields: `
131134
items(
132135
id,
133136
snippet(title, channelTitle, thumbnails),
134-
contentDetails(duration, regionRestriction)
137+
contentDetails(duration, regionRestriction),
138+
player(embedWidth, embedHeight)
135139
)
136140
`.replace(/\s+/g, ''),
137-
id: sourceIDs.join(',')
141+
id: sourceIDs.join(','),
142+
// These are the maximum acceptable values, we only send them to force
143+
// YouTube to send an embedWidth and embedHeight back so we can calculate
144+
// the video aspect ratio.
145+
maxWidth: 8192,
146+
maxHeight: 8192
138147
});
139148

140149
return result.items.map(normalizeMedia);

0 commit comments

Comments
 (0)