extension settings

This commit is contained in:
Finnley Somdahl 2023-10-29 19:45:11 -05:00
parent 9c0ef7a788
commit 3368a1bc8d
76 changed files with 2320 additions and 131 deletions

View file

@ -0,0 +1,98 @@
package tachiyomi.source.local.entries.anime
import android.content.Context
import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
import eu.kanade.tachiyomi.animesource.AnimeSource
import eu.kanade.tachiyomi.animesource.UnmeteredSource
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
import eu.kanade.tachiyomi.animesource.model.AnimesPage
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
import eu.kanade.tachiyomi.util.storage.DiskUtil
//import eu.kanade.tachiyomi.util.storage.toFFmpegString
import kotlinx.serialization.json.Json
import rx.Observable
import tachiyomi.core.util.lang.withIOContext
import tachiyomi.domain.entries.anime.model.Anime
import tachiyomi.source.local.filter.anime.AnimeOrderBy
import uy.kohesive.injekt.injectLazy
import java.io.File
import java.util.concurrent.TimeUnit
class LocalAnimeSource(
private val context: Context,
) : AnimeCatalogueSource, UnmeteredSource {
private val POPULAR_FILTERS = AnimeFilterList(AnimeOrderBy.Popular(context))
private val LATEST_FILTERS = AnimeFilterList(AnimeOrderBy.Latest(context))
override val name ="Local anime source"
override val id: Long = ID
override val lang = "other"
override fun toString() = name
override val supportsLatest = true
// Browse related
override fun fetchPopularAnime(page: Int) = fetchSearchAnime(page, "", POPULAR_FILTERS)
override fun fetchLatestUpdates(page: Int) = fetchSearchAnime(page, "", LATEST_FILTERS)
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
//return emptyObservable()
return Observable.just(AnimesPage(emptyList(), false))
}
// Anime details related
override suspend fun getAnimeDetails(anime: SAnime): SAnime = withIOContext {
//return empty
anime
}
// Episodes
override suspend fun getEpisodeList(anime: SAnime): List<SEpisode> {
//return empty
return emptyList()
}
// Filters
override fun getFilterList() = AnimeFilterList(AnimeOrderBy.Popular(context))
// Unused stuff
override suspend fun getVideoList(episode: SEpisode) = throw UnsupportedOperationException("Unused")
companion object {
const val ID = 0L
const val HELP_URL = "https://aniyomi.org/help/guides/local-anime/"
private const val DEFAULT_COVER_NAME = "cover.jpg"
private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS)
private fun getBaseDirectories(context: Context): Sequence<File> {
val localFolder = "Aniyomi" + File.separator + "localanime"
return DiskUtil.getExternalStorages(context)
.map { File(it.absolutePath, localFolder) }
.asSequence()
}
private fun getBaseDirectoriesFiles(context: Context): Sequence<File> {
return getBaseDirectories(context)
// Get all the files inside all baseDir
.flatMap { it.listFiles().orEmpty().toList() }
}
private fun getAnimeDir(animeUrl: String, baseDirsFile: Sequence<File>): File? {
return baseDirsFile
// Get the first animeDir or null
.firstOrNull { it.isDirectory && it.name == animeUrl }
}
}
}
fun Anime.isLocal(): Boolean = source == LocalAnimeSource.ID
fun AnimeSource.isLocal(): Boolean = id == LocalAnimeSource.ID

View file

@ -0,0 +1,70 @@
package tachiyomi.source.local.entries.manga
import android.content.Context
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.MangaSource
import eu.kanade.tachiyomi.source.UnmeteredSource
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import rx.Observable
import tachiyomi.core.util.lang.withIOContext
import tachiyomi.domain.entries.manga.model.Manga
import tachiyomi.source.local.filter.manga.MangaOrderBy
import java.util.concurrent.TimeUnit
class LocalMangaSource(
private val context: Context,
) : CatalogueSource, UnmeteredSource {
private val POPULAR_FILTERS = FilterList(MangaOrderBy.Popular(context))
private val LATEST_FILTERS = FilterList(MangaOrderBy.Latest(context))
override val name: String = "Local manga source"
override val id: Long = ID
override val lang: String = "other"
override fun toString() = name
override val supportsLatest: Boolean = true
// Browse related
override fun fetchPopularManga(page: Int) = fetchSearchManga(page, "", POPULAR_FILTERS)
override fun fetchLatestUpdates(page: Int) = fetchSearchManga(page, "", LATEST_FILTERS)
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return Observable.just(MangasPage(emptyList(), false))
}
// Manga details related
override suspend fun getMangaDetails(manga: SManga): SManga = withIOContext {
manga
}
// Chapters
override suspend fun getChapterList(manga: SManga): List<SChapter> {
return emptyList()
}
// Filters
override fun getFilterList() = FilterList(MangaOrderBy.Popular(context))
// Unused stuff
override suspend fun getPageList(chapter: SChapter) = throw UnsupportedOperationException("Unused")
companion object {
const val ID = 0L
const val HELP_URL = "https://aniyomi.org/help/guides/local-manga/"
private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS)
}
}
fun Manga.isLocal(): Boolean = source == LocalMangaSource.ID
fun MangaSource.isLocal(): Boolean = id == LocalMangaSource.ID

View file

@ -0,0 +1,14 @@
package tachiyomi.source.local.filter.anime
import android.content.Context
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
sealed class AnimeOrderBy(context: Context, selection: Selection) : AnimeFilter.Sort(
"Order by",
arrayOf("Title", "Date"),
selection,
) {
class Popular(context: Context) : AnimeOrderBy(context, Selection(0, true))
class Latest(context: Context) : AnimeOrderBy(context, Selection(1, false))
}

View file

@ -0,0 +1,13 @@
package tachiyomi.source.local.filter.manga
import android.content.Context
import eu.kanade.tachiyomi.source.model.Filter
sealed class MangaOrderBy(context: Context, selection: Selection) : Filter.Sort(
"Order by",
arrayOf("Title", "Date"),
selection,
) {
class Popular(context: Context) : MangaOrderBy(context, Selection(0, true))
class Latest(context: Context) : MangaOrderBy(context, Selection(1, false))
}

View file

@ -0,0 +1,21 @@
package tachiyomi.source.local.io
import java.io.File
object ArchiveAnime {
private val SUPPORTED_ARCHIVE_TYPES = listOf("mp4", "mkv")
fun isSupported(file: File): Boolean = with(file) {
return extension.lowercase() in SUPPORTED_ARCHIVE_TYPES
}
}
object ArchiveManga {
private val SUPPORTED_ARCHIVE_TYPES = listOf("zip", "cbz", "rar", "cbr", "epub")
fun isSupported(file: File): Boolean = with(file) {
return extension.lowercase() in SUPPORTED_ARCHIVE_TYPES
}
}