Skip to content

Instantly share code, notes, and snippets.

@webianks
Created October 8, 2025 02:48
Show Gist options
  • Select an option

  • Save webianks/66f63fcac4103f0a282507834a6ad6dd to your computer and use it in GitHub Desktop.

Select an option

Save webianks/66f63fcac4103f0a282507834a6ad6dd to your computer and use it in GitHub Desktop.
Youtube Shorts Logic
class YoutubeUtils {
private val client = OkHttpClient()
suspend fun isYoutubeShortVideo(videoId: String): Boolean =
withContext(Dispatchers.IO) {
val url = "https://www.youtube.com/watch?v=$videoId"
val request = Request.Builder().url(url).build()
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) return@withContext false
val body = response.body()?.string() ?: return@withContext false
val shortsPattern = Regex("""href=["'](https://www\.youtube\.com/shorts/[^"']+)["']""")
val match = shortsPattern.find(body)
return@withContext match != null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment