Fix incorrect thumbnail url and song metadata inference

This commit is contained in:
vfsfitvnm
2022-06-16 15:25:14 +02:00
parent abf2be6c9a
commit 6dbc57aa53
9 changed files with 64 additions and 21 deletions

View File

@@ -159,18 +159,32 @@ object YouTube {
override fun from(content: MusicShelfRenderer.Content): Song {
val (mainRuns, otherRuns) = content.runs
// Possible configurations:
// "song" • author(s) • album • duration
// "song" • author(s) • duration
// author(s) • album • duration
// author(s) • duration
val album: Info<NavigationEndpoint.Endpoint.Browse>? = otherRuns
.getOrNull(otherRuns.lastIndex - 1)
?.firstOrNull()
?.takeIf { run ->
run
.navigationEndpoint
?.browseEndpoint
?.type == "MUSIC_PAGE_TYPE_ALBUM"
}
?.let(Info.Companion::from)
return Song(
info = Info.from(mainRuns.first()),
authors = otherRuns
.getOrNull(otherRuns.lastIndex - 2)
.getOrNull(otherRuns.lastIndex - if (album == null) 1 else 2)
?.map(Info.Companion::from)
?: emptyList(),
album = otherRuns
.getOrNull(otherRuns.lastIndex - 1)
?.firstOrNull()
?.let(Info.Companion::from),
album = album,
durationText = otherRuns
.getOrNull(otherRuns.lastIndex)
.lastOrNull()
?.firstOrNull()?.text,
thumbnail = content
.thumbnail
@@ -603,8 +617,13 @@ object YouTube {
thumbnail = renderer
.thumbnail
.thumbnails
.getOrNull(0),
durationText = renderer.lengthText.text
.also {
println(it)
}
.firstOrNull(),
durationText = renderer
.lengthText
.text
)
},
lyrics = NextResult.Lyrics(

View File

@@ -56,10 +56,8 @@ data class NavigationEndpoint(
val endpoint: Endpoint?
get() = watchEndpoint ?: browseEndpoint ?: watchPlaylistEndpoint ?: searchEndpoint
@Serializable
sealed class Endpoint {
@Serializable
data class Watch(
val params: String? = null,
@@ -69,6 +67,10 @@ data class NavigationEndpoint(
val playlistSetVideoId: String? = null,
val watchEndpointMusicSupportedConfigs: WatchEndpointMusicSupportedConfigs? = null,
) : Endpoint() {
val type: String?
get() = watchEndpointMusicSupportedConfigs
?.watchEndpointMusicConfig
?.musicVideoType
@Serializable
data class WatchEndpointMusicSupportedConfigs(
@@ -82,7 +84,6 @@ data class NavigationEndpoint(
}
}
@Serializable
data class WatchPlaylist(
val params: String?,
@@ -96,6 +97,10 @@ data class NavigationEndpoint(
val browseId: String,
val browseEndpointContextSupportedConfigs: BrowseEndpointContextSupportedConfigs?,
) : Endpoint() {
val type: String?
get() = browseEndpointContextSupportedConfigs
?.browseEndpointContextMusicConfig
?.pageType
@Serializable
data class BrowseEndpointContextSupportedConfigs(

View File

@@ -16,7 +16,11 @@ data class Runs(
run.text == "" -> listOf(index - 1, index + 1)
else -> emptyList()
}
}.windowed(size = 2, step = 2) { (from, to) -> runs.slice(from..to) }
}.windowed(size = 2, step = 2) { (from, to) -> runs.slice(from..to) }.let {
it.ifEmpty {
listOf(runs)
}
}
}
@Serializable

View File

@@ -45,3 +45,4 @@ data class ThumbnailRenderer(
}
}
}