Skip to content

Commit

Permalink
fix(playlist): usage of new youtube api format for playlists/albums. …
Browse files Browse the repository at this point in the history
…Credits to LlinksRechts @ vfsfitvnm#1654.
  • Loading branch information
Sublimeful committed Jul 15, 2024
1 parent e6bdd6c commit d7b33ed
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun AlbumScreen(browseId: String) {
.collect { (currentAlbum, tabIndex) ->
album = currentAlbum

if (albumPage == null && (currentAlbum?.timestamp == null || tabIndex == 1)) {
if (albumPage == null && (currentAlbum?.timestamp == null || currentAlbum.title == null || tabIndex == 1)) {
withContext(Dispatchers.IO) {
Innertube.albumPage(BrowseBody(browseId = browseId))
?.onSuccess { currentAlbumPage ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class BrowseResponse(
@Serializable
data class Contents(
val singleColumnBrowseResultsRenderer: Tabs?,
val twoColumnBrowseResultsRenderer: TwoColResults?,
val sectionListRenderer: SectionListRenderer?,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ data class MusicShelfRenderer(
val bottomEndpoint: NavigationEndpoint?,
val contents: List<Content>?,
val continuations: List<Continuation>?,
val title: Runs?
val title: Runs?,
val thumbnail: ThumbnailRenderer?,
val subtitle: Runs?
) {
@Serializable
data class Content(
Expand All @@ -23,7 +25,7 @@ data class MusicShelfRenderer(
?: emptyList()) to
(musicResponsiveListItemRenderer
?.flexColumns
?.lastOrNull()
?.getOrNull(1)
?.musicResponsiveListItemFlexColumnRenderer
?.text
?.splitBySeparator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ data class SectionListRenderer(
val musicCarouselShelfRenderer: MusicCarouselShelfRenderer?,
@JsonNames("musicPlaylistShelfRenderer")
val musicShelfRenderer: MusicShelfRenderer?,
val musicResponsiveHeaderRenderer: MusicShelfRenderer?,
val musicPlaylistShelfRenderer: MusicShelfRenderer?,
val gridRenderer: GridRenderer?,
val musicDescriptionShelfRenderer: MusicDescriptionShelfRenderer?,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package it.vfsfitvnm.innertube.models

import kotlinx.serialization.Serializable

@Serializable
data class TwoColResults(
val secondaryContents: SecondaryContents?,
val tabs: List<Tabs.Tab>?
) {
@Serializable
data class SecondaryContents(
val sectionListRenderer: SectionListRenderer?
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ suspend fun <T : Innertube.Item> Innertube.itemsPage(

itemsPageFromMusicShelRendererOrGridRenderer(
musicShelfRenderer = sectionListRendererContent
?.musicShelfRenderer,
?.musicPlaylistShelfRenderer,
gridRenderer = sectionListRendererContent
?.gridRenderer,
fromMusicResponsiveListItemRenderer = fromMusicResponsiveListItemRenderer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,31 @@ import it.vfsfitvnm.innertube.utils.runCatchingNonCancellable
suspend fun Innertube.playlistPage(body: BrowseBody) = runCatchingNonCancellable {
val response = client.post(browse) {
setBody(body)
mask("contents.singleColumnBrowseResultsRenderer.tabs.tabRenderer.content.sectionListRenderer.contents(musicPlaylistShelfRenderer(continuations,contents.$musicResponsiveListItemRendererMask),musicCarouselShelfRenderer.contents.$musicTwoRowItemRendererMask),header.musicDetailHeaderRenderer(title,subtitle,thumbnail),microformat")
mask("contents.twoColumnBrowseResultsRenderer(tabs.tabRenderer.content.sectionListRenderer.contents.musicResponsiveHeaderRenderer(title,subtitle,thumbnail),secondaryContents.sectionListRenderer.contents(musicPlaylistShelfRenderer(continuations,contents.$musicResponsiveListItemRendererMask),musicCarouselShelfRenderer.contents.$musicTwoRowItemRendererMask)),microformat")
}.body<BrowseResponse>()

val musicDetailHeaderRenderer = response
.header
?.musicDetailHeaderRenderer

val sectionListRendererContents = response
.contents
?.singleColumnBrowseResultsRenderer
?.twoColumnBrowseResultsRenderer
?.tabs
?.firstOrNull()
?.tabRenderer
?.content
?.sectionListRenderer
?.contents
?.firstOrNull()
?.musicResponsiveHeaderRenderer

val sectionListRendererContents = response
.contents
?.twoColumnBrowseResultsRenderer
?.secondaryContents
?.sectionListRenderer
?.contents

val musicShelfRenderer = sectionListRendererContents
?.firstOrNull()
?.musicShelfRenderer
?.musicPlaylistShelfRenderer

val musicCarouselShelfRenderer = sectionListRendererContents
?.getOrNull(1)
Expand Down

0 comments on commit d7b33ed

Please sign in to comment.