Set userAgent to ANDROID client (#385)

This commit is contained in:
vfsfitvnm
2022-10-09 15:44:59 +02:00
parent c00a079715
commit d49ac4fa13
3 changed files with 7 additions and 3 deletions

View File

@@ -160,7 +160,7 @@ fun Thumbnail(
is PlayableFormatNotFoundException -> "Couldn't find a playable audio format"
is UnplayableException -> "The original video source of this song has been deleted"
is LoginRequiredException -> "This song cannot be played due to server restrictions"
is VideoIdMismatchException -> "The returned video id didn't match the requested one"
is VideoIdMismatchException -> "The returned video id doesn't match the requested one"
else -> "An unknown playback error has occurred"
}
},

View File

@@ -14,7 +14,8 @@ data class Context(
val platform: String,
val hl: String = "en",
val visitorData: String? = null,
val androidSdkVersion: Int? = null
val androidSdkVersion: Int? = null,
val userAgent: String? = null
)
@Serializable
@@ -37,7 +38,8 @@ data class Context(
clientName = "ANDROID",
clientVersion = "17.36.4",
platform = "MOBILE",
androidSdkVersion = 31,
androidSdkVersion = 30,
userAgent = "com.google.android.youtube/17.36.4 (Linux; U; Android 11) gzip"
)
)

View File

@@ -6,6 +6,7 @@ import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.http.userAgent
import it.vfsfitvnm.youtubemusic.Innertube
import it.vfsfitvnm.youtubemusic.models.Context
import it.vfsfitvnm.youtubemusic.models.PlayerResponse
@@ -16,6 +17,7 @@ import kotlinx.serialization.Serializable
suspend fun Innertube.player(body: PlayerBody) = runCatchingNonCancellable {
val response = client.post(player) {
setBody(body)
body.context.client.userAgent?.let(::userAgent)
mask("playabilityStatus.status,playerConfig.audioConfig,streamingData.adaptiveFormats")
}.body<PlayerResponse>()