Skip to content

Commit

Permalink
fix(online playlist): playing song position incorrect, close #1532
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Sep 3, 2024
1 parent 0f4857f commit 138dec1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 13 additions & 10 deletions innertube/src/main/java/com/zionhuang/innertube/YouTube.kt
Original file line number Diff line number Diff line change
Expand Up @@ -440,29 +440,32 @@ object YouTube {
val title = response.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content?.musicQueueRenderer?.header?.musicQueueHeaderRenderer?.subtitle?.runs?.firstOrNull()?.text
val playlistPanelRenderer = response.continuationContents?.playlistPanelContinuation
?: response.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs[0].tabRenderer.content?.musicQueueRenderer?.content?.playlistPanelRenderer!!

val items = playlistPanelRenderer.contents.mapNotNull { content ->
content.playlistPanelVideoRenderer
?.let(NextPage::fromPlaylistPanelVideoRenderer)
?.let { it to content.playlistPanelVideoRenderer.selected }
}
val songs = items.map { it.first }
val currentIndex = items.indexOfFirst { it.second }.takeIf { it != -1 }

// load automix items
playlistPanelRenderer.contents.lastOrNull()?.automixPreviewVideoRenderer?.content?.automixPlaylistVideoRenderer?.navigationEndpoint?.watchPlaylistEndpoint?.let { watchPlaylistEndpoint ->
return@runCatching next(watchPlaylistEndpoint).getOrThrow().let { result ->
result.copy(
title = title,
items = playlistPanelRenderer.contents.mapNotNull {
it.playlistPanelVideoRenderer?.let { renderer ->
NextPage.fromPlaylistPanelVideoRenderer(renderer)
}
} + result.items,
items = songs + result.items,
lyricsEndpoint = response.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs.getOrNull(1)?.tabRenderer?.endpoint?.browseEndpoint,
relatedEndpoint = response.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs.getOrNull(2)?.tabRenderer?.endpoint?.browseEndpoint,
currentIndex = playlistPanelRenderer.currentIndex,
currentIndex = currentIndex,
endpoint = watchPlaylistEndpoint
)
}
}
NextResult(
title = title,
items = playlistPanelRenderer.contents.mapNotNull {
it.playlistPanelVideoRenderer?.let(NextPage::fromPlaylistPanelVideoRenderer)
},
currentIndex = playlistPanelRenderer.currentIndex,
items = songs,
currentIndex = currentIndex,
lyricsEndpoint = response.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs.getOrNull(1)?.tabRenderer?.endpoint?.browseEndpoint,
relatedEndpoint = response.contents.singleColumnMusicWatchNextResultsRenderer.tabbedRenderer.watchNextTabbedResultsRenderer.tabs.getOrNull(2)?.tabRenderer?.endpoint?.browseEndpoint,
continuation = playlistPanelRenderer.continuations?.getContinuation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ data class PlaylistPanelRenderer(
val titleText: Runs?,
val shortBylineText: Runs?,
val contents: List<Content>,
val currentIndex: Int?,
val isInfinite: Boolean,
val numItemsToShow: Int?,
val playlistId: String?,
Expand Down

0 comments on commit 138dec1

Please sign in to comment.