Skip to content
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
9 changes: 8 additions & 1 deletion app/src/main/java/com/github/libretube/api/ExternalApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.github.libretube.api.obj.SubmitSegmentResponse
import com.github.libretube.api.obj.VoteInfo
import com.github.libretube.obj.update.UpdateInfo
import kotlinx.serialization.json.JsonElement
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Headers
Expand All @@ -22,11 +24,16 @@ private const val SB_API_URL = "https://sponsor.ajay.app"
private const val RYD_API_URL = "https://returnyoutubedislikeapi.com"
private const val GOOGLE_API_KEY = "AIzaSyDyT5W0Jh49F30Pqqtyfdf7pDLFKLJoAnw"
const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.3"
private const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks"
private const val PIPED_INSTANCES_MARKDOWN_URL = "https://raw.githubusercontent.com/TeamPiped/documentation/refs/heads/main/content/docs/public-instances/index.md"

interface ExternalApi {
// only for fetching servers list
@GET
suspend fun getInstances(@Url url: String): List<PipedInstance>
suspend fun getInstances(@Url url: String = PIPED_INSTANCES_URL): List<PipedInstance>

@GET
suspend fun getInstancesMarkdown(@Url url: String = PIPED_INSTANCES_MARKDOWN_URL): Response<ResponseBody>

@GET("config")
suspend fun getInstanceConfig(@Url url: String): PipedConfig
Expand Down
26 changes: 16 additions & 10 deletions app/src/main/java/com/github/libretube/api/InstanceRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.github.libretube.api

import android.content.Context
import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance.PIPED_API_URL
import com.github.libretube.api.obj.PipedInstance
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.HttpUrl.Companion.toHttpUrl

class InstanceRepository(private val context: Context) {

Expand All @@ -13,19 +15,23 @@ class InstanceRepository(private val context: Context) {
*/
suspend fun getInstances(): Result<List<PipedInstance>> = withContext(Dispatchers.IO) {
runCatching {
RetrofitInstance.externalApi.getInstances(PIPED_INSTANCES_URL)
RetrofitInstance.externalApi.getInstances()
}
}

fun getInstancesFallback(): List<PipedInstance> {
val instanceNames = context.resources.getStringArray(R.array.instances)
return context.resources.getStringArray(R.array.instancesValue)
.mapIndexed { index, instanceValue ->
PipedInstance(instanceNames[index], instanceValue)
}
}
suspend fun getInstancesFallback(): List<PipedInstance> = withContext(Dispatchers.IO) {
return@withContext try {
RetrofitInstance.externalApi.getInstancesMarkdown().body()!!.string().lines().reversed()
.takeWhile { !it.startsWith("---") }
.filter { it.isNotBlank() }
.map { line ->
val infoParts = line.split("|")

companion object {
private const val PIPED_INSTANCES_URL = "https://piped-instances.kavin.rocks"
PipedInstance(name = infoParts[0], apiUrl = infoParts[1], locations = infoParts[2], cdn = infoParts[3] == "Yes")
}
} catch (e: Exception) {
// worst case scenario: only return official instance
return@withContext listOf(PipedInstance(name = PIPED_API_URL.toHttpUrl().host, apiUrl = PIPED_API_URL))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class MainActivity : BaseActivity() {

val isAppConfigured = PreferenceHelper.getBoolean(PreferenceKeys.LOCAL_FEED_EXTRACTION, false) ||
PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, "").isNotEmpty()
if (isAppConfigured) {
if (!isAppConfigured) {
val welcomeIntent = Intent(this, WelcomeActivity::class.java)
startActivity(welcomeIntent)
finish()
Expand Down
34 changes: 0 additions & 34 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="instances">
<item>kavin.rocks (Official)</item>
<item>syncpundit.io</item>
<item>lunar.icu</item>
<item>r4fo.com</item>
<item>kavin.rocks libre (Official)</item>
<item>projectsegfau.lt</item>
<item>projectsegfau.lt us</item>
<item>smnz.de</item>
<item>adminforge.de</item>
<item>astartes.nl</item>
<item>drgns.space</item>
<item>ducks.party</item>
<item>ngn.tf</item>
<item>coldforge.xyz</item>
</string-array>

<string-array name="instancesValue">
<item>https://pipedapi.kavin.rocks</item>
<item>https://pipedapi.syncpundit.io</item>
<item>https://piped-api.lunar.icu</item>
<item>https://pipedapi.r4fo.com</item>
<item>https://pipedapi-libre.kavin.rocks</item>
<item>https://api.piped.projectsegfau.lt</item>
<item>https://pipedapi.us.projectsegfau.lt</item>
<item>https://pipedapi.smnz.de</item>
<item>https://pipedapi.adminforge.de</item>
<item>https://pipedapi.astartes.nl</item>
<item>https://pipedapi.drgns.space</item>
<item>https://pipedapi.ducks.party</item>
<item>https://pipedapi.ngn.tf</item>
<item>https://pipedapi.coldforge.xyz</item>
</string-array>

<string-array name="languages">
<item>@string/systemLanguage</item>
<item>العربية</item>
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/xml/instance_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
<ListPreference
android:icon="@drawable/ic_server"
app:defaultValue="https://pipedapi.kavin.rocks"
app:entries="@array/instances"
app:entryValues="@array/instancesValue"
app:key="selectInstance"
android:dependency="full_local_mode"
app:title="@string/instances" />
Expand Down Expand Up @@ -70,8 +68,6 @@
android:dependency="auth_instance_toggle"
android:icon="@drawable/ic_server"
app:defaultValue="https://pipedapi.kavin.rocks"
app:entries="@array/instances"
app:entryValues="@array/instancesValue"
app:key="selectAuthInstance"
app:title="@string/auth_instances" />

Expand Down
31 changes: 0 additions & 31 deletions update-instances.sh

This file was deleted.

Loading