Fetch audio-only video ids for albums (#88)
This commit is contained in:
@@ -71,7 +71,7 @@ fun AlbumScreen(
|
|||||||
authorsText = youtubeAlbum.authors?.joinToString("") { it.name },
|
authorsText = youtubeAlbum.authors?.joinToString("") { it.name },
|
||||||
shareUrl = youtubeAlbum.url
|
shareUrl = youtubeAlbum.url
|
||||||
).also(Database::upsert).also {
|
).also(Database::upsert).also {
|
||||||
youtubeAlbum.items?.forEachIndexed { position, albumItem ->
|
youtubeAlbum.withAudioSources().items?.forEachIndexed { position, albumItem ->
|
||||||
albumItem.toMediaItem(browseId, youtubeAlbum)?.let { mediaItem ->
|
albumItem.toMediaItem(browseId, youtubeAlbum)?.let { mediaItem ->
|
||||||
Database.insert(mediaItem)
|
Database.insert(mediaItem)
|
||||||
Database.upsert(
|
Database.upsert(
|
||||||
|
|||||||
@@ -691,7 +691,7 @@ object YouTube {
|
|||||||
}.recoverIfCancelled()
|
}.recoverIfCancelled()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class PlaylistOrAlbum(
|
data class PlaylistOrAlbum(
|
||||||
val title: String?,
|
val title: String?,
|
||||||
val authors: List<Info<NavigationEndpoint.Endpoint.Browse>>?,
|
val authors: List<Info<NavigationEndpoint.Endpoint.Browse>>?,
|
||||||
val year: String?,
|
val year: String?,
|
||||||
@@ -700,13 +700,50 @@ object YouTube {
|
|||||||
val url: String?,
|
val url: String?,
|
||||||
val continuation: String?,
|
val continuation: String?,
|
||||||
) {
|
) {
|
||||||
open class Item(
|
data class Item(
|
||||||
val info: Info<NavigationEndpoint.Endpoint.Watch>,
|
val info: Info<NavigationEndpoint.Endpoint.Watch>,
|
||||||
val authors: List<Info<NavigationEndpoint.Endpoint.Browse>>?,
|
val authors: List<Info<NavigationEndpoint.Endpoint.Browse>>?,
|
||||||
val durationText: String?,
|
val durationText: String?,
|
||||||
val album: Info<NavigationEndpoint.Endpoint.Browse>?,
|
val album: Info<NavigationEndpoint.Endpoint.Browse>?,
|
||||||
val thumbnail: ThumbnailRenderer.MusicThumbnailRenderer.Thumbnail.Thumbnail?,
|
val thumbnail: ThumbnailRenderer.MusicThumbnailRenderer.Thumbnail.Thumbnail?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
suspend fun withAudioSources(): PlaylistOrAlbum {
|
||||||
|
@Serializable
|
||||||
|
data class RelatedStream(
|
||||||
|
val url: String,
|
||||||
|
val title: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class Response(
|
||||||
|
val relatedStreams: List<RelatedStream>
|
||||||
|
)
|
||||||
|
|
||||||
|
return url?.replace("https://music.youtube.com/playlist?list=", "https://pipedapi.kavin.rocks/playlists/")?.let { url ->
|
||||||
|
val sources = client.get(url).body<Response>().relatedStreams
|
||||||
|
|
||||||
|
copy(
|
||||||
|
items = items?.mapIndexed { index, item ->
|
||||||
|
if (item.info.endpoint?.type != "MUSIC_VIDEO_TYPE_ATV") {
|
||||||
|
sources.getOrNull(index)?.takeIf { source ->
|
||||||
|
source.title == item.info.name
|
||||||
|
}?.let { source ->
|
||||||
|
item.copy(
|
||||||
|
info = item.info.copy(
|
||||||
|
endpoint = item.info.endpoint?.copy(
|
||||||
|
videoId = source.url.removePrefix("/watch?v=")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} ?: item
|
||||||
|
} else {
|
||||||
|
item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} ?: this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun playlistOrAlbum(browseId: String): Result<PlaylistOrAlbum>? {
|
suspend fun playlistOrAlbum(browseId: String): Result<PlaylistOrAlbum>? {
|
||||||
@@ -795,7 +832,8 @@ object YouTube {
|
|||||||
?.firstOrNull()
|
?.firstOrNull()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
?.filter { it.info.endpoint != null },
|
// ?.filter { it.info.endpoint != null }
|
||||||
|
,
|
||||||
url = body
|
url = body
|
||||||
.microformat
|
.microformat
|
||||||
?.microformatDataRenderer
|
?.microformatDataRenderer
|
||||||
|
|||||||
Reference in New Issue
Block a user