Merge branch 'master' of https://github.com/inorichi/tachiyomi
# Conflicts: # README.md # app/build.gradle # app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt # app/src/main/java/eu/kanade/tachiyomi/data/source/SourceManager.kt # app/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt # app/src/main/java/eu/kanade/tachiyomi/ui/backup/BackupPresenter.kt # app/src/main/java/eu/kanade/tachiyomi/ui/main/ChangelogDialogFragment.kt # app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt # app/src/main/res/raw/changelog_release.xml # app/src/main/res/values/arrays.xml # app/src/main/res/values/strings.xml
This commit is contained in:
@@ -1,5 +1,17 @@
|
||||
package exh
|
||||
|
||||
/**
|
||||
* Created by nulldev on 2/28/17.
|
||||
* Source helpers
|
||||
*/
|
||||
|
||||
val LEWD_SOURCE_SERIES = 6900L
|
||||
val EH_SOURCE_ID = LEWD_SOURCE_SERIES + 1
|
||||
val EXH_SOURCE_ID = LEWD_SOURCE_SERIES + 2
|
||||
val EH_METADATA_SOURCE_ID = LEWD_SOURCE_SERIES + 3
|
||||
val EXH_METADATA_SOURCE_ID = LEWD_SOURCE_SERIES + 4
|
||||
|
||||
fun isLewdSource(source: Long) = source >= 6900
|
||||
&& source <= 6999
|
||||
|
||||
fun isExSource(source: Long) = source == EXH_SOURCE_ID
|
||||
|| source == EXH_METADATA_SOURCE_ID
|
||||
|
||||
@@ -2,14 +2,15 @@ package exh
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.UrlUtil
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.syncChaptersWithSource
|
||||
import exh.metadata.MetadataHelper
|
||||
import exh.metadata.copyTo
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URI
|
||||
import java.net.URISyntaxException
|
||||
import java.net.URL
|
||||
|
||||
class GalleryAdder {
|
||||
@@ -22,19 +23,20 @@ class GalleryAdder {
|
||||
|
||||
fun addGallery(url: String, fav: Boolean = false): Manga {
|
||||
val source = when(URL(url).host) {
|
||||
"g.e-hentai.org", "e-hentai.org" -> 1
|
||||
"exhentai.org" -> 2
|
||||
"g.e-hentai.org", "e-hentai.org" -> EH_SOURCE_ID
|
||||
"exhentai.org" -> EXH_SOURCE_ID
|
||||
else -> throw MalformedURLException("Not a valid gallery URL!")
|
||||
}
|
||||
|
||||
val sourceObj = sourceManager.get(source)
|
||||
?: throw IllegalStateException("Could not find EH source!")
|
||||
|
||||
val pathOnlyUrl = UrlUtil.getPath(url)
|
||||
val pathOnlyUrl = getUrlWithoutDomain(url)
|
||||
|
||||
//Use manga in DB if possible, otherwise, make a new manga
|
||||
val manga = db.getManga(pathOnlyUrl, source).executeAsBlocking()
|
||||
?: Manga.create(pathOnlyUrl, source).apply {
|
||||
?: Manga.create(source).apply {
|
||||
this.url = pathOnlyUrl
|
||||
title = url
|
||||
}
|
||||
|
||||
@@ -42,7 +44,7 @@ class GalleryAdder {
|
||||
manga.copyFrom(sourceObj.fetchMangaDetails(manga).toBlocking().first())
|
||||
|
||||
//Apply metadata
|
||||
metadataHelper.fetchMetadata(url, source == 2)?.copyTo(manga)
|
||||
metadataHelper.fetchMetadata(url, isExSource(source))?.copyTo(manga)
|
||||
|
||||
if(fav) manga.favorite = true
|
||||
|
||||
@@ -61,4 +63,18 @@ class GalleryAdder {
|
||||
|
||||
return manga
|
||||
}
|
||||
|
||||
private fun getUrlWithoutDomain(orig: String): String {
|
||||
try {
|
||||
val uri = URI(orig)
|
||||
var out = uri.path
|
||||
if (uri.query != null)
|
||||
out += "?" + uri.query
|
||||
if (uri.fragment != null)
|
||||
out += "#" + uri.fragment
|
||||
return out
|
||||
} catch (e: URISyntaxException) {
|
||||
return orig
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package exh.metadata
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.UrlUtil
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import exh.metadata.models.ExGalleryMetadata
|
||||
import exh.metadata.models.Tag
|
||||
import exh.plusAssign
|
||||
@@ -28,16 +27,18 @@ val EX_DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US)
|
||||
|
||||
private val prefs: PreferencesHelper by injectLazy()
|
||||
|
||||
fun ExGalleryMetadata.copyTo(manga: Manga) {
|
||||
exh?.let {
|
||||
fun ExGalleryMetadata.copyTo(manga: SManga) {
|
||||
//TODO Find some way to do this with SManga
|
||||
/*exh?.let {
|
||||
manga.source = if(it)
|
||||
2
|
||||
else
|
||||
1
|
||||
}
|
||||
}*/
|
||||
url?.let { manga.url = it }
|
||||
thumbnailUrl?.let { manga.thumbnail_url = it }
|
||||
|
||||
//No title bug?
|
||||
val titleObj = if(prefs.useJapaneseTitle().getOrDefault())
|
||||
altTitle ?: title
|
||||
else
|
||||
@@ -57,12 +58,12 @@ fun ExGalleryMetadata.copyTo(manga: Manga) {
|
||||
|
||||
//Try to automatically identify if it is ongoing, we try not to be too lenient here to avoid making mistakes
|
||||
//We default to completed
|
||||
manga.status = Manga.COMPLETED
|
||||
manga.status = SManga.COMPLETED
|
||||
title?.let { t ->
|
||||
ONGOING_SUFFIX.find {
|
||||
t.endsWith(it, ignoreCase = true)
|
||||
}?.let {
|
||||
manga.status = Manga.ONGOING
|
||||
manga.status = SManga.ONGOING
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.source.SourceManager
|
||||
import eu.kanade.tachiyomi.data.source.online.all.EHentai
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.online.all.EHentai
|
||||
import exh.isExSource
|
||||
import exh.metadata.MetadataHelper
|
||||
import exh.metadata.copyTo
|
||||
import timber.log.Timber
|
||||
@@ -44,7 +45,7 @@ class MetadataFetchDialog {
|
||||
.executeAsBlocking()
|
||||
.filter {
|
||||
it.source <= 2
|
||||
&& !metadataHelper.hasMetadata(it.url, it.source == 2)
|
||||
&& !metadataHelper.hasMetadata(it.url, isExSource(it.source))
|
||||
}
|
||||
|
||||
context.runOnUiThread {
|
||||
@@ -91,7 +92,7 @@ class MetadataFetchDialog {
|
||||
db.getLibraryMangas().asRxSingle().subscribe {
|
||||
//Not logged in but have ExHentai galleries
|
||||
if(!preferenceHelper.enableExhentai().getOrDefault()) {
|
||||
it.find { it.source == 2 }?.let {
|
||||
it.find { isExSource(it.source) }?.let {
|
||||
extra = "<b><font color='red'>If you use ExHentai, please log in first before fetching your library metadata!</font></b><br><br>"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ class MigrationCompletionActivity : BaseActivity() {
|
||||
//Migrate urls
|
||||
UrlMigrator().perform()
|
||||
|
||||
//Migrate source IDs
|
||||
SourceMigrator().perform()
|
||||
|
||||
//Go back to MainActivity
|
||||
//Set final steps
|
||||
preferenceManager.migrationStatus().set(MigrationStatus.FINALIZE_MIGRATION)
|
||||
|
||||
@@ -1,5 +1,74 @@
|
||||
package exh.ui.migration
|
||||
|
||||
/**
|
||||
* Created by nulldev on 2/28/17.
|
||||
*/
|
||||
import android.app.Activity
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import eu.kanade.tachiyomi.data.backup.BackupManager
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import exh.LEWD_SOURCE_SERIES
|
||||
import timber.log.Timber
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.File
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class SourceMigrator {
|
||||
|
||||
val db: DatabaseHelper by injectLazy()
|
||||
|
||||
val prefs: PreferencesHelper by injectLazy()
|
||||
|
||||
val backupManager by lazy {
|
||||
BackupManager(db)
|
||||
}
|
||||
|
||||
fun perform() {
|
||||
db.insertMangas(db.getMangas().executeAsBlocking().map {
|
||||
if(it.source < 100) {
|
||||
if(it.url.trim('/').startsWith("g/")) {
|
||||
//EH source, move ID
|
||||
it.source += LEWD_SOURCE_SERIES
|
||||
}
|
||||
} else if(it.source < 200) {
|
||||
//Regular source, move ID down
|
||||
it.source -= 100
|
||||
}
|
||||
it
|
||||
}).executeAsBlocking()
|
||||
}
|
||||
|
||||
fun tryMigrationWithDialog(context: Activity, callback: () -> Unit) {
|
||||
if(!prefs.hasPerformedSourceMigration().getOrDefault()) {
|
||||
val dialog = MaterialDialog.Builder(context)
|
||||
.title("Migrating galleries")
|
||||
.progress(true, 0)
|
||||
.cancelable(false)
|
||||
.show()
|
||||
|
||||
thread {
|
||||
try {
|
||||
context.runOnUiThread {
|
||||
dialog.setContent("Backing up library...")
|
||||
}
|
||||
backupManager.backupToFile(File(context.filesDir, "teh-source-migration-bck.json"))
|
||||
context.runOnUiThread {
|
||||
dialog.setContent("Performing migration...")
|
||||
}
|
||||
perform()
|
||||
context.runOnUiThread {
|
||||
dialog.setContent("Completing migration...")
|
||||
}
|
||||
prefs.hasPerformedSourceMigration().set(true)
|
||||
dialog.dismiss()
|
||||
} catch(e: Exception) {
|
||||
Timber.e(e, "Error migrating source IDs!")
|
||||
}
|
||||
context.runOnUiThread {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import exh.isExSource
|
||||
import exh.isLewdSource
|
||||
import exh.metadata.MetadataHelper
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
@@ -21,8 +23,7 @@ class UrlMigrator {
|
||||
|
||||
//Find all EX mangas
|
||||
val qualifyingMangas = dbMangas.asSequence().filter {
|
||||
it.source > 0
|
||||
&& it.source <= 4
|
||||
isLewdSource(it.source)
|
||||
}
|
||||
|
||||
val possibleDups = mutableListOf<Manga>()
|
||||
@@ -42,8 +43,7 @@ class UrlMigrator {
|
||||
//Build fixed URL
|
||||
val urlWithSlash = "/" + it.url
|
||||
//Fix metadata if required
|
||||
val metadata = metadataHelper.fetchMetadata(it.url, it.source == 2
|
||||
|| it.source == 4)
|
||||
val metadata = metadataHelper.fetchMetadata(it.url, isExSource(it.source))
|
||||
metadata?.url?.let {
|
||||
if(it.startsWith("g/")) { //Check if metadata URL has no slash
|
||||
metadata.url = urlWithSlash //Fix it
|
||||
|
||||
Reference in New Issue
Block a user