fix: allow deprecated media to be played

This commit is contained in:
rebelonion 2024-04-21 02:58:17 -05:00
parent 3c46c21a25
commit 3622d91886
12 changed files with 647 additions and 103 deletions

View file

@ -55,8 +55,8 @@ class SubtitleDownloader {
context,
downloadedType.type,
false,
downloadedType.title,
downloadedType.chapter
downloadedType.titleName,
downloadedType.chapterName
) ?: throw Exception("Could not create directory")
val type = loadSubtitleType(url)
directory.findFile("subtitle.${type}")?.delete()

View file

@ -553,8 +553,8 @@ class AnimeWatchFragment : Fragment() {
episodeAdapter.updateType(style ?: PrefManager.getVal(PrefName.AnimeDefaultView))
episodeAdapter.notifyItemRangeInserted(0, arr.size)
for (download in downloadManager.animeDownloadedTypes) {
if (media.compareName(download.title)) {
episodeAdapter.stopDownload(download.chapter)
if (media.compareName(download.titleName)) {
episodeAdapter.stopDownload(download.chapterName)
}
}
}

View file

@ -111,6 +111,7 @@ import ani.dantotsu.connections.updateProgress
import ani.dantotsu.databinding.ActivityExoplayerBinding
import ani.dantotsu.defaultHeaders
import ani.dantotsu.download.DownloadsManager.Companion.getSubDirectory
import ani.dantotsu.download.video.Helper
import ani.dantotsu.dp
import ani.dantotsu.getCurrentBrightnessValue
import ani.dantotsu.hideSystemBars
@ -1481,26 +1482,38 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL
val downloadedMediaItem = if (ext.server.offline) {
val titleName = ext.server.name.split("/").first()
val episodeName = ext.server.name.split("/").last()
downloadId = PrefManager.getAnimeDownloadPreferences()
.getString("$titleName - $episodeName", null) ?:
PrefManager.getAnimeDownloadPreferences()
.getString(ext.server.name, null)
val exoItem = if (downloadId != null) {
Helper.downloadManager(this)
.downloadIndex.getDownload(downloadId!!)?.request?.toMediaItem()
} else null
if (exoItem != null) {
exoItem
} else {
val directory = getSubDirectory(this, MediaType.ANIME, false, titleName, episodeName)
if (directory != null) {
val files = directory.listFiles()
println(files)
val docFile = directory.listFiles().firstOrNull {
it.name?.endsWith(".mp4") == true || it.name?.endsWith(".mkv") == true
}
if (docFile != null) {
val uri = docFile.uri
MediaItem.Builder().setUri(uri).setMimeType(mimeType).build()
val directory =
getSubDirectory(this, MediaType.ANIME, false, titleName, episodeName)
if (directory != null) {
val files = directory.listFiles()
println(files)
val docFile = directory.listFiles().firstOrNull {
it.name?.endsWith(".mp4") == true || it.name?.endsWith(".mkv") == true
}
if (docFile != null) {
val uri = docFile.uri
MediaItem.Builder().setUri(uri).setMimeType(mimeType).build()
} else {
snackString("File not found")
null
}
} else {
snackString("File not found")
snackString("Directory not found")
null
}
} else {
snackString("Directory not found")
null
}
} else null
mediaItem = if (downloadedMediaItem == null) {

View file

@ -194,8 +194,8 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
)
for (download in downloadManager.mangaDownloadedTypes) {
if (media.compareName(download.title)) {
chapterAdapter.stopDownload(download.chapter)
if (media.compareName(download.titleName)) {
chapterAdapter.stopDownload(download.chapterName)
}
}