Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

fix(playlist): usage of new youtube api format for playlists/albums #1654

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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 @@ -5,8 +5,10 @@ import io.ktor.client.request.post
import io.ktor.client.request.setBody
import it.vfsfitvnm.innertube.Innertube
import it.vfsfitvnm.innertube.models.BrowseResponse
import it.vfsfitvnm.innertube.models.Continuation
import it.vfsfitvnm.innertube.models.ContinuationResponse
import it.vfsfitvnm.innertube.models.MusicCarouselShelfRenderer
import it.vfsfitvnm.innertube.models.MusicResponsiveListItemRenderer
import it.vfsfitvnm.innertube.models.MusicShelfRenderer
import it.vfsfitvnm.innertube.models.bodies.BrowseBody
import it.vfsfitvnm.innertube.models.bodies.ContinuationBody
Expand All @@ -16,26 +18,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