From 1604adaa58e3d9f8a26c28176e9ea8cf4f36aa7f Mon Sep 17 00:00:00 2001 From: funkyhippo <52957110+funkyhippo@users.noreply.github.com> Date: Tue, 30 Jul 2019 04:19:25 -0700 Subject: [PATCH] Added headers to Guya calls. (#1358) Added headers to Guya calls. --- src/en/guya/build.gradle | 2 +- .../tachiyomi/extension/en/guya/Guya.kt | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/en/guya/build.gradle b/src/en/guya/build.gradle index fcdf10246..39ec9ba62 100644 --- a/src/en/guya/build.gradle +++ b/src/en/guya/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Guya' pkgNameSuffix = "en.guya" extClass = '.Guya' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' } diff --git a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt index 3e82bb46f..b43fe5ab9 100644 --- a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt +++ b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt @@ -9,6 +9,7 @@ import eu.kanade.tachiyomi.source.ConfigurableSource import android.content.SharedPreferences import android.support.v7.preference.ListPreference import android.support.v7.preference.PreferenceScreen +import eu.kanade.tachiyomi.extension.BuildConfig import okhttp3.* import org.json.JSONObject import rx.Observable @@ -26,6 +27,10 @@ open class Guya() : ConfigurableSource, HttpSource() { override val supportsLatest = false override val lang = "en" + override fun headersBuilder() = Headers.Builder().apply { + add("User-Agent", "Tachiyomi/${BuildConfig.VERSION_NAME}") + } + private val Scanlators: ScanlatorStore = ScanlatorStore() // Preferences confirguration @@ -36,7 +41,7 @@ open class Guya() : ConfigurableSource, HttpSource() { // Request builder for the "browse" page of the manga override fun popularMangaRequest(page: Int): Request { - return GET("$baseUrl/api/get_all_series") + return GET("$baseUrl/api/get_all_series/", headers) } // Gets the response object from the request @@ -47,7 +52,7 @@ open class Guya() : ConfigurableSource, HttpSource() { // Overridden to use our overload override fun fetchMangaDetails(manga: SManga): Observable { - return clientBuilder().newCall(GET("$baseUrl/api/get_all_series/")) + return clientBuilder().newCall(GET("$baseUrl/api/get_all_series/", headers)) .asObservableSuccess() .map {response -> mangaDetailsParse(response, manga) @@ -56,7 +61,7 @@ open class Guya() : ConfigurableSource, HttpSource() { // Called when the series is loaded, or when opening in browser override fun mangaDetailsRequest(manga: SManga): Request { - return GET("$baseUrl/reader/series/" + manga.url) + return GET("$baseUrl/reader/series/" + manga.url + "/", headers) } // Stub @@ -71,7 +76,7 @@ open class Guya() : ConfigurableSource, HttpSource() { // Gets the chapter list based on the series being viewed override fun chapterListRequest(manga: SManga): Request { - return GET("$baseUrl/api/series/" + manga.url) + return GET("$baseUrl/api/series/" + manga.url + "/", headers) } // Called after the request @@ -123,7 +128,7 @@ open class Guya() : ConfigurableSource, HttpSource() { } override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - return GET("$baseUrl/api/get_all_series") + return GET("$baseUrl/api/get_all_series/", headers) } override fun searchMangaParse(response: Response): MangasPage { @@ -132,7 +137,7 @@ open class Guya() : ConfigurableSource, HttpSource() { private fun searchMangaParse(response: Response, query: String): MangasPage { val res = response.body()!!.string() - var json = JSONObject(res) + val json = JSONObject(res) val truncatedJSON = JSONObject() val iter = json.keys() @@ -299,7 +304,7 @@ open class Guya() : ConfigurableSource, HttpSource() { private fun update() { if (scanlatorMap.isEmpty() && !polling) { polling = true - clientBuilder().newCall(GET("$baseUrl/api/get_all_groups")).enqueue( + clientBuilder().newCall(GET("$baseUrl/api/get_all_groups/", headers)).enqueue( object: Callback { override fun onResponse(call: Call, response: Response) { val json = JSONObject(response.body()!!.string())