Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ytmusic): Multiple authors/artists #82

Merged
merged 1 commit into from
Jun 27, 2022
Merged
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
26 changes: 17 additions & 9 deletions lib/parser/ytmusic/search/SongResultItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ class SongResultItem {

static parseItem(item) {
const list_item = item.musicResponsiveListItemRenderer;
if (list_item.playlistItemData) return {
id: list_item.playlistItemData.videoId,
title: list_item.flexColumns[0]?.musicResponsiveListItemFlexColumnRenderer.text.runs[0]?.text,
artist: list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs[2]?.text,
album: list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs[4]?.text,
duration: list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs
.find((run) => /^\d+$/.test(run.text.replace(/:/g, ''))).text,
thumbnails: list_item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails,
};
if (list_item.playlistItemData) {
let artists = list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs;
// Remove parts of array that just includes information that the item is a song
artists.splice(0,2);
// Remove parts of array that contains data like album and duration
const meta = artists.splice(artists.length - 4, 4);
// Keep only even parts of array, the odd ones are just a delimiter between artists (&)
artists = artists.filter((artist, index) => !(index % 2));
return {
id: list_item.playlistItemData.videoId,
title: list_item.flexColumns[0]?.musicResponsiveListItemFlexColumnRenderer.text.runs[0]?.text,
artist: artists.map((artist) => artist.text),
album: meta[1]?.text,
duration: meta[3]?.text,
thumbnails: list_item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails,
};
}
}
}

Expand Down
26 changes: 17 additions & 9 deletions lib/parser/ytmusic/search/VideoResultItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ class VideoResultItem {

static parseItem(item) {
const list_item = item.musicResponsiveListItemRenderer;
if (list_item.playlistItemData) return {
id: list_item.playlistItemData.videoId,
title: list_item.flexColumns[0]?.musicResponsiveListItemFlexColumnRenderer.text.runs[0]?.text,
author: list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs[2]?.text,
views: list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs[4]?.text,
duration: list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs
.find((run) => /^\d+$/.test(run.text.replace(/:/g, ''))).text,
thumbnails: list_item?.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails,
};
if (list_item.playlistItemData) {
let authors = list_item.flexColumns[1]?.musicResponsiveListItemFlexColumnRenderer.text.runs;
// Remove parts of array that just includes information that the item is a video
authors.splice(0,2);
// Remove parts of array that contains data like number of views and duration
const meta = authors.splice(authors.length - 4, 4);
// Keep only even parts of array, the odd ones are just a delimiter between authors (&)
authors = authors.filter((author, index) => !(index % 2));
return {
id: list_item.playlistItemData.videoId,
title: list_item.flexColumns[0]?.musicResponsiveListItemFlexColumnRenderer.text.runs[0]?.text,
author: authors.map((author) => author.text),
views: meta[1]?.text,
duration: meta[3]?.text,
thumbnails: list_item?.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails,
};
}
}
}

Expand Down