mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
Merge pull request #4819 from Bnyro/master
feat: also parse piped.video links
This commit is contained in:
commit
b49a59aa73
@ -118,6 +118,6 @@ class ShareDialog : DialogFragment() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val YOUTUBE_FRONTEND_URL = "https://www.youtube.com"
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.icu.text.RelativeDateTimeFormatter
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.text.format.DateUtils
|
import android.text.format.DateUtils
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
|
import com.github.libretube.ui.dialogs.ShareDialog
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
@ -14,6 +15,7 @@ import java.time.temporal.ChronoUnit
|
|||||||
import kotlin.time.Duration
|
import kotlin.time.Duration
|
||||||
import kotlinx.datetime.LocalDate as KotlinLocalDate
|
import kotlinx.datetime.LocalDate as KotlinLocalDate
|
||||||
import kotlinx.datetime.toJavaLocalDate
|
import kotlinx.datetime.toJavaLocalDate
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
|
|
||||||
object TextUtils {
|
object TextUtils {
|
||||||
@ -53,9 +55,12 @@ object TextUtils {
|
|||||||
* Get video id if the link is a valid youtube video link
|
* Get video id if the link is a valid youtube video link
|
||||||
*/
|
*/
|
||||||
fun getVideoIdFromUrl(link: String): String? {
|
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 {
|
return link.toHttpUrlOrNull()?.let {
|
||||||
when (it.host) {
|
when (it.host) {
|
||||||
"www.youtube.com", "m.youtube.com" -> it.queryParameter("v")
|
in unShortenedHosts -> it.queryParameter("v")
|
||||||
"youtu.be" -> it.pathSegments.lastOrNull()
|
"youtu.be" -> it.pathSegments.lastOrNull()
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user