Fix #203
This commit is contained in:
@@ -415,7 +415,7 @@ private suspend fun fetchAlbum(browseId: String): Result<Album>? {
|
|||||||
shareUrl = youtubeAlbum.url,
|
shareUrl = youtubeAlbum.url,
|
||||||
timestamp = System.currentTimeMillis()
|
timestamp = System.currentTimeMillis()
|
||||||
).also(Database::upsert).also {
|
).also(Database::upsert).also {
|
||||||
youtubeAlbum.withAudioSources().items?.forEachIndexed { position, albumItem ->
|
youtubeAlbum.withAudioSources()?.getOrNull()?.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(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import io.ktor.client.request.parameter
|
|||||||
import io.ktor.client.request.post
|
import io.ktor.client.request.post
|
||||||
import io.ktor.client.request.setBody
|
import io.ktor.client.request.setBody
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
|
import io.ktor.http.Url
|
||||||
import io.ktor.http.contentType
|
import io.ktor.http.contentType
|
||||||
import io.ktor.serialization.kotlinx.json.json
|
import io.ktor.serialization.kotlinx.json.json
|
||||||
import it.vfsfitvnm.youtubemusic.models.BrowseResponse
|
import it.vfsfitvnm.youtubemusic.models.BrowseResponse
|
||||||
@@ -878,43 +879,16 @@ object YouTube {
|
|||||||
?.continuation
|
?.continuation
|
||||||
).next()
|
).next()
|
||||||
}
|
}
|
||||||
}?.recoverIfCancelled()?.getOrNull()
|
}.recoverIfCancelled()?.getOrNull()
|
||||||
} ?: this
|
} ?: this
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun withAudioSources(): PlaylistOrAlbum {
|
suspend fun withAudioSources(): Result<PlaylistOrAlbum>? {
|
||||||
@Serializable
|
return url?.let { Url(it).parameters["list"] }?.let { playlistId ->
|
||||||
data class RelatedStream(
|
playlistOrAlbum("VL$playlistId")?.map { playlist ->
|
||||||
val url: String,
|
copy(items = playlist.items)
|
||||||
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)?.let { source ->
|
|
||||||
item.copy(
|
|
||||||
info = item.info.copy(
|
|
||||||
endpoint = item.info.endpoint?.copy(
|
|
||||||
videoId = source.url.removePrefix("/watch?v=")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} ?: item
|
|
||||||
} else {
|
|
||||||
item
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} ?: this
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user