mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
add proxy to raw.githubusercontent.com (#368)
This commit is contained in:
parent
00a91ca5fb
commit
51137701f2
6 changed files with 102 additions and 25 deletions
|
@ -32,7 +32,9 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||||
import com.google.android.gms.cast.framework.*
|
import com.google.android.gms.cast.framework.*
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.navigationrail.NavigationRailView
|
import com.google.android.material.navigationrail.NavigationRailView
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
import com.jaredrummler.android.colorpicker.ColorPickerDialogListener
|
||||||
|
import com.lagradost.cloudstream3.app
|
||||||
import com.lagradost.cloudstream3.APIHolder.allProviders
|
import com.lagradost.cloudstream3.APIHolder.allProviders
|
||||||
import com.lagradost.cloudstream3.APIHolder.apis
|
import com.lagradost.cloudstream3.APIHolder.apis
|
||||||
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
|
import com.lagradost.cloudstream3.APIHolder.getApiDubstatusSettings
|
||||||
|
@ -79,6 +81,7 @@ import com.lagradost.cloudstream3.ui.setup.SetupFragmentExtensions
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.html
|
import com.lagradost.cloudstream3.utils.AppUtils.html
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
|
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
|
||||||
|
import com.lagradost.cloudstream3.utils.AppUtils.isNetworkAvailable
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
|
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadRepository
|
import com.lagradost.cloudstream3.utils.AppUtils.loadRepository
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
import com.lagradost.cloudstream3.utils.AppUtils.loadResult
|
||||||
|
@ -86,6 +89,7 @@ import com.lagradost.cloudstream3.utils.AppUtils.loadSearchResult
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
|
import com.lagradost.cloudstream3.utils.AppUtils.setDefaultFocus
|
||||||
import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup
|
import com.lagradost.cloudstream3.utils.BackupUtils.setUpBackup
|
||||||
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
|
||||||
|
import com.lagradost.cloudstream3.utils.Coroutines.main
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
import com.lagradost.cloudstream3.utils.DataStore.getKey
|
||||||
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
import com.lagradost.cloudstream3.utils.DataStore.setKey
|
||||||
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
|
import com.lagradost.cloudstream3.utils.DataStoreHelper.migrateResumeWatching
|
||||||
|
@ -717,6 +721,28 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
|
|
||||||
changeStatusBarState(isEmulatorSettings())
|
changeStatusBarState(isEmulatorSettings())
|
||||||
|
|
||||||
|
// Automatically enable jsdelivr if cant connect to raw.githubusercontent.com
|
||||||
|
if (this.getKey<Boolean>(getString(R.string.jsdelivr_proxy_key)) == null && isNetworkAvailable()) {
|
||||||
|
main {
|
||||||
|
if (checkGithubConnectivity()) {
|
||||||
|
this.setKey(getString(R.string.jsdelivr_proxy_key), false)
|
||||||
|
} else {
|
||||||
|
this.setKey(getString(R.string.jsdelivr_proxy_key), true)
|
||||||
|
val parentView: View = findViewById(android.R.id.content)
|
||||||
|
Snackbar.make(parentView, R.string.jsdelivr_enabled, Snackbar.LENGTH_LONG).let { snackbar ->
|
||||||
|
snackbar.setAction(R.string.revert) {
|
||||||
|
setKey(getString(R.string.jsdelivr_proxy_key), false)
|
||||||
|
}
|
||||||
|
snackbar.setBackgroundTint(colorFromAttribute(R.attr.primaryGrayBackground))
|
||||||
|
snackbar.setTextColor(colorFromAttribute(R.attr.textColor))
|
||||||
|
snackbar.setActionTextColor(colorFromAttribute(R.attr.colorPrimary))
|
||||||
|
snackbar.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (PluginManager.checkSafeModeFile()) {
|
if (PluginManager.checkSafeModeFile()) {
|
||||||
normalSafeApiCall {
|
normalSafeApiCall {
|
||||||
|
@ -1090,4 +1116,12 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun checkGithubConnectivity(): Boolean {
|
||||||
|
return try {
|
||||||
|
app.get("https://raw.githubusercontent.com/recloudstream/.github/master/connectivitycheck", timeout = 5).text.trim() == "ok"
|
||||||
|
} catch (t: Throwable) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package com.lagradost.cloudstream3.plugins
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
||||||
|
import com.lagradost.cloudstream3.R
|
||||||
import com.lagradost.cloudstream3.amap
|
import com.lagradost.cloudstream3.amap
|
||||||
import com.lagradost.cloudstream3.app
|
import com.lagradost.cloudstream3.app
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
|
@ -71,6 +73,15 @@ object RepositoryManager {
|
||||||
val PREBUILT_REPOSITORIES: Array<RepositoryData> by lazy {
|
val PREBUILT_REPOSITORIES: Array<RepositoryData> by lazy {
|
||||||
getKey("PREBUILT_REPOSITORIES") ?: emptyArray()
|
getKey("PREBUILT_REPOSITORIES") ?: emptyArray()
|
||||||
}
|
}
|
||||||
|
val GH_REGEX = Regex("^https://raw.githubusercontent.com/([A-Za-z0-9-]+)/([A-Za-z0-9_.-]+)/(.*)$")
|
||||||
|
|
||||||
|
/* Convert raw.githubusercontent.com urls to cdn.jsdelivr.net if enabled in settings */
|
||||||
|
fun convertRawGitUrl(url: String): String {
|
||||||
|
if (getKey<Boolean>(context!!.getString(R.string.jsdelivr_proxy_key)) != true) return url
|
||||||
|
val match = GH_REGEX.find(url) ?: return url
|
||||||
|
val (user, repo, rest) = match.destructured
|
||||||
|
return "https://cdn.jsdelivr.net/gh/$user/$repo@$rest"
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun parseRepoUrl(url: String): String? {
|
suspend fun parseRepoUrl(url: String): String? {
|
||||||
val fixedUrl = url.trim()
|
val fixedUrl = url.trim()
|
||||||
|
@ -84,10 +95,15 @@ object RepositoryManager {
|
||||||
}
|
}
|
||||||
} else if (fixedUrl.matches("^[a-zA-Z0-9!_-]+$".toRegex())) {
|
} else if (fixedUrl.matches("^[a-zA-Z0-9!_-]+$".toRegex())) {
|
||||||
suspendSafeApiCall {
|
suspendSafeApiCall {
|
||||||
app.get("https://l.cloudstream.cf/${fixedUrl}").let {
|
app.get("https://l.cloudstream.cf/${fixedUrl}", allowRedirects = false).let {
|
||||||
return@let if (it.isSuccessful && !it.url.startsWith("https://cutt.ly/branded-domains")) it.url
|
it.headers["Location"]?.let { url ->
|
||||||
else app.get("https://cutt.ly/${fixedUrl}").let let2@{ it2 ->
|
return@suspendSafeApiCall if (!url.startsWith("https://cutt.ly/branded-domains")) url
|
||||||
return@let2 if (it2.isSuccessful) it2.url else null
|
else null
|
||||||
|
}
|
||||||
|
app.get("https://cutt.ly/${fixedUrl}", allowRedirects = false).let { it2 ->
|
||||||
|
it2.headers["Location"]?.let { url ->
|
||||||
|
return@suspendSafeApiCall if (url.startsWith("https://cutt.ly/404")) url else null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,14 +113,14 @@ object RepositoryManager {
|
||||||
suspend fun parseRepository(url: String): Repository? {
|
suspend fun parseRepository(url: String): Repository? {
|
||||||
return suspendSafeApiCall {
|
return suspendSafeApiCall {
|
||||||
// Take manifestVersion and such into account later
|
// Take manifestVersion and such into account later
|
||||||
app.get(url).parsedSafe()
|
app.get(convertRawGitUrl(url)).parsedSafe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun parsePlugins(pluginUrls: String): List<SitePlugin> {
|
private suspend fun parsePlugins(pluginUrls: String): List<SitePlugin> {
|
||||||
// Take manifestVersion and such into account later
|
// Take manifestVersion and such into account later
|
||||||
return try {
|
return try {
|
||||||
val response = app.get(pluginUrls)
|
val response = app.get(convertRawGitUrl(pluginUrls))
|
||||||
// Normal parsed function not working?
|
// Normal parsed function not working?
|
||||||
// return response.parsedSafe()
|
// return response.parsedSafe()
|
||||||
tryParseJson<Array<SitePlugin>>(response.text)?.toList() ?: emptyList()
|
tryParseJson<Array<SitePlugin>>(response.text)?.toList() ?: emptyList()
|
||||||
|
@ -139,7 +155,7 @@ object RepositoryManager {
|
||||||
}
|
}
|
||||||
file.createNewFile()
|
file.createNewFile()
|
||||||
|
|
||||||
val body = app.get(pluginUrl).okhttpResponse.body
|
val body = app.get(convertRawGitUrl(pluginUrl)).okhttpResponse.body
|
||||||
write(body.byteStream(), file.outputStream())
|
write(body.byteStream(), file.outputStream())
|
||||||
file
|
file
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ val appLanguages = arrayListOf(
|
||||||
Triple("", "norsk bokmål", "no"),
|
Triple("", "norsk bokmål", "no"),
|
||||||
Triple("", "polski", "pl"),
|
Triple("", "polski", "pl"),
|
||||||
Triple("\uD83C\uDDF5\uD83C\uDDF9", "português", "pt"),
|
Triple("\uD83C\uDDF5\uD83C\uDDF9", "português", "pt"),
|
||||||
Triple("🦍", "mmmm... monke", "qt"),
|
Triple("\uD83E\uDD8D", "mmmm... monke", "qt"),
|
||||||
Triple("", "română", "ro"),
|
Triple("", "română", "ro"),
|
||||||
Triple("", "русский", "ru"),
|
Triple("", "русский", "ru"),
|
||||||
Triple("", "slovenčina", "sk"),
|
Triple("", "slovenčina", "sk"),
|
||||||
|
@ -97,7 +97,7 @@ val appLanguages = arrayListOf(
|
||||||
Triple("", "中文", "zh"),
|
Triple("", "中文", "zh"),
|
||||||
Triple("\uD83C\uDDF9\uD83C\uDDFC", "文言", "zh-rTW"),
|
Triple("\uD83C\uDDF9\uD83C\uDDFC", "文言", "zh-rTW"),
|
||||||
/* end language list */
|
/* end language list */
|
||||||
).sortedBy { it.second?.toLowerCase() } //ye, we go alphabetical, so ppl don't put their lang on top
|
).sortedBy { it.second.lowercase() } //ye, we go alphabetical, so ppl don't put their lang on top
|
||||||
|
|
||||||
class SettingsGeneral : PreferenceFragmentCompat() {
|
class SettingsGeneral : PreferenceFragmentCompat() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
@ -157,9 +157,6 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
|
getPref(R.string.locale_key)?.setOnPreferenceClickListener { pref ->
|
||||||
val tempLangs = appLanguages.toMutableList()
|
val tempLangs = appLanguages.toMutableList()
|
||||||
//if (beneneCount > 100) {
|
|
||||||
// tempLangs.add(Triple("\uD83E\uDD8D", "mmmm... monke", "mo"))
|
|
||||||
//}
|
|
||||||
val current = getCurrentLocale(pref.context)
|
val current = getCurrentLocale(pref.context)
|
||||||
val languageCodes = tempLangs.map { (_, _, iso) -> iso }
|
val languageCodes = tempLangs.map { (_, _, iso) -> iso }
|
||||||
val languageNames = tempLangs.map { (emoji, name, iso) ->
|
val languageNames = tempLangs.map { (emoji, name, iso) ->
|
||||||
|
@ -316,6 +313,12 @@ class SettingsGeneral : PreferenceFragmentCompat() {
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
settingsManager.edit().putBoolean(getString(R.string.jsdelivr_proxy_key), getKey(getString(R.string.jsdelivr_proxy_key), false) ?: false).apply()
|
||||||
|
getPref(R.string.jsdelivr_proxy_key)?.setOnPreferenceChangeListener { _, newValue ->
|
||||||
|
setKey(getString(R.string.jsdelivr_proxy_key), newValue)
|
||||||
|
return@setOnPreferenceChangeListener true
|
||||||
|
}
|
||||||
|
|
||||||
getPref(R.string.download_path_key)?.setOnPreferenceClickListener {
|
getPref(R.string.download_path_key)?.setOnPreferenceClickListener {
|
||||||
val dirs = getDownloadDirs()
|
val dirs = getDownloadDirs()
|
||||||
|
|
||||||
|
|
|
@ -491,6 +491,12 @@ object AppUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.isNetworkAvailable(): Boolean {
|
||||||
|
val manager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val activeNetworkInfo = manager.activeNetworkInfo
|
||||||
|
return activeNetworkInfo != null && activeNetworkInfo.isConnected || manager.allNetworkInfo?.any { it.isConnected } ?: false
|
||||||
|
}
|
||||||
|
|
||||||
fun splitQuery(url: URL): Map<String, String> {
|
fun splitQuery(url: URL): Map<String, String> {
|
||||||
val queryPairs: MutableMap<String, String> = LinkedHashMap()
|
val queryPairs: MutableMap<String, String> = LinkedHashMap()
|
||||||
val query: String = url.query
|
val query: String = url.query
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
<string name="random_button_key" translatable="false">random_button_key</string>
|
<string name="random_button_key" translatable="false">random_button_key</string>
|
||||||
<string name="provider_lang_key" translatable="false">provider_lang_key</string>
|
<string name="provider_lang_key" translatable="false">provider_lang_key</string>
|
||||||
<string name="dns_key" translatable="false">dns_key</string>
|
<string name="dns_key" translatable="false">dns_key</string>
|
||||||
|
<string name="jsdelivr_proxy_key" translatable="false">jsdelivr_proxy_key</string>
|
||||||
<string name="download_path_key" translatable="false">download_path_key</string>
|
<string name="download_path_key" translatable="false">download_path_key</string>
|
||||||
<string name="app_name_download_path" translatable="false">Cloudstream</string>
|
<string name="app_name_download_path" translatable="false">Cloudstream</string>
|
||||||
<string name="app_layout_key" translatable="false">app_layout_key</string>
|
<string name="app_layout_key" translatable="false">app_layout_key</string>
|
||||||
|
@ -378,6 +379,9 @@
|
||||||
<string name="video_disk_description">Causes problems if set too high on devices with low storage space, such as Android TV.</string>
|
<string name="video_disk_description">Causes problems if set too high on devices with low storage space, such as Android TV.</string>
|
||||||
<string name="dns_pref">DNS over HTTPS</string>
|
<string name="dns_pref">DNS over HTTPS</string>
|
||||||
<string name="dns_pref_summary">Useful for bypassing ISP blocks</string>
|
<string name="dns_pref_summary">Useful for bypassing ISP blocks</string>
|
||||||
|
<string name="jsdelivr_proxy">raw.githubusercontent.com Proxy</string>
|
||||||
|
<string name="jsdelivr_enabled">Failed to reach GitHub, enabling jsdelivr proxy.</string>
|
||||||
|
<string name="jsdelivr_proxy_summary">Bypasses blocking of GitHub using jsdelivr, may cause updates to be delayed by few days.</string>
|
||||||
<string name="add_site_pref">Clone site</string>
|
<string name="add_site_pref">Clone site</string>
|
||||||
<string name="remove_site_pref">Remove site</string>
|
<string name="remove_site_pref">Remove site</string>
|
||||||
<string name="add_site_summary">Add a clone of an existing site, with a different URL</string>
|
<string name="add_site_summary">Add a clone of an existing site, with a different URL</string>
|
||||||
|
@ -405,6 +409,7 @@
|
||||||
responsibility of user to avoid any actions that might violate the laws governing his/her locality. Use
|
responsibility of user to avoid any actions that might violate the laws governing his/her locality. Use
|
||||||
CloudStream 3 at your own risk.
|
CloudStream 3 at your own risk.
|
||||||
</string>
|
</string>
|
||||||
|
<string name="pref_category_bypass">ISP Bypasses</string>
|
||||||
<string name="pref_category_links">Links</string>
|
<string name="pref_category_links">Links</string>
|
||||||
<string name="pref_category_app_updates">App updates</string>
|
<string name="pref_category_app_updates">App updates</string>
|
||||||
<string name="pref_category_backup">Backup</string>
|
<string name="pref_category_backup">Backup</string>
|
||||||
|
@ -644,6 +649,7 @@
|
||||||
<string name="empty_library_no_accounts_message">Looks like your library is empty :(\nLogin to a library account or add shows to your local library</string>
|
<string name="empty_library_no_accounts_message">Looks like your library is empty :(\nLogin to a library account or add shows to your local library</string>
|
||||||
<string name="empty_library_logged_in_message">Looks like this list is empty, try switching to another one</string>
|
<string name="empty_library_logged_in_message">Looks like this list is empty, try switching to another one</string>
|
||||||
<string name="safe_mode_file">Safe mode file found!\nNot loading any extensions on startup until file is removed.</string>
|
<string name="safe_mode_file">Safe mode file found!\nNot loading any extensions on startup until file is removed.</string>
|
||||||
|
<string name="revert">Revert</string>
|
||||||
<string name="subscription_in_progress_notification">Updating subscribed shows</string>
|
<string name="subscription_in_progress_notification">Updating subscribed shows</string>
|
||||||
<string name="subscription_list_name">Subscribed</string>
|
<string name="subscription_list_name">Subscribed</string>
|
||||||
<string name="subscription_new">Subscribed to %s</string>
|
<string name="subscription_new">Subscribed to %s</string>
|
||||||
|
|
|
@ -6,18 +6,6 @@
|
||||||
android:title="@string/app_language"
|
android:title="@string/app_language"
|
||||||
android:icon="@drawable/ic_baseline_language_24" />
|
android:icon="@drawable/ic_baseline_language_24" />
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="@string/override_site_key"
|
|
||||||
android:title="@string/add_site_pref"
|
|
||||||
android:summary="@string/add_site_summary"
|
|
||||||
android:icon="@drawable/ic_baseline_add_24" />
|
|
||||||
|
|
||||||
<Preference
|
|
||||||
android:key="@string/dns_key"
|
|
||||||
android:title="@string/dns_pref"
|
|
||||||
android:summary="@string/dns_pref_summary"
|
|
||||||
android:icon="@drawable/ic_baseline_dns_24" />
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="@string/download_path_key"
|
android:key="@string/download_path_key"
|
||||||
android:title="@string/download_path_pref"
|
android:title="@string/download_path_pref"
|
||||||
|
@ -34,6 +22,30 @@
|
||||||
android:icon="@drawable/benene"
|
android:icon="@drawable/benene"
|
||||||
app:summary="@string/benene_des" />
|
app:summary="@string/benene_des" />
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:title="@string/pref_category_bypass">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="@string/override_site_key"
|
||||||
|
android:title="@string/add_site_pref"
|
||||||
|
android:summary="@string/add_site_summary"
|
||||||
|
android:icon="@drawable/ic_baseline_add_24" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="@string/dns_key"
|
||||||
|
android:title="@string/dns_pref"
|
||||||
|
android:summary="@string/dns_pref_summary"
|
||||||
|
android:icon="@drawable/ic_baseline_dns_24" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:icon="@drawable/ic_github_logo"
|
||||||
|
android:key="@string/jsdelivr_proxy_key"
|
||||||
|
android:title="@string/jsdelivr_proxy"
|
||||||
|
android:summary="@string/jsdelivr_proxy_summary" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:title="@string/pref_category_links">
|
android:title="@string/pref_category_links">
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue