Skip to content

Commit

Permalink
Fix #1177
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang authored Jan 11, 2024
2 parents e549420 + e75c69b commit 1f55c0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 16 additions & 0 deletions innertube/src/main/java/com/zionhuang/innertube/models/Runs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ fun List<Run>.splitBySeparator(): List<List<Run>> {
return res
}

fun List<List<Run>>.clean(): List<List<Run>> {
val res = mutableListOf<List<Run>>()
var l: List<List<Run>> = emptyList()
this.getOrNull(0)?.getOrNull(0)?.navigationEndpoint
?.let {
l = this
}
?: run {
l = this.drop(1)
}
l.forEach {
res.add(it)
}
return res
}

fun List<Run>.oddElements() = filterIndexed { index, _ ->
index % 2 == 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ data class ArtistItemsPage(
id = it.navigationEndpoint?.browseEndpoint?.browseId
)
} ?: return null,
album = renderer.flexColumns.getOrNull(2)?.musicResponsiveListItemFlexColumnRenderer?.text?.runs?.firstOrNull()?.let {
album = renderer.flexColumns.getOrNull(3)?.musicResponsiveListItemFlexColumnRenderer?.text?.runs?.firstOrNull()?.let {
Album(
name = it.text,
id = it.navigationEndpoint?.browseEndpoint?.browseId ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.zionhuang.innertube.models.MusicResponsiveListItemRenderer
import com.zionhuang.innertube.models.PlaylistItem
import com.zionhuang.innertube.models.SongItem
import com.zionhuang.innertube.models.YTItem
import com.zionhuang.innertube.models.clean
import com.zionhuang.innertube.models.oddElements
import com.zionhuang.innertube.models.splitBySeparator
import com.zionhuang.innertube.utils.parseTime
Expand Down Expand Up @@ -90,20 +91,24 @@ data class SearchSummaryPage(
val secondaryLine = renderer.flexColumns.getOrNull(1)
?.musicResponsiveListItemFlexColumnRenderer?.text?.runs?.splitBySeparator()
?: return null
val thirdLine = renderer.flexColumns.getOrNull(2)
?.musicResponsiveListItemFlexColumnRenderer?.text?.runs?.splitBySeparator()
?: emptyList()
val listRun = (secondaryLine + thirdLine).clean()
return when {
renderer.isSong -> {
SongItem(
id = renderer.playlistItemData?.videoId ?: return null,
title = renderer.flexColumns.firstOrNull()
?.musicResponsiveListItemFlexColumnRenderer?.text?.runs
?.firstOrNull()?.text ?: return null,
artists = secondaryLine.getOrNull(1)?.oddElements()?.map {
artists = listRun.getOrNull(0)?.oddElements()?.map {
Artist(
name = it.text,
id = it.navigationEndpoint?.browseEndpoint?.browseId
)
} ?: return null,
album = secondaryLine.getOrNull(2)?.firstOrNull()?.takeIf { it.navigationEndpoint?.browseEndpoint != null }?.let {
album = listRun.getOrNull(1)?.firstOrNull()?.takeIf { it.navigationEndpoint?.browseEndpoint != null }?.let {
Album(
name = it.text,
id = it.navigationEndpoint?.browseEndpoint?.browseId!!
Expand Down

0 comments on commit 1f55c0d

Please sign in to comment.