Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: also parse piped.video links #4819

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
7 changes: 6 additions & 1 deletion app/src/main/java/com/github/libretube/util/TextUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
Loading