Created
October 8, 2025 02:48
-
-
Save webianks/66f63fcac4103f0a282507834a6ad6dd to your computer and use it in GitHub Desktop.
Youtube Shorts Logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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