From b02153040bbb82757877861644bf5421af368b79 Mon Sep 17 00:00:00 2001 From: mattcarter11 <38189440+mattcarter11@users.noreply.github.com> Date: Mon, 16 Sep 2024 22:34:07 +0200 Subject: [PATCH] show all account playlists, not only the first 24 --- .../java/com/zionhuang/innertube/YouTube.kt | 24 ++++++++++++++++--- .../innertube/models/GridRenderer.kt | 1 + .../models/response/BrowseResponse.kt | 8 +++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/innertube/src/main/java/com/zionhuang/innertube/YouTube.kt b/innertube/src/main/java/com/zionhuang/innertube/YouTube.kt index 4b386cfe0..5578d0f16 100644 --- a/innertube/src/main/java/com/zionhuang/innertube/YouTube.kt +++ b/innertube/src/main/java/com/zionhuang/innertube/YouTube.kt @@ -399,17 +399,35 @@ object YouTube { } suspend fun likedPlaylists(): Result> = runCatching { - val response = innerTube.browse( + var response = innerTube.browse( client = WEB_REMIX, browseId = "FEmusic_liked_playlists", setLogin = true ).body() - response.contents?.singleColumnBrowseResultsRenderer?.tabs?.firstOrNull()?.tabRenderer?.content?.sectionListRenderer?.contents?.firstOrNull()?.gridRenderer?.items!! + val gridRenderer = response.contents?.singleColumnBrowseResultsRenderer?.tabs?.firstOrNull()?.tabRenderer?.content?.sectionListRenderer?.contents?.firstOrNull()?.gridRenderer + val playlists = gridRenderer?.items!! .drop(1) // the first item is "create new playlist" .mapNotNull(GridRenderer.Item::musicTwoRowItemRenderer) .mapNotNull { ArtistItemsPage.fromMusicTwoRowItemRenderer(it) as? PlaylistItem - } + }.toMutableList() + var continuation = gridRenderer?.continuations?.getContinuation() + while (continuation != null) { + response = innerTube.browse( + client = WEB_REMIX, + continuation = continuation, + setLogin = true + ).body() + val gridContinuation = response.continuationContents?.gridContinuation + playlists += gridContinuation?.items!! + .drop(1) // the first item is "create new playlist" + .mapNotNull(GridRenderer.Item::musicTwoRowItemRenderer) + .mapNotNull { + ArtistItemsPage.fromMusicTwoRowItemRenderer(it) as? PlaylistItem + } + continuation = gridContinuation?.continuations?.getContinuation() + } + playlists } suspend fun player(videoId: String, playlistId: String? = null): Result = runCatching { diff --git a/innertube/src/main/java/com/zionhuang/innertube/models/GridRenderer.kt b/innertube/src/main/java/com/zionhuang/innertube/models/GridRenderer.kt index 795e8b277..783e7e3e5 100644 --- a/innertube/src/main/java/com/zionhuang/innertube/models/GridRenderer.kt +++ b/innertube/src/main/java/com/zionhuang/innertube/models/GridRenderer.kt @@ -6,6 +6,7 @@ import kotlinx.serialization.Serializable data class GridRenderer( val header: Header?, val items: List, + val continuations: List? ) { @Serializable data class Header( diff --git a/innertube/src/main/java/com/zionhuang/innertube/models/response/BrowseResponse.kt b/innertube/src/main/java/com/zionhuang/innertube/models/response/BrowseResponse.kt index 2273fee40..616aa6b71 100644 --- a/innertube/src/main/java/com/zionhuang/innertube/models/response/BrowseResponse.kt +++ b/innertube/src/main/java/com/zionhuang/innertube/models/response/BrowseResponse.kt @@ -2,6 +2,7 @@ package com.zionhuang.innertube.models.response import com.zionhuang.innertube.models.Button import com.zionhuang.innertube.models.Continuation +import com.zionhuang.innertube.models.GridRenderer.Item import com.zionhuang.innertube.models.Menu import com.zionhuang.innertube.models.MusicShelfRenderer import com.zionhuang.innertube.models.ResponseContext @@ -49,6 +50,7 @@ data class BrowseResponse( data class ContinuationContents( val sectionListContinuation: SectionListContinuation?, val musicPlaylistShelfContinuation: MusicPlaylistShelfContinuation?, + val gridContinuation: GidContinuation ) { @Serializable data class SectionListContinuation( @@ -61,6 +63,12 @@ data class BrowseResponse( val contents: List, val continuations: List?, ) + + @Serializable + data class GidContinuation( + val items: List, + val continuations: List?, + ) } @Serializable