Skip to content

Commit 6f48f52

Browse files
committed
feat(YouTube): Warn on alternate release versions
YouTube Music sometimes returns incorrect, alternate versions of a release when looking up a GTIN. This warns if a release with multiple versions is returned, as there is no way of knowing if YouTube returned the correct one.
1 parent 65280fa commit 6f48f52

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

providers/YouTubeMusic/api_types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export type Nodes = {
8787
| Renderer<'MusicShelf'>
8888
| Renderer<'MusicPlaylistShelf'>
8989
| Renderer<'MusicResponsiveHeader'>
90+
| Renderer<'MusicCarouselShelf'>
9091
)[];
9192
};
9293
/** @see https://github.com/LuanRT/YouTube.js/blob/v14.0.0/src/parser/classes/ItemSection.ts */
@@ -138,6 +139,30 @@ export type Nodes = {
138139
MusicCardShelfHeaderBasic: unknown;
139140
/** @see https://github.com/LuanRT/YouTube.js/blob/v14.0.0/src/parser/classes/MusicItemThumbnailOverlay.ts */
140141
MusicItemThumbnailOverlay: unknown;
142+
/** @see https://github.com/LuanRT/YouTube.js/blob/v14.0.0/src/parser/classes/MusicCarouselShelf.ts */
143+
MusicCarouselShelf: {
144+
header: Renderer<'MusicCarouselShelfBasicHeader'>;
145+
contents: Renderer<'MusicTwoRowItem'>[];
146+
};
147+
/** @see https://github.com/LuanRT/YouTube.js/blob/v14.0.0/src/parser/classes/MusicCarouselShelfBasicHeader.ts */
148+
MusicCarouselShelfBasicHeader: {
149+
title: YTText;
150+
accessibilityData?: {
151+
accessibilityData: {
152+
label?: string;
153+
};
154+
};
155+
};
156+
/** @see https://github.com/LuanRT/YouTube.js/blob/v14.0.0/src/parser/classes/MusicTwoRowItem.ts */
157+
MusicTwoRowItem: {
158+
thumbnailRenderer?: Renderer<'MusicThumbnail'>;
159+
aspectRatio?: string;
160+
title: YTText;
161+
subtitle?: YTText;
162+
navigationEndpoint: BrowseEndpoint;
163+
menu?: Renderer<'Menu'>;
164+
thumbnailOverlay: Renderer<'MusicItemThumbnailOverlay'>;
165+
};
141166
/** @see https://github.com/LuanRT/YouTube.js/blob/v14.0.0/src/parser/classes/MusicResponsiveListItem.ts */
142167
MusicResponsiveListItem: {
143168
thumbnail: Renderer<'MusicThumbnail'>;

providers/YouTubeMusic/mod.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,22 @@ export class YouTubeMusicReleaseLookup extends ReleaseLookup<YouTubeMusicProvide
438438
release.releaseDate = { year: releaseYear };
439439
}
440440

441+
const otherVersions = album
442+
.contents
443+
?.twoColumnBrowseResultsRenderer
444+
.secondaryContents.sectionListRenderer
445+
.contents
446+
.filter((renderer) => 'musicCarouselShelfRenderer' in renderer)
447+
.map((shelf) => shelf.musicCarouselShelfRenderer)
448+
.find((shelf) => shelf.header.musicCarouselShelfBasicHeaderRenderer.title.runs.at(0)?.text === 'Other versions')
449+
?.contents
450+
.map((item) => item.musicTwoRowItemRenderer.navigationEndpoint.browseEndpoint.browseId)
451+
.map((id) => this.provider.constructUrl({ id, type: BROWSE }));
452+
453+
if (otherVersions) {
454+
this.warnMultipleResults(otherVersions);
455+
}
456+
441457
return release;
442458
}
443459

0 commit comments

Comments
 (0)