Skip to content

Commit

Permalink
Allow age restricted songs to play by sending age check confirmation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gechoto authored Oct 28, 2024
1 parent a7da937 commit afb3268
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion innertube/src/main/java/com/zionhuang/innertube/YouTube.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.zionhuang.innertube.models.SearchSuggestions
import com.zionhuang.innertube.models.SongItem
import com.zionhuang.innertube.models.WatchEndpoint
import com.zionhuang.innertube.models.WatchEndpoint.WatchEndpointMusicSupportedConfigs.WatchEndpointMusicConfig.Companion.MUSIC_VIDEO_TYPE_ATV
import com.zionhuang.innertube.models.YouTubeClient.Companion.ANDROID_MUSIC
import com.zionhuang.innertube.models.YouTubeClient.Companion.IOS
import com.zionhuang.innertube.models.YouTubeClient.Companion.TVHTML5
import com.zionhuang.innertube.models.YouTubeClient.Companion.WEB
Expand Down Expand Up @@ -417,7 +418,14 @@ object YouTube {
}

suspend fun player(videoId: String, playlistId: String? = null): Result<PlayerResponse> = runCatching {
val playerResponse = innerTube.player(IOS, videoId, playlistId).body<PlayerResponse>()
var playerResponse: PlayerResponse
if (this.cookie != null) { // if logged in: try ANDROID_MUSIC client first because IOS client does not play age restricted songs
playerResponse = innerTube.player(ANDROID_MUSIC, videoId, playlistId).body<PlayerResponse>()
if (playerResponse.playabilityStatus.status == "OK") {
return@runCatching playerResponse
}
}
playerResponse = innerTube.player(IOS, videoId, playlistId).body<PlayerResponse>()
if (playerResponse.playabilityStatus.status == "OK") {
return@runCatching playerResponse
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ data class PlayerBody(
val context: Context,
val videoId: String,
val playlistId: String?,
val contentCheckOk: Boolean = true,
)

0 comments on commit afb3268

Please sign in to comment.