Merge pull request #4819 from Bnyro/master

feat: also parse piped.video links
This commit is contained in:
Bnyro 2023-09-19 11:42:53 +02:00 committed by GitHub
commit b49a59aa73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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"
}
}

View File

@ -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
}