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

Improve library history parsing #27

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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
17 changes: 14 additions & 3 deletions src/service/youtube-music-authenticated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,26 @@ export default class YouTubeMusicAuthenticated extends YouTubeMusicGuest impleme
const response = await this.sendRequest("browse", data);

// cannot use parsePlaylistDetailResponse because last slice is different IE musicPlaylistShelfRenderer !== musicShelfRenderer
const recentPlays = this.playlistParser.traverse(response, "contents", "singleColumnBrowseResultsRenderer", "tabs", "0", "tabRenderer", "content", "sectionListRenderer", "contents", "0", "musicShelfRenderer");
const recentPlaySlices = this.playlistParser.traverse(response, "contents", "singleColumnBrowseResultsRenderer", "tabs", "0", "tabRenderer", "content", "sectionListRenderer", "contents");

// iterate each time slice (IE Today, Yesterday, May 2023) and concatenate all found tracks into one list
const trackLists: any[][] = [];
for(const listContent of recentPlaySlices) {
// need to check renderer and contents exists because sometimes one (or both) don't exist??
if(listContent.musicShelfRenderer !== undefined && listContent.musicShelfRenderer.contents !== undefined && listContent.musicShelfRenderer.contents.length > 0) {
trackLists.push(listContent.musicShelfRenderer.contents);
}
}

const tracks = trackLists.flat(1);

return {
id: 'FEmusic_history', // no real id for this playlist
name: 'History',
description: 'Recently played music in reverse chronological order',
privacy: 'PRIVATE',
count: recentPlays.contents.length,
tracks: this.trackParser.parseTrackDetails(recentPlays.contents)
count: tracks.length,
tracks: this.trackParser.parseTrackDetails(tracks)
}
}

Expand Down