diff --git a/lib/services/ytmusic/index.js b/lib/services/ytmusic/index.js index 0a0b100..85335b3 100644 --- a/lib/services/ytmusic/index.js +++ b/lib/services/ytmusic/index.js @@ -31,7 +31,7 @@ export async function search(data, original = {}) { let query; const various = data.artist.name === 'Various Artists' || data.artist.name === 'Various'; if (various) { - data.artist.name = undefined; + data.artist.name = ""; } if (data.type == "track") { query = [data.name, data.artist.name, data.albumName] @@ -43,8 +43,8 @@ export async function search(data, original = {}) { // Add "" to try and make the search better, works for stuff like "The beatles" to reduce noise query = query.filter(String).map((entry) => '"' + entry + '"').join(" ") - let param = base_filter + (data.type == "track" ? tracks_filter : albums_filter) + exact_search_filter - let request_body = {query, param, ...standard_body } + let params = base_filter + (data.type == "track" ? tracks_filter : albums_filter) + exact_search_filter + let request_body = {query, params, ...standard_body } const { body } = await request.post("https://music.youtube.com/youtubei/v1/search") .set(standard_headers) @@ -57,8 +57,12 @@ export async function search(data, original = {}) { return { service: 'ytmusic' }; } - // I ignore the tabbedSearchResultsRenderer case from ytmusicapi, because we're always selecting a tab. - const results = body.contents.sectionListRenderer.contents + let results; + if (body.contents.tabbedSearchResultsRenderer !== undefined) { + results = body.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content + } else { + results = body.contents.sectionListRenderer.contents + } // no results if (results.length == 1 && results.itemSectionRenderer !== undefined) { @@ -156,14 +160,19 @@ async function lookupAlbum(id) { } return false }).payload.musicAlbumRelease; - let artists = data.filter((entry) => { - if (entry.payload.musicArtist !== undefined) { - if (album_data.primaryArtists.includes(entry.entityKey)) { - return true + let artists; + if (album_data.primaryArtists) { + artists= data.filter((entry) => { + if (entry.payload.musicArtist !== undefined) { + if (album_data.primaryArtists.includes(entry.entityKey)) { + return true + } } - } - return false - }).map((entry) => entry.payload.musicArtist.name); + return false + }).map((entry) => entry.payload.musicArtist.name); + } else { // Various artists, most likely + artists = [album_data.artistDisplayName]; + } const artwork = { small: album_data.thumbnailDetails.thumbnails[0].url,