Use new way to transform playlist id into album id
Following changes in https://github.com/sigma67/ytmusicapi/issues/186
This commit is contained in:
parent
2ff1c61510
commit
1b58d95551
2 changed files with 13 additions and 26 deletions
|
@ -202,35 +202,18 @@ async function lookupAlbum(id) {
|
|||
}
|
||||
|
||||
async function lookupPlaylist(id) {
|
||||
let request_body = {enablePersistentPlaylistPanel: true, isAudioOnly: true, playlistId: id, ...standard_body}
|
||||
const { body } = await request.post("https://music.youtube.com/youtubei/v1/next")
|
||||
const endpoint = "https://music.youtube.com/playlist"
|
||||
const response = await request.get(endpoint)
|
||||
.set(standard_headers)
|
||||
.query(standard_params)
|
||||
.send(request_body)
|
||||
|
||||
// The playlist object is rather complex, but here's what I'm doing: I'll parse the very minimum to get to the first track.
|
||||
// At that point, I'm going to check the id of the album in that track. And make a lookup on it. If the album looked up
|
||||
// has the same playlist id as the one I'm looking up, it means it's an album and not a playlist and we're good.
|
||||
const watchNextRenderer = body.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer
|
||||
const firstTrack = watchNextRenderer.tabs[0].tabRenderer.content.musicQueueRenderer.content.playlistPanelRenderer.contents[0]
|
||||
const runs = firstTrack.playlistPanelVideoRenderer.longBylineText.runs
|
||||
const reverse_last_artist_idx = runs.reverse().findIndex((entry) => {
|
||||
if (entry.navigationEndpoint === undefined) {
|
||||
return false
|
||||
}
|
||||
return entry.navigationEndpoint.browseEndpoint.browseId.startsWith("UC") ||
|
||||
entry.navigationEndpoint.browseEndpoint.browseId.startsWith("FEmusic_library_privately_owned_artist")
|
||||
});
|
||||
if (reverse_last_artist_idx == -1) {
|
||||
debug("Could not find an artist. Implement extra logic from ytmusicapi!");
|
||||
.query({list: id})
|
||||
let match = response.text.match(/"MPRE[_a-zA-Z0-9]+/)
|
||||
let albumId
|
||||
if (match) {
|
||||
albumId = match[0].substr(1)
|
||||
} else {
|
||||
debug("Couldn't match album id");
|
||||
throw new Error();
|
||||
}
|
||||
const last_artist_idx = runs.length - reverse_last_artist_idx - 1;
|
||||
if (runs.length - last_artist_idx != 5) {
|
||||
debug("No album found, can't find this.");
|
||||
throw new Error();
|
||||
}
|
||||
const albumId = runs[last_artist_idx + 2].navigationEndpoint.browseEndpoint.browseId
|
||||
const possibleAlbum = await lookupAlbum(albumId)
|
||||
if (possibleAlbum.playlistId = id) {
|
||||
return possibleAlbum;
|
||||
|
|
|
@ -55,6 +55,10 @@ describe('ytmusic', function(){
|
|||
const result = await ytmusic.parseUrl('https://music.youtube.com/playlist?list=OLAK5uy_lx9K5RpiBEwd3E4C1GKqY7e06qTlwydvs');
|
||||
result.id.should.equal("MPREb_9C36yscfgmJ");
|
||||
});
|
||||
it('should parse alternative album url into ID, regression', async function (){
|
||||
const result = await ytmusic.parseUrl('https://music.youtube.com/playlist?list=OLAK5uy_kxepMtCUKFek54-bgWICIsmglK86HD0TM');
|
||||
result.id.should.equal("MPREb_XmlDLpyWvMt");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue