diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt index 412ccc5a4..0d06e6f04 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt @@ -118,6 +118,6 @@ class ShareDialog : DialogFragment() { companion object { const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com" - private const val PIPED_FRONTEND_URL = "https://piped.video" + const val PIPED_FRONTEND_URL = "https://piped.video" } } diff --git a/app/src/main/java/com/github/libretube/util/TextUtils.kt b/app/src/main/java/com/github/libretube/util/TextUtils.kt index 1b1a5e21c..0f0741924 100644 --- a/app/src/main/java/com/github/libretube/util/TextUtils.kt +++ b/app/src/main/java/com/github/libretube/util/TextUtils.kt @@ -5,6 +5,7 @@ import android.icu.text.RelativeDateTimeFormatter import android.os.Build import android.text.format.DateUtils import com.github.libretube.R +import com.github.libretube.ui.dialogs.ShareDialog import java.time.Instant import java.time.LocalDate import java.time.ZoneId @@ -14,6 +15,7 @@ import java.time.temporal.ChronoUnit import kotlin.time.Duration import kotlinx.datetime.LocalDate as KotlinLocalDate import kotlinx.datetime.toJavaLocalDate +import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull object TextUtils { @@ -53,9 +55,12 @@ object TextUtils { * Get video id if the link is a valid youtube video link */ fun getVideoIdFromUrl(link: String): String? { + val mainPipedFrontendUrl = ShareDialog.PIPED_FRONTEND_URL.toHttpUrl().host + val unShortenedHosts = listOf("www.youtube.com", "m.youtube.com", mainPipedFrontendUrl) + return link.toHttpUrlOrNull()?.let { when (it.host) { - "www.youtube.com", "m.youtube.com" -> it.queryParameter("v") + in unShortenedHosts -> it.queryParameter("v") "youtu.be" -> it.pathSegments.lastOrNull() else -> null }