feat: custom downloader and downloader location (#313)

* feat: custom downloader (novel broken)

* fix: send headers to ffmpeg

ffmpeg can be a real bitch to work with

* fix: offline page for new download system

* feat: novel to new system | load freezing

* chore: clean manifest

* fix: notification incrementing

* feat: changing the downloads dir
This commit is contained in:
rebel onion 2024-04-04 04:03:45 -05:00 committed by GitHub
parent 75e90541c9
commit 720b40afa7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 1162 additions and 1018 deletions

View file

@ -1,9 +1,12 @@
package ani.dantotsu.parsers
import android.app.Application
import android.net.Uri
import android.os.Environment
import ani.dantotsu.currContext
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory
import ani.dantotsu.download.anime.AnimeDownloaderService.AnimeDownloadTask.Companion.getTaskName
import ani.dantotsu.media.MediaType
import ani.dantotsu.media.MediaNameAdapter
import ani.dantotsu.tryWithSuspend
@ -18,6 +21,7 @@ import java.util.Locale
class OfflineAnimeParser : AnimeParser() {
private val downloadManager = Injekt.get<DownloadsManager>()
private val context = Injekt.get<Application>()
override val name = "Offline"
override val saveName = "Offline"
@ -29,22 +33,19 @@ class OfflineAnimeParser : AnimeParser() {
extra: Map<String, String>?,
sAnime: SAnime
): List<Episode> {
val directory = File(
currContext()?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"${DownloadsManager.animeLocation}/$animeLink"
)
val directory = getSubDirectory(context, MediaType.ANIME, false, animeLink)
//get all of the folder names and add them to the list
val episodes = mutableListOf<Episode>()
if (directory.exists()) {
directory.listFiles()?.forEach {
if (directory?.exists() == true) {
directory.listFiles().forEach {
//put the title and episdode number in the extra data
val extraData = mutableMapOf<String, String>()
extraData["title"] = animeLink
extraData["episode"] = it.name
extraData["episode"] = it.name!!
if (it.isDirectory) {
val episode = Episode(
it.name,
"$animeLink - ${it.name}",
it.name!!,
getTaskName(animeLink,it.name!!),
it.name,
null,
null,
@ -131,18 +132,19 @@ class OfflineVideoExtractor(val videoServer: VideoServer) : VideoExtractor() {
private fun getSubtitle(title: String, episode: String): List<Subtitle>? {
currContext()?.let {
DownloadsManager.getDirectory(
DownloadsManager.getSubDirectory(
it,
MediaType.ANIME,
false,
title,
episode
).listFiles()?.forEach { file ->
if (file.name.contains("subtitle")) {
)?.listFiles()?.forEach { file ->
if (file.name?.contains("subtitle") == true) {
return listOf(
Subtitle(
"Downloaded Subtitle",
Uri.fromFile(file).toString(),
determineSubtitletype(file.absolutePath)
file.uri.toString(),
determineSubtitletype(file.name ?: "")
)
)
}

View file

@ -1,9 +1,12 @@
package ani.dantotsu.parsers
import android.app.Application
import android.os.Environment
import ani.dantotsu.currContext
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory
import ani.dantotsu.media.MediaNameAdapter
import ani.dantotsu.media.MediaType
import ani.dantotsu.util.Logger
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
@ -14,6 +17,7 @@ import java.io.File
class OfflineMangaParser : MangaParser() {
private val downloadManager = Injekt.get<DownloadsManager>()
private val context = Injekt.get<Application>()
override val hostUrl: String = "Offline"
override val name: String = "Offline"
@ -23,17 +27,14 @@ class OfflineMangaParser : MangaParser() {
extra: Map<String, String>?,
sManga: SManga
): List<MangaChapter> {
val directory = File(
currContext()?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"Dantotsu/Manga/$mangaLink"
)
val directory = getSubDirectory(context, MediaType.MANGA, false, mangaLink)
//get all of the folder names and add them to the list
val chapters = mutableListOf<MangaChapter>()
if (directory.exists()) {
directory.listFiles()?.forEach {
if (directory?.exists() == true) {
directory.listFiles().forEach {
if (it.isDirectory) {
val chapter = MangaChapter(
it.name,
it.name!!,
"$mangaLink/${it.name}",
it.name,
null,
@ -50,16 +51,15 @@ class OfflineMangaParser : MangaParser() {
}
override suspend fun loadImages(chapterLink: String, sChapter: SChapter): List<MangaImage> {
val directory = File(
currContext()?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"Dantotsu/Manga/$chapterLink"
)
val title = chapterLink.split("/").first()
val chapter = chapterLink.split("/").last()
val directory = getSubDirectory(context, MediaType.MANGA, false, title, chapter)
val images = mutableListOf<MangaImage>()
val imageNumberRegex = Regex("""(\d+)\.jpg$""")
if (directory.exists()) {
directory.listFiles()?.forEach {
if (directory?.exists() == true) {
directory.listFiles().forEach {
if (it.isFile) {
val image = MangaImage(it.absolutePath, false, null)
val image = MangaImage(it.uri.toString(), false, null)
images.add(image)
}
}

View file

@ -1,9 +1,12 @@
package ani.dantotsu.parsers
import android.app.Application
import android.os.Environment
import ani.dantotsu.currContext
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory
import ani.dantotsu.media.MediaNameAdapter
import ani.dantotsu.media.MediaType
import me.xdrop.fuzzywuzzy.FuzzySearch
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -11,6 +14,7 @@ import java.io.File
class OfflineNovelParser : NovelParser() {
private val downloadManager = Injekt.get<DownloadsManager>()
private val context = Injekt.get<Application>()
override val hostUrl: String = "Offline"
override val name: String = "Offline"
@ -21,19 +25,16 @@ class OfflineNovelParser : NovelParser() {
override suspend fun loadBook(link: String, extra: Map<String, String>?): Book {
//link should be a directory
val directory = File(
currContext()?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"Dantotsu/Novel/$link"
)
val directory = getSubDirectory(context, MediaType.NOVEL, false, link)
val chapters = mutableListOf<Book>()
if (directory.exists()) {
directory.listFiles()?.forEach {
if (directory?.exists() == true) {
directory.listFiles().forEach {
if (it.isDirectory) {
val chapter = Book(
it.name,
it.absolutePath + "/cover.jpg",
it.name?:"Unknown",
it.uri.toString(),
null,
listOf(it.absolutePath + "/0.epub")
listOf(it.uri.toString())
)
chapters.add(chapter)
}
@ -60,20 +61,16 @@ class OfflineNovelParser : NovelParser() {
val returnList: MutableList<ShowResponse> = mutableListOf()
for (title in returnTitles) {
//need to search the subdirectories for the ShowResponses
val directory = File(
currContext()?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS),
"Dantotsu/Novel/$title"
)
val directory = getSubDirectory(context, MediaType.NOVEL, false, title)
val names = mutableListOf<String>()
if (directory.exists()) {
directory.listFiles()?.forEach {
if (directory?.exists() == true) {
directory.listFiles().forEach {
if (it.isDirectory) {
names.add(it.name)
names.add(it.name?: "Unknown")
}
}
}
val cover =
currContext()?.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS)?.absolutePath + "/Dantotsu/Novel/$title/cover.jpg"
val cover = directory?.findFile("cover.jpg")?.uri.toString()
names.forEach {
returnList.add(ShowResponse(it, it, cover))
}