Skip to content

Commit

Permalink
Fixed #547 Fixed #548 Fixed #549 Fixed #551 Fixed #552
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Nov 8, 2024
1 parent 667de58 commit 83e7c9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.maxrave.kotlinytmusicscraper.models.VideoItem
import com.maxrave.kotlinytmusicscraper.models.WatchEndpoint
import com.maxrave.kotlinytmusicscraper.models.YTItemType
import com.maxrave.kotlinytmusicscraper.models.YouTubeClient.Companion.ANDROID_MUSIC
import com.maxrave.kotlinytmusicscraper.models.YouTubeClient.Companion.IOS
import com.maxrave.kotlinytmusicscraper.models.YouTubeClient.Companion.WEB
import com.maxrave.kotlinytmusicscraper.models.YouTubeClient.Companion.WEB_REMIX
import com.maxrave.kotlinytmusicscraper.models.YouTubeLocale
Expand Down Expand Up @@ -1246,7 +1247,7 @@ object YouTube {
]
}.joinToString("")
val playerResponse =
ytMusic.player(ANDROID_MUSIC, videoId, playlistId, cpn).body<PlayerResponse>()
ytMusic.player( if (cookie != null) ANDROID_MUSIC else IOS, videoId, playlistId, cpn).body<PlayerResponse>()
println("Player Response " + playerResponse)
// val ytScrapeInitial: YouTubeInitialPage = ytMusic.player(WEB, videoId, playlistId, cpn).body<YouTubeInitialPage>()
println("Thumbnails " + playerResponse.videoDetails?.thumbnail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class Context(
val gl: String,
val hl: String,
val visitorData: String?,
val osVersion: String?,
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ data class YouTubeClient(
val api_key: String,
val userAgent: String,
val referer: String? = null,
val osVersion: String? = null,
) {
fun toContext(locale: YouTubeLocale, visitorData: String?) = Context(
client = Context.Client(
clientName = clientName,
clientVersion = clientVersion,
gl = locale.gl,
hl = locale.hl,
visitorData = visitorData
)
visitorData = visitorData,
osVersion = osVersion,
)
)

companion object {
Expand All @@ -30,6 +32,7 @@ data class YouTubeClient(

private const val USER_AGENT_WEB = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
private const val USER_AGENT_ANDROID = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Mobile Safari/537.36"
private const val USER_AGENT_IOS = "com.google.ios.youtube/19.29.1 (iPhone16,2; U; CPU iOS 17_5_1 like Mac OS X;)"

val ANDROID_MUSIC = YouTubeClient(
clientName = "ANDROID_MUSIC",
Expand Down Expand Up @@ -88,7 +91,14 @@ data class YouTubeClient(
api_key = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
userAgent = USER_AGENT_WEB,
referer = REFERER_YOUTUBE
)

val IOS = YouTubeClient(
clientName = "IOS",
clientVersion = "19.29.1",
api_key = "AIzaSyB-63vPrdThhKuerbB2N_l7Kwwcxj6yUAc",
userAgent = USER_AGENT_IOS,
osVersion = "17.5.1.21F90",
)
}
}

0 comments on commit 83e7c9c

Please sign in to comment.