diff --git a/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt b/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt index 0bc0a90da..f8582cd88 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/animesource/LocalAnimeSource.kt @@ -7,7 +7,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.animesource.model.* import eu.kanade.tachiyomi.util.episode.EpisodeRecognition import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder -import eu.kanade.tachiyomi.util.storage.AnimeFile import eu.kanade.tachiyomi.util.storage.DiskUtil import eu.kanade.tachiyomi.util.system.ImageUtil import rx.Observable @@ -25,7 +24,7 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { const val HELP_URL = "https://tachiyomi.org/help/guides/local-anime/" private const val COVER_NAME = "cover.jpg" - private val SUPPORTED_ARCHIVE_TYPES = setOf("zip", "rar", "cbr", "cbz", "epub") + private val SUPPORTED_FILE_TYPES = setOf("mp4", "m3u8", "mkv") private val LATEST_THRESHOLD = TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS) @@ -48,7 +47,7 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { } private fun getBaseDirectories(context: Context): List { - val c = context.getString(R.string.app_name) + File.separator + "local" + val c = context.getString(R.string.app_name) + File.separator + "localanime" return DiskUtil.getExternalStorages(context).map { File(it.absolutePath, c) } } } @@ -110,12 +109,12 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { val episodes = fetchEpisodeList(this).toBlocking().first() if (episodes.isNotEmpty()) { val episode = episodes.last() - val format = getFormat(episode) + /*val format = getFormat(episode) if (format is Format.Anime) { AnimeFile(format.file).use { epub -> epub.fillAnimeMetadata(this) } - } + }*/ // Copy the cover from the first episode found. if (thumbnail_url == null) { @@ -160,12 +159,12 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { override fun fetchEpisodeList(anime: SAnime): Observable> { val episodes = getBaseDirectories(context) .asSequence() - .mapNotNull { File(it, anime.url).listFiles()?.toList() } + .mapNotNull { file -> File(file, anime.url).listFiles()?.filter { isSupportedFile(it.extension) } } .flatten() .filter { it.isDirectory || isSupportedFile(it.extension) } .map { episodeFile -> SEpisode.create().apply { - url = "${anime.url}/${episodeFile.name}" + url = episodeFile.absolutePath name = if (episodeFile.isDirectory) { episodeFile.name } else { @@ -173,12 +172,12 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { } date_upload = episodeFile.lastModified() - val format = getFormat(this) + /*val format = getFormat(this) if (format is Format.Anime) { AnimeFile(format.file).use { epub -> epub.fillEpisodeMetadata(this) } - } + }*/ val chapNameCut = stripAnimeTitle(name, anime.title) if (chapNameCut.isNotEmpty()) name = chapNameCut @@ -235,7 +234,7 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { } private fun isSupportedFile(extension: String): Boolean { - return extension.lowercase(Locale.ROOT) in SUPPORTED_ARCHIVE_TYPES + return extension.lowercase(Locale.ROOT) in SUPPORTED_FILE_TYPES } fun getFormat(episode: SEpisode): Format { @@ -258,7 +257,7 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { Format.Zip(file) } else if (extension.equals("rar", true) || extension.equals("cbr", true)) { Format.Rar(file) - } else if (extension.equals("epub", true)) { + } else if (isSupportedFile(extension)) { Format.Anime(file) } else { throw Exception(context.getString(R.string.local_invalid_episode_format)) @@ -293,13 +292,9 @@ class LocalAnimeSource(private val context: Context) : AnimeCatalogueSource { } } is Format.Anime -> { - AnimeFile(format.file).use { epub -> - val entry = epub.getImagesFromPages() - .firstOrNull() - ?.let { epub.getEntry(it) } - - entry?.let { updateCover(context, anime, epub.getInputStream(it)) } - } + if (!anime.thumbnail_url.isNullOrBlank()) { + File(anime.thumbnail_url!!) + } else null } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/DownloadController.kt index 1ede3ef84..6bba84696 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/anime/DownloadController.kt @@ -259,6 +259,7 @@ class DownloadController : */ private fun onUpdateProgress(download: AnimeDownload) { getHolder(download)?.notifyProgress() + getHolder(download)?.notifyDownloadedPages() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/EpisodeLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/EpisodeLoader.kt index 58e0dba2a..467403a94 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/EpisodeLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/EpisodeLoader.kt @@ -26,7 +26,7 @@ class EpisodeLoader { return when { isDownloaded -> mutableListOf(downloaded(episode, anime, source, downloadManager)) source is AnimeHttpSource -> notDownloaded(episode, anime, source) - source is LocalAnimeSource -> mutableListOf(Link("path", "local")) + source is LocalAnimeSource -> mutableListOf(local(episode, source)) else -> error("no worky") } } @@ -81,5 +81,21 @@ class EpisodeLoader { } return Link(path.toString(), "download") } + + fun local( + episode: Episode, + source: AnimeSource + ): Link { + val link = runBlocking { + return@runBlocking suspendCoroutine { continuation -> + launchIO { + val link = + source.fetchEpisodeLink(episode).awaitSingle().first() + continuation.resume(link) + } + } + } + return link + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/WatcherActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/WatcherActivity.kt index 844723039..672ec1bab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/WatcherActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/watcher/WatcherActivity.kt @@ -29,6 +29,7 @@ import com.google.android.exoplayer2.util.Util import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.animesource.AnimeSource import eu.kanade.tachiyomi.animesource.AnimeSourceManager +import eu.kanade.tachiyomi.animesource.LocalAnimeSource import eu.kanade.tachiyomi.animesource.model.Link import eu.kanade.tachiyomi.data.database.AnimeDatabaseHelper import eu.kanade.tachiyomi.data.database.models.Anime @@ -132,7 +133,7 @@ class WatcherActivity : AppCompatActivity() { links = EpisodeLoader.getLinks(episode, anime, source) if (links.lastIndex > 0) settingsBtn.visibility = View.VISIBLE uri = links.first().url - if (EpisodeLoader.isDownloaded(episode, anime)) { + if (EpisodeLoader.isDownloaded(episode, anime) || source is LocalAnimeSource) { dataSourceFactory = DefaultDataSourceFactory(this) } else { dataSourceFactory = DefaultHttpDataSource.Factory().apply {