Add extra logic to match albums and tracks to improve match
This commit is contained in:
parent
248e42f841
commit
216940a2b8
2 changed files with 15 additions and 2 deletions
|
@ -76,8 +76,15 @@ export async function search(data, original = {}) {
|
|||
}
|
||||
|
||||
const matches = parse_result_content(result.musicShelfRenderer.contents, data.type)
|
||||
if (matches[0]) {
|
||||
return await lookupId(matches[0], data.type)
|
||||
// This could probably be done without extra lookups, but it would involve parsing deeply the response.
|
||||
// If there's some kind of rate limit on ytmusic's side, this is a good play to start refactoring
|
||||
for (const match of matches) {
|
||||
const possibleMatch = await lookupId(match, data.type)
|
||||
const nameMatch = possibleMatch.name == data.name;
|
||||
const artistMatch = data.artist.name == "" ? possibleMatch.artist.name === 'Various Artists' : data.artist.name == possibleMatch.artist.name;
|
||||
if (nameMatch && artistMatch) {
|
||||
return possibleMatch
|
||||
}
|
||||
}
|
||||
}
|
||||
debug("Finished looking up, no results")
|
||||
|
|
|
@ -27,6 +27,12 @@ describe('ytmusic', function(){
|
|||
result.id.should.equal('MPREb_iZt1VjORlv7');
|
||||
});
|
||||
|
||||
it('should find album and make sure it makes sense by search', async function(){
|
||||
const result = await ytmusic.search({type: 'album', artist: {name: 'The Beatles'}, name: 'The Beatles'});
|
||||
result.name.should.equal('The Beatles');
|
||||
result.id.should.equal('MPREb_S5TiUIYvI78');
|
||||
});
|
||||
|
||||
it('should find track by search', async function (){
|
||||
const result = await ytmusic.search({type: 'track', artist: {name: 'Oasis'}, albumName: 'Stop The Clocks', name: 'Wonderwall'});
|
||||
result.name.should.equal('Wonderwall');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue