Modern Apps git

← Modern-Apps.git

youpipe: route all video deep links to the player without crashing

Commit
d3cb62572080e823986cd775aa7c6a0f32d28b31
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:09 UTC (28 days ago)
Parents
05b6fca
Share-target and VIEW deep links for youtu.be, /shorts/, /live/ and
/embed/ URLs opened the app on the Home tab instead of the video,
because resolveInitialBackStack only recognized watch?v= links; a
malformed v param crashed onCreate inside videoURLtoID (!! / Base64
decode). Route every launch URI through the total parseSharedVideoId
(null falls through to the default page, never throws) and teach it
the /live/ form.

Verified: ExtractorPureUtilPass3Test gains live, m.youtube.com and
malformed-v cases; full :youpipe:testDevUnitTest run follows.

Diff

youpipe/src/main/java/com/vayunmathur/youpipe/MainActivity.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/MainActivity.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/MainActivity.ktindex 24dbc2164a..804de09538 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/MainActivity.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/MainActivity.kt@@ -58,7 +58,6 @@ import com.vayunmathur.youpipe.ui.dialogs.CreatePlaylist import com.vayunmathur.youpipe.ui.dialogs.AddToPlaylist import com.vayunmathur.youpipe.ui.dialogs.AddToWatchLater import kotlinx.serialization.Serializable-import com.vayunmathur.youpipe.util.videoURLtoID import com.vayunmathur.youpipe.util.parseSharedVideoId  internal fun Context.findActivity(): ComponentActivity {@@ -139,8 +138,13 @@ class MainActivity : MaActivity() {             }         }         val uri = intent.data-        if (uri != null && "watch" in uri.pathSegments && "v" in uri.queryParameterNames) {-            return listOf(Route.Main(TAB_HOME), Route.VideoPage(videoURLtoID(uri.toString())))+        // Total parse: watch, youtu.be, /shorts/, /live/ and /embed/ links route to the+        // video; anything without an 11-char id (channel pages, playlists, garbage `v`+        // params that used to crash videoURLtoID in onCreate) falls through to default.+        if (uri != null) {+            parseSharedVideoId(uri.toString())?.let { videoID ->+                return listOf(Route.Main(TAB_HOME), Route.VideoPage(videoID))+            }         }         return defaultBackStack(DataStoreUtils.getInstance(this).getString(DEFAULT_PAGE_KEY))     }
youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.ktindex 925c47df34..19a6d62ebf 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt@@ -66,11 +66,11 @@ fun videoIDtoURL(id: Long): String = "https://www.youtube.com/watch?v=${decodeVi  /**  * Extracts a YouTube video id from arbitrary shared text (a pasted link, a `watch?v=`,- * `youtu.be/`, `/shorts/`, or `/embed/` URL, possibly surrounded by other text) and encodes+ * `youtu.be/`, `/shorts/`, `/live/`, or `/embed/` URL, possibly surrounded by other text) and encodes  * it to the app's [Long] id. Returns null when no 11-char id can be found.  */ fun parseSharedVideoId(text: String): Long? {-    val match = Regex("""(?:v=|/shorts/|/embed/|youtu\.be/)([A-Za-z0-9_-]{11})""").find(text)+    val match = Regex("""(?:v=|/shorts/|/live/|/embed/|youtu\.be/)([A-Za-z0-9_-]{11})""").find(text)         ?: return null     return runCatching { encodeVideoID(match.groupValues[1]) }.getOrNull() }
youpipe/src/test/java/com/vayunmathur/youpipe/util/ExtractorPureUtilPass3Test.kt
diff --git a/youpipe/src/test/java/com/vayunmathur/youpipe/util/ExtractorPureUtilPass3Test.kt b/youpipe/src/test/java/com/vayunmathur/youpipe/util/ExtractorPureUtilPass3Test.ktindex f1923ebd41..4807f7d46c 100644--- a/youpipe/src/test/java/com/vayunmathur/youpipe/util/ExtractorPureUtilPass3Test.kt+++ b/youpipe/src/test/java/com/vayunmathur/youpipe/util/ExtractorPureUtilPass3Test.kt@@ -46,8 +46,13 @@ class ExtractorPureUtilPass3Test {         assertEquals(expected, parseSharedVideoId("https://youtu.be/dQw4w9WgXcQ"))         assertEquals(expected, parseSharedVideoId("https://www.youtube.com/shorts/dQw4w9WgXcQ"))         assertEquals(expected, parseSharedVideoId("https://www.youtube.com/embed/dQw4w9WgXcQ"))+        assertEquals(expected, parseSharedVideoId("https://www.youtube.com/live/dQw4w9WgXcQ"))+        assertEquals(expected, parseSharedVideoId("https://m.youtube.com/watch?v=dQw4w9WgXcQ"))         assertNull(parseSharedVideoId("no video here"))         assertNull(parseSharedVideoId("https://example.com/watch?v=short"))+        // Malformed `v` params must not parse (deep links with these used to crash onCreate).+        assertNull(parseSharedVideoId("https://www.youtube.com/watch?v=!!!"))+        assertNull(parseSharedVideoId("https://www.youtube.com/watch"))         assertNull(parseSharedVideoId(""))     }     @Test fun channelUrlHelpers() {