From ee434f2458b46b47f2fd7ef53832ef6349dc341d Mon Sep 17 00:00:00 2001
From: funkyhippo <52957110+funkyhippo@users.noreply.github.com>
Date: Thu, 1 Aug 2019 05:08:37 -0700
Subject: [PATCH] Fixed API issue caused by change on guya.moe, and added
 description to preferred scanlator. (#1364)

Additional bug-fixes and improvements to Guya extension.
---
 src/en/guya/build.gradle                      |  2 +-
 .../tachiyomi/extension/en/guya/Guya.kt       | 24 +++++++++++++++----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/en/guya/build.gradle b/src/en/guya/build.gradle
index 39ec9ba62..bc13708fa 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 = 2
+    extVersionCode = 3
     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 b43fe5ab9..979f01711 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
@@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.network.GET
 import eu.kanade.tachiyomi.network.asObservableSuccess
 import eu.kanade.tachiyomi.source.ConfigurableSource
 import android.content.SharedPreferences
+import android.os.Build
 import android.support.v7.preference.ListPreference
 import android.support.v7.preference.PreferenceScreen
 import eu.kanade.tachiyomi.extension.BuildConfig
@@ -28,7 +29,10 @@ open class Guya() : ConfigurableSource, HttpSource() {
     override val lang = "en"
 
     override fun headersBuilder() = Headers.Builder().apply {
-        add("User-Agent", "Tachiyomi/${BuildConfig.VERSION_NAME}")
+        add("User-Agent","(Android ${Build.VERSION.RELEASE}; " +
+            "${Build.MANUFACTURER} ${Build.MODEL}) " +
+            "Tachiyomi/${BuildConfig.VERSION_NAME} " +
+            Build.ID)
     }
 
     private val Scanlators: ScanlatorStore = ScanlatorStore()
@@ -61,7 +65,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 + "/", headers)
+        return GET("$baseUrl/reader/series/${manga.url}/", headers)
     }
 
     // Stub
@@ -76,7 +80,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 + "/", headers)
+        return GET("$baseUrl/api/series/${manga.url}/", headers)
     }
 
     // Called after the request
@@ -94,6 +98,10 @@ open class Guya() : ConfigurableSource, HttpSource() {
             }
     }
 
+    override fun pageListRequest(chapter: SChapter): Request {
+        return GET("$baseUrl/api/series/${chapter.url.split("/")[0]}/", headers)
+    }
+
     // Stub
     override fun pageListParse(response: Response): List<Page> {
         throw Exception("Unused")
@@ -164,7 +172,13 @@ open class Guya() : ConfigurableSource, HttpSource() {
             }
             entries = scanlators
             entryValues = scanlatorsIndex
-            summary = "%s"
+            summary = "Current: %s\n\n" +
+                "This setting sets the scanlation group to prioritize " +
+                "on chapter refresh/update. It will get the next available if " +
+                "your preferred scanlator isn't an option (yet)." +
+                "\nNOTE: If you've already downloaded a chapter and the pages aren't updating, " +
+                "clear your chapter cache under Settings > Advanced > Clear chapter cache."
+
             this.setDefaultValue(1)
 
             setOnPreferenceChangeListener{_, newValue ->
@@ -232,7 +246,7 @@ open class Guya() : ConfigurableSource, HttpSource() {
         chapter.scanlator = Scanlators.getValueFromKey(firstGroupId)
         chapter.name = num + " - " + json.getString("title")
         chapter.chapter_number = num.toFloat()
-        chapter.url = "/api/series/$slug/$num/1"
+        chapter.url = "$slug/$num/1"
 
         return chapter
     }