Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .github/stale.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/lint.yml

This file was deleted.

42 changes: 0 additions & 42 deletions .github/workflows/node_ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
coverage
.nyc_output
dumps
.vscode
.vscode
11 changes: 11 additions & 0 deletions example/artistmix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const YTSR = require('../');

const main = async() => {
return await YTSR('enrique iglesias')
};

main().then(results => {
console.log(results.artistDetails)
}).catch(err => {
console.log(err)
});
8 changes: 8 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const main = module.exports = async(searchString, options, rt = 3) => {
refinements: [],
items: [],
continuation: null,
artistDetails: []
};
// Add refinements
if (Array.isArray(parsed.json.refinements)) {
Expand All @@ -49,6 +50,13 @@ const main = module.exports = async(searchString, options, rt = 3) => {
parsed.json.contents.twoColumnSearchResultsRenderer.primaryContents,
);

// Parse Artist details
const artistWrapper = parsed.json.contents
.twoColumnSearchResultsRenderer.secondaryContents;
if (artistWrapper) {
resp.artistDetails = UTIL.parseArtist(artistWrapper)
}

// Parse items
resp.items = rawItems.map(a => PARSE_ITEM(a, resp)).filter(a => a).filter((_, index) => index < opts.limit);

Expand Down
24 changes: 24 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,30 @@ const cutAfterJSON = exports.cutAfterJSON = mixedJson => {
throw Error("Can't cut unsupported JSON (no matching closing bracket found)");
};

exports.parseArtist = (wrapper) => {
const artistDetails = [];
const artistWrapper = wrapper
.secondarySearchContainerRenderer.contents[0]
.universalWatchCardRenderer;

const artistHeader = artistWrapper.header.watchCardRichHeaderRenderer;
const artistImages = artistWrapper.callToAction.watchCardHeroVideoRenderer.heroImage.collageHeroImageRenderer;
const artistAlbums = artistWrapper.sections[1].watchCardSectionSequenceRenderer.lists[0].horizontalCardListRenderer.cards.map(card => {
return {thumbnail: card.searchRefinementCardRenderer.thumbnail.thumbnails, title: card.searchRefinementCardRenderer.query.runs[0].text}
});
const artistTracks = artistWrapper.sections[0].watchCardSectionSequenceRenderer.lists[0].verticalWatchCardListRenderer.items.map(track => {
return {thumbnail: track.watchCardCompactVideoRenderer.thumbnail.thumbnails, title: track.watchCardCompactVideoRenderer.title.runs[0].text,
subtitle: track.watchCardCompactVideoRenderer.subtitle.simpleText, length: track.watchCardCompactVideoRenderer.lengthText.simpleText,
videoId:track.watchCardCompactVideoRenderer.navigationEndpoint.watchEndpoint.videoId, playlistId: track.watchCardCompactVideoRenderer.navigationEndpoint.watchEndpoint.playlistId}
});
artistDetails.push({
header: {title: artistHeader.title.simpleText, subtitle: artistHeader.subtitle.simpleText, avatar:artistHeader.avatar.thumbnails[0].url},
images: {leftThumbnail:artistImages.leftThumbnail.thumbnails, topRightThumbnail: artistImages.topRightThumbnail.thumbnails, bottomRightThumbnail: artistImages.bottomRightThumbnail.thumbnails},
tracks: artistTracks,
albums: artistAlbums
});
return artistDetails
};
// Exports for testing
exports._hidden = {
jsonAfter, between, cutAfterJSON,
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.