Skip to content

Commit

Permalink
Merge pull request #4024 from knighthat/master
Browse files Browse the repository at this point in the history
throw correct error instead of UnknownException for almost every error
  • Loading branch information
fast4x authored Oct 16, 2024
2 parents b5d1041 + a3863b2 commit 566aa7f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,6 @@ class PlayerService : InvincibleService(),
is SocketTimeoutException -> throw TimeoutException()
else -> throw UnknownException()
}

}

runBlocking(Dispatchers.IO) {
Expand Down
77 changes: 39 additions & 38 deletions innertube/src/main/kotlin/it/fast4x/innertube/requests/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,51 @@ suspend fun Innertube.player(body: PlayerBody) = runCatchingNonCancellable {

println("mediaItem requests Player response $response")

if (response.playabilityStatus?.status == "OK") {
response
} else {
@Serializable
data class AudioStream(
val url: String,
val bitrate: Long
)
when( response.playabilityStatus?.status ) {
"OK", "LOGIN_REQUIRED", "UNPLAYABLE" -> response
else -> {
@Serializable
data class AudioStream(
val url: String,
val bitrate: Long
)

@Serializable
data class PipedResponse(
val audioStreams: List<AudioStream>
)
@Serializable
data class PipedResponse(
val audioStreams: List<AudioStream>
)

val safePlayerResponse = client.post(player) {
setBody(
body.copy(
//context = Context.DefaultAgeRestrictionBypass.copy(
context = Context.DefaultWeb.copy(
thirdParty = Context.ThirdParty(
embedUrl = "https://www.youtube.com/watch?v=${body.videoId}"
)
),
val safePlayerResponse = client.post(player) {
setBody(
body.copy(
//context = Context.DefaultAgeRestrictionBypass.copy(
context = Context.DefaultWeb.copy(
thirdParty = Context.ThirdParty(
embedUrl = "https://www.youtube.com/watch?v=${body.videoId}"
)
),
)
)
)
mask("playabilityStatus.status,playerConfig.audioConfig,streamingData.adaptiveFormats,videoDetails.videoId")
}.body<PlayerResponse>()
mask("playabilityStatus.status,playerConfig.audioConfig,streamingData.adaptiveFormats,videoDetails.videoId")
}.body<PlayerResponse>()

if (safePlayerResponse.playabilityStatus?.status != "OK") {
return@runCatchingNonCancellable response
}
if (safePlayerResponse.playabilityStatus?.status != "OK") {
return@runCatchingNonCancellable response
}

val audioStreams = client.get("https://watchapi.whatever.social/streams/${body.videoId}") {
contentType(ContentType.Application.Json)
}.body<PipedResponse>().audioStreams
val audioStreams = client.get("https://watchapi.whatever.social/streams/${body.videoId}") {
contentType(ContentType.Application.Json)
}.body<PipedResponse>().audioStreams

safePlayerResponse.copy(
streamingData = safePlayerResponse.streamingData?.copy(
adaptiveFormats = safePlayerResponse.streamingData.adaptiveFormats?.map { adaptiveFormat ->
adaptiveFormat.copy(
url = audioStreams.find { it.bitrate == adaptiveFormat.bitrate }?.url
)
}
safePlayerResponse.copy(
streamingData = safePlayerResponse.streamingData?.copy(
adaptiveFormats = safePlayerResponse.streamingData.adaptiveFormats?.map { adaptiveFormat ->
adaptiveFormat.copy(
url = audioStreams.find { it.bitrate == adaptiveFormat.bitrate }?.url
)
}
)
)
)
}
}
}

0 comments on commit 566aa7f

Please sign in to comment.