Proxy implemented

This commit is contained in:
Pupil
2020-02-16 19:59:51 +09:00
parent 0d93785581
commit ac1ca71299
16 changed files with 68 additions and 31 deletions

View File

@@ -20,7 +20,7 @@ android {
minSdkVersion 16
targetSdkVersion 29
versionCode 42
versionName "4.6-beta4"
versionName "4.6-alpha4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true

View File

@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6-beta4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":42,"versionName":"4.6-alpha4","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]

View File

@@ -31,7 +31,9 @@ import com.google.android.gms.common.GooglePlayServicesNotAvailableException
import com.google.android.gms.common.GooglePlayServicesRepairableException
import com.google.android.gms.security.ProviderInstaller
import com.google.firebase.analytics.FirebaseAnalytics
import xyz.quaver.proxy
import xyz.quaver.pupil.util.Histories
import xyz.quaver.pupil.util.getProxy
import java.io.File
class Pupil : MultiDexApplication() {
@@ -46,6 +48,8 @@ class Pupil : MultiDexApplication() {
override fun onCreate() {
val preference = PreferenceManager.getDefaultSharedPreferences(this)
proxy = getProxy(this)
try {
preference.getString("dl_location", null)
} catch (e: Exception) {

View File

@@ -83,15 +83,6 @@ class ReaderAdapter(private val context: Context,
var onItemClickListener : ((Int) -> (Unit))? = null
init {
CoroutineScope(Dispatchers.IO).launch {
reader = Cache(context).getReader(galleryID)
launch(Dispatchers.Main) {
notifyDataSetChanged()
}
}
}
class ViewHolder(val view: View) : RecyclerView.ViewHolder(view)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {

View File

@@ -22,6 +22,7 @@ import android.content.Intent
import android.graphics.drawable.Animatable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.util.Log
import android.view.*
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
@@ -238,9 +239,11 @@ class ReaderActivity : AppCompatActivity() {
}
timer.schedule(1000, 1000) {
Log.i("PUPILD", "TIMER")
if (worker.progress.indexOfKey(galleryID) < 0) //loading
return@schedule
Log.i("PUPILD", "LOADEND")
if (worker.progress[galleryID] == null) { //Gallery not found
timer.cancel()
Snackbar
@@ -248,15 +251,25 @@ class ReaderActivity : AppCompatActivity() {
.show()
}
Log.i("PUPILD", "GALLERY")
runOnUiThread {
Log.i("PUPILD", "UI")
reader_download_progressbar.max = reader_recyclerview.adapter?.itemCount ?: 0
reader_download_progressbar.progress = worker.progress[galleryID]?.count { !it.isFinite() } ?: 0
reader_progressbar.max = reader_recyclerview.adapter?.itemCount ?: 0
Log.i("PUPILD", "COUNTEND")
if (title == getString(R.string.reader_loading)) {
val reader = (reader_recyclerview.adapter as ReaderAdapter).reader
Log.i("PUPILD", "LOADING")
val reader = Cache(this@ReaderActivity).getReaderOrNull(galleryID)
Log.i("PUPILD", "READER")
if (reader != null) {
Log.i("PUPILD", "NOTNULL")
with (reader_recyclerview?.adapter as ReaderAdapter) {
this.reader = reader
notifyDataSetChanged()
}
title = reader.title
menu?.findItem(R.id.reader_menu_page_indicator)?.title = "$currentPage/${reader.galleryInfo.size}"

View File

@@ -29,6 +29,7 @@ import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.preference.PreferenceManager
import kotlinx.android.synthetic.main.dialog_proxy.view.*
import xyz.quaver.proxy
import xyz.quaver.pupil.R
import xyz.quaver.pupil.util.ProxyInfo
import xyz.quaver.pupil.util.getProxyInfo
@@ -114,9 +115,14 @@ class ProxyDialog(context: Context) : Dialog(context) {
return@setOnClickListener
}
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("proxy",
json.stringify(ProxyInfo.serializer(), ProxyInfo(type, addr, port, username, password))
).apply()
ProxyInfo(type, addr, port, username, password).let {
PreferenceManager.getDefaultSharedPreferences(context).edit().putString("proxy",
json.stringify(ProxyInfo.serializer(), it)
).apply()
proxy = it.proxy()
}
dismiss()
}

View File

@@ -155,9 +155,11 @@ class Cache(context: Context) : ContextWrapper(context) {
var retval: Reader? = null
for (source in sources) {
retval = kotlin.runCatching {
retval = try {
source.value.invoke()
}.getOrNull()
} catch (e: Exception) {
null
}
if (retval != null)
break

View File

@@ -23,6 +23,7 @@ import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.SharedPreferences
import android.util.Log
import android.util.SparseArray
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
@@ -40,9 +41,9 @@ import xyz.quaver.hitomi.urlFromUrlFromHash
import xyz.quaver.hiyobi.cookie
import xyz.quaver.hiyobi.createImgList
import xyz.quaver.hiyobi.user_agent
import xyz.quaver.proxy
import xyz.quaver.pupil.R
import xyz.quaver.pupil.ui.ReaderActivity
import xyz.quaver.pupil.util.getProxy
import java.io.IOException
import java.util.concurrent.Executors
import java.util.concurrent.LinkedBlockingQueue
@@ -160,7 +161,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
OkHttpClient.Builder()
.addInterceptor(interceptor)
.dispatcher(Dispatcher(Executors.newFixedThreadPool(4)))
.proxy(getProxy(this))
.proxy(proxy)
.build()
fun stop() {
@@ -263,6 +264,8 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
}.toMutableList())
exception.put(galleryID, reader.galleryInfo.map { null }.toMutableList())
Log.i("PUPILD", "READER HERE!")
if (notification[galleryID] == null)
initNotification(galleryID)

View File

@@ -16,6 +16,10 @@
package xyz.quaver
import java.net.Proxy
var proxy = Proxy.NO_PROXY
fun availableInHiyobi(galleryID: Int) : Boolean {
return try {
xyz.quaver.hiyobi.getReader(galleryID)

View File

@@ -18,6 +18,7 @@ package xyz.quaver.hitomi
import kotlinx.serialization.json.Json
import kotlinx.serialization.list
import xyz.quaver.proxy
import java.net.URL
const val protocol = "https:"
@@ -27,7 +28,9 @@ fun getGalleryInfo(galleryID: Int) =
Json.nonstrict.parse(
GalleryInfo.serializer().list,
Regex("""\[.+]""").find(
URL("$protocol//$domain/galleries/$galleryID.js").readText()
URL("$protocol//$domain/galleries/$galleryID.js").openConnection(proxy).getInputStream().use {
it.reader().readText()
}
)?.value ?: "[]"
)

View File

@@ -18,6 +18,7 @@ package xyz.quaver.hitomi
import kotlinx.serialization.Serializable
import org.jsoup.Jsoup
import xyz.quaver.proxy
import java.net.URLDecoder
@Serializable
@@ -36,7 +37,7 @@ data class Gallery(
val thumbnails: List<String>
)
fun getGallery(galleryID: Int) : Gallery {
val url = Jsoup.connect("https://hitomi.la/galleries/$galleryID.html").get()
val url = Jsoup.connect("https://hitomi.la/galleries/$galleryID.html").proxy(proxy).get()
.select("a").attr("href")
val doc = Jsoup.connect(url).get()

View File

@@ -19,6 +19,7 @@ package xyz.quaver.hitomi
import kotlinx.serialization.Serializable
import org.jsoup.Jsoup
import xyz.quaver.Code
import xyz.quaver.proxy
import java.net.URL
import java.net.URLDecoder
import java.nio.ByteBuffer
@@ -78,7 +79,7 @@ data class GalleryBlock(
fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
val url = "$protocol//$domain/$galleryblockdir/$galleryID$extension"
val doc = Jsoup.connect(url).get()
val doc = Jsoup.connect(url).proxy(proxy).get()
val galleryUrl = doc.selectFirst(".lillie").attr("href")

View File

@@ -19,6 +19,7 @@ package xyz.quaver.hitomi
import kotlinx.serialization.Serializable
import org.jsoup.Jsoup
import xyz.quaver.Code
import xyz.quaver.proxy
fun getReferer(galleryID: Int) = "https://hitomi.la/reader/$galleryID.html"
@@ -38,7 +39,7 @@ data class Reader(val code: Code, val title: String, val galleryInfo: List<Galle
fun getReader(galleryID: Int) : Reader {
val readerUrl = "https://hitomi.la/reader/$galleryID.html"
val doc = Jsoup.connect(readerUrl).get()
val doc = Jsoup.connect(readerUrl).proxy(proxy).get()
return Reader(Code.HITOMI, doc.title(), getGalleryInfo(galleryID))
}

View File

@@ -16,6 +16,7 @@
package xyz.quaver.hitomi
import xyz.quaver.proxy
import java.net.URL
import java.nio.ByteBuffer
import java.nio.ByteOrder
@@ -49,8 +50,9 @@ fun sanitize(input: String) : String {
fun getIndexVersion(name: String) : String {
return try {
URL("$protocol//$domain/$name/version?_=${System.currentTimeMillis()}")
.readText()
URL("$protocol//$domain/$name/version?_=${System.currentTimeMillis()}").openConnection(proxy).getInputStream().use {
it.reader().readText()
}
} catch (e: Exception) {
""
}
@@ -167,13 +169,16 @@ fun getSuggestionsFromData(field: String, data: Pair<Long, Int>) : List<Suggesti
}
fun getGalleryIDsFromNozomi(area: String?, tag: String, language: String) : List<Int> {
print("PUPILD: NOZOMI REQUEST: $area:$tag ($language)")
val nozomiAddress =
when(area) {
null -> "$protocol//$domain/$compressed_nozomi_prefix/$tag-$language$nozomiextension"
else -> "$protocol//$domain/$compressed_nozomi_prefix/$area/$tag-$language$nozomiextension"
}
val bytes = URL(nozomiAddress).readBytes()
val bytes = URL(nozomiAddress).openConnection(proxy).getInputStream().use {
it.readBytes()
}
val nozomi = ArrayList<Int>()
@@ -184,6 +189,7 @@ fun getGalleryIDsFromNozomi(area: String?, tag: String, language: String) : List
while (arrayBuffer.hasRemaining())
nozomi.add(arrayBuffer.int)
print("PUPILD: NOZOMI REQUEST END: $area:$tag ($language)")
return nozomi
}
@@ -238,7 +244,7 @@ fun getNodeAtAddress(field: String, address: Long) : Node? {
fun getURLAtRange(url: String, range: LongRange) : ByteArray? {
try {
with (URL(url).openConnection() as HttpsURLConnection) {
with (URL(url).openConnection(proxy) as HttpsURLConnection) {
requestMethod = "GET"
setRequestProperty("Range", "bytes=${range.first}-${range.last}")

View File

@@ -20,11 +20,12 @@ import org.jsoup.Jsoup
import xyz.quaver.Code
import xyz.quaver.hitomi.GalleryBlock
import xyz.quaver.hitomi.protocol
import xyz.quaver.proxy
fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
val url = "$protocol//$hiyobi/info/$galleryID"
val doc = Jsoup.connect(url).get()
val doc = Jsoup.connect(url).proxy(proxy).get()
val galleryBlock = doc.selectFirst(".gallery-content")

View File

@@ -23,6 +23,7 @@ import xyz.quaver.Code
import xyz.quaver.hitomi.GalleryInfo
import xyz.quaver.hitomi.Reader
import xyz.quaver.hitomi.protocol
import xyz.quaver.proxy
import java.net.URL
import javax.net.ssl.HttpsURLConnection
@@ -47,7 +48,7 @@ fun renewCookie() : String {
val url = "https://$hiyobi/"
try {
with(URL(url).openConnection() as HttpsURLConnection) {
with(URL(url).openConnection(proxy) as HttpsURLConnection) {
setRequestProperty("User-Agent", user_agent)
connectTimeout = 2000
connect()
@@ -62,12 +63,12 @@ fun getReader(galleryID: Int) : Reader {
val reader = "https://$hiyobi/reader/$galleryID"
val url = "https://$hiyobi/data/json/${galleryID}_list.json"
val title = Jsoup.connect(reader).get().title()
val title = Jsoup.connect(reader).proxy(proxy).get().title()
@Suppress("EXPERIMENTAL_API_USAGE")
val galleryInfo = Json.parse(
GalleryInfo.serializer().list,
with(URL(url).openConnection() as HttpsURLConnection) {
with(URL(url).openConnection(proxy) as HttpsURLConnection) {
setRequestProperty("User-Agent", user_agent)
setRequestProperty("Cookie", cookie)
connectTimeout = 2000