episode test

This commit is contained in:
reduplicated 2022-09-18 13:25:17 +02:00
parent 266a511cd7
commit 63e4e670c0
4 changed files with 205 additions and 152 deletions

View file

@ -18,6 +18,7 @@ import com.lagradost.cloudstream3.ui.download.DownloadClickEvent
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.utils.AppUtils.html import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.UIHelper.setImage import com.lagradost.cloudstream3.utils.UIHelper.setImage
import com.lagradost.fetchbutton.aria2c.UriRequest
import com.lagradost.fetchbutton.aria2c.newUriRequest import com.lagradost.fetchbutton.aria2c.newUriRequest
import kotlinx.android.synthetic.main.result_episode.view.* import kotlinx.android.synthetic.main.result_episode.view.*
import kotlinx.android.synthetic.main.result_episode.view.episode_text import kotlinx.android.synthetic.main.result_episode.view.episode_text
@ -52,7 +53,7 @@ data class EpisodeClickEvent(val action: Int, val data: ResultEpisode)
class EpisodeAdapter( class EpisodeAdapter(
private val hasDownloadSupport: Boolean, private val hasDownloadSupport: Boolean,
private val clickCallback: (EpisodeClickEvent) -> Unit, private val clickCallback: (EpisodeClickEvent) -> Unit,
private val downloadClickCallback: (DownloadClickEvent) -> Unit, private val downloadClickCallback: suspend ResultEpisode.() -> List<UriRequest>,
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { ) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var cardList: MutableList<ResultEpisode> = mutableListOf() private var cardList: MutableList<ResultEpisode> = mutableListOf()
@ -125,7 +126,7 @@ class EpisodeAdapter(
itemView: View, itemView: View,
private val hasDownloadSupport: Boolean, private val hasDownloadSupport: Boolean,
private val clickCallback: (EpisodeClickEvent) -> Unit, private val clickCallback: (EpisodeClickEvent) -> Unit,
private val downloadClickCallback: (DownloadClickEvent) -> Unit, private val downloadClickCallback : suspend ResultEpisode.() -> List<UriRequest>,
) : RecyclerView.ViewHolder(itemView) { ) : RecyclerView.ViewHolder(itemView) {
//override var downloadButton = EasyDownloadButton() //override var downloadButton = EasyDownloadButton()
@ -153,11 +154,7 @@ class EpisodeAdapter(
downloadButton.setPersistentId(card.id.toLong()) downloadButton.setPersistentId(card.id.toLong())
downloadButton.isVisible = hasDownloadSupport downloadButton.isVisible = hasDownloadSupport
downloadButton.setDefaultClickListener { downloadButton.setDefaultClickListener {
listOf( downloadClickCallback.invoke(card)
newUriRequest(
card.id.toLong(), "https://speed.hetzner.de/100MB.bin", "Hello World",
)
)
} }
val name = val name =

View file

@ -36,8 +36,10 @@ import com.lagradost.cloudstream3.syncproviders.providers.Kitsu
import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick import com.lagradost.cloudstream3.ui.download.DownloadButtonSetup.handleDownloadClick
import com.lagradost.cloudstream3.ui.download.DownloadViewModel
import com.lagradost.cloudstream3.ui.download.EasyDownloadButton import com.lagradost.cloudstream3.ui.download.EasyDownloadButton
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
import com.lagradost.cloudstream3.ui.result.ResultViewModel2.Companion.getDownloadRequest
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.*
@ -506,8 +508,9 @@ open class ResultFragment : ResultTrailerPlayer() {
{ episodeClick -> { episodeClick ->
viewModel.handleAction(activity, episodeClick) viewModel.handleAction(activity, episodeClick)
}, },
{ downloadClickEvent -> {
handleDownloadClick(activity, downloadClickEvent) viewModel.getRequest(this)?.links ?: emptyList()
//handleDownloadClick(activity, downloadClickEvent)
} }
) )

View file

@ -28,7 +28,6 @@ import com.lagradost.cloudstream3.syncproviders.SyncAPI
import com.lagradost.cloudstream3.syncproviders.providers.Kitsu import com.lagradost.cloudstream3.syncproviders.providers.Kitsu
import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.WatchType import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
import com.lagradost.cloudstream3.ui.player.GeneratorPlayer import com.lagradost.cloudstream3.ui.player.GeneratorPlayer
import com.lagradost.cloudstream3.ui.player.IGenerator import com.lagradost.cloudstream3.ui.player.IGenerator
import com.lagradost.cloudstream3.ui.player.RepoLinkGenerator import com.lagradost.cloudstream3.ui.player.RepoLinkGenerator
@ -55,6 +54,10 @@ import com.lagradost.cloudstream3.utils.DataStoreHelper.setResultSeason
import com.lagradost.cloudstream3.utils.UIHelper.checkWrite import com.lagradost.cloudstream3.utils.UIHelper.checkWrite
import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream3.utils.UIHelper.requestRW import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
import com.lagradost.fetchbutton.aria2c.Aria2Starter
import com.lagradost.fetchbutton.aria2c.UriRequest
import com.lagradost.fetchbutton.aria2c.newUriRequest
import kotlinx.coroutines.* import kotlinx.coroutines.*
import java.io.File import java.io.File
import java.lang.Math.abs import java.lang.Math.abs
@ -584,8 +587,7 @@ class ResultViewModel2 : ViewModel() {
} }
} }
fun startDownload( fun getDownloadRequest(
context: Context?,
episode: ResultEpisode, episode: ResultEpisode,
currentIsMovie: Boolean, currentIsMovie: Boolean,
currentHeaderName: String, currentHeaderName: String,
@ -596,10 +598,7 @@ class ResultViewModel2 : ViewModel() {
url: String, url: String,
links: List<ExtractorLink>, links: List<ExtractorLink>,
subs: List<SubtitleData>? subs: List<SubtitleData>?
) { ): DownloadRequest? {
try {
if (context == null) return
val meta = val meta =
getMeta( getMeta(
episode, episode,
@ -610,9 +609,11 @@ class ResultViewModel2 : ViewModel() {
currentType currentType
) )
val folder = getFolder(currentType, currentHeaderName) val topFolder = AcraApplication.context?.getBasePath()?.first?.filePath
val src = "$DOWNLOAD_NAVIGATE_TO/$parentId" // url ?: return@let val folder =
topFolder + "/" + getFolder(currentType, currentHeaderName).replace(".", "")
//val src = "$DOWNLOAD_NAVIGATE_TO/$parentId" // url ?: return@let
// SET VISUAL KEYS // SET VISUAL KEYS
AcraApplication.setKey( AcraApplication.setKey(
@ -647,22 +648,20 @@ class ResultViewModel2 : ViewModel() {
System.currentTimeMillis(), System.currentTimeMillis(),
) )
) )
val linkRequests = links.filter { link -> !link.isM3u8 }.map { link ->
// DOWNLOAD VIDEO newUriRequest(
VideoDownloadManager.downloadEpisodeUsingWorker( episode.id.toLong(), link.url,
context, VideoDownloadManager.getDisplayName(
src,//url ?: return, VideoDownloadManager.getFileName(
folder, AcraApplication.context ?: return null,
meta, meta
links ), ".mp4"
), folder, link.headers, USER_AGENT
) )
}
// 1. Checks if the lang should be downloaded
// 2. Makes it into the download format
// 3. Downloads it as a .vtt file
val downloadList = SubtitlesFragment.getDownloadSubsLanguageISO639_1() val downloadList = SubtitlesFragment.getDownloadSubsLanguageISO639_1()
subs?.let { subsList -> val downloadSubsList = (subs ?: emptyList()).filter {
subsList.filter {
downloadList.contains( downloadList.contains(
SubtitleHelper.fromLanguageToTwoLetters( SubtitleHelper.fromLanguageToTwoLetters(
it.name, it.name,
@ -671,18 +670,67 @@ class ResultViewModel2 : ViewModel() {
) )
} }
.map { ExtractorSubtitleLink(it.name, it.url, "") } .map { ExtractorSubtitleLink(it.name, it.url, "") }
.forEach { link -> .map { link ->
val fileName = VideoDownloadManager.getFileName(context, meta) val fileName = VideoDownloadManager.getFileName(
downloadSubtitle(context, link, fileName, folder) AcraApplication.context ?: return null,
} meta
} )
} catch (e: Exception) { newUriRequest(0, link.url, fileName, folder, link.headers, USER_AGENT)
logError(e) //downloadSubtitle(context, link, fileName, folder)
}
} }
return DownloadRequest(linkRequests, downloadSubsList)
// DOWNLOAD VIDEO
//VideoDownloadManager.downloadEpisodeUsingWorker(
// context,
// src,//url ?: return,
// folder,
// meta,
// links
//)
// 1. Checks if the lang should be downloaded
// 2. Makes it into the download format
// 3. Downloads it as a .vtt file
//val downloadList = SubtitlesFragment.getDownloadSubsLanguageISO639_1()
//subs?.let { subsList ->
// subsList.filter {
// downloadList.contains(
// SubtitleHelper.fromLanguageToTwoLetters(
// it.name,
// true
// )
// )
// }
// .map { ExtractorSubtitleLink(it.name, it.url, "") }
// .forEach { link ->
// val fileName = VideoDownloadManager.getFileName(context, meta)
// downloadSubtitle(context, link, fileName, folder)
// }
//}
}
data class DownloadRequest(
val links: List<UriRequest>,
val subs: List<UriRequest>,
)
/*suspend fun download(episode: ResultEpisode): DownloadRequest {
val generator = RepoLinkGenerator(listOf(episode))
val currentLinks = mutableSetOf<ExtractorLink>()
val currentSubs = mutableSetOf<SubtitleData>()
generator.generateLinks(clearCache = false, isCasting = false, callback = {
it.first?.let { link ->
currentLinks.add(link)
}
}, subtitleCallback = { sub ->
currentSubs.add(sub)
})
}*/
suspend fun downloadEpisode( suspend fun downloadEpisode(
activity: Activity?,
episode: ResultEpisode, episode: ResultEpisode,
currentIsMovie: Boolean, currentIsMovie: Boolean,
currentHeaderName: String, currentHeaderName: String,
@ -691,8 +739,7 @@ class ResultViewModel2 : ViewModel() {
apiName: String, apiName: String,
parentId: Int, parentId: Int,
url: String, url: String,
) { ): DownloadRequest? {
ioSafe {
val generator = RepoLinkGenerator(listOf(episode)) val generator = RepoLinkGenerator(listOf(episode))
val currentLinks = mutableSetOf<ExtractorLink>() val currentLinks = mutableSetOf<ExtractorLink>()
val currentSubs = mutableSetOf<SubtitleData>() val currentSubs = mutableSetOf<SubtitleData>()
@ -704,27 +751,26 @@ class ResultViewModel2 : ViewModel() {
currentSubs.add(sub) currentSubs.add(sub)
}) })
if (currentLinks.isEmpty()) { //if (currentLinks.isEmpty()) {
main { // main {
showToast( // showToast(
activity, // activity,
R.string.no_links_found_toast, // R.string.no_links_found_toast,
Toast.LENGTH_SHORT // Toast.LENGTH_SHORT
) // )
} // }
return@ioSafe // return@ioSafe
} else { //} else {
main { // main {
showToast( // showToast(
activity, // activity,
R.string.download_started, // R.string.download_started,
Toast.LENGTH_SHORT // Toast.LENGTH_SHORT
) // )
} // }
} //}
startDownload( return getDownloadRequest(
activity,
episode, episode,
currentIsMovie, currentIsMovie,
currentHeaderName, currentHeaderName,
@ -737,7 +783,6 @@ class ResultViewModel2 : ViewModel() {
sortSubs(currentSubs), sortSubs(currentSubs),
) )
} }
}
private fun getMeta( private fun getMeta(
episode: ResultEpisode, episode: ResultEpisode,
@ -1021,6 +1066,20 @@ class ResultViewModel2 : ViewModel() {
handleEpisodeClickEvent(activity, click) handleEpisodeClickEvent(activity, click)
} }
suspend fun getRequest(card: ResultEpisode): DownloadRequest? {
val response = currentResponse ?: return null
return downloadEpisode(
card,
response.isMovie(),
response.name,
response.type,
response.posterUrl,
response.apiName,
response.getId(),
response.url
)
}
private suspend fun handleEpisodeClickEvent(activity: Activity?, click: EpisodeClickEvent) { private suspend fun handleEpisodeClickEvent(activity: Activity?, click: EpisodeClickEvent) {
when (click.action) { when (click.action) {
ACTION_SHOW_OPTIONS -> { ACTION_SHOW_OPTIONS -> {
@ -1117,18 +1176,11 @@ class ResultViewModel2 : ViewModel() {
showToast(activity, R.string.play_episode_toast, Toast.LENGTH_SHORT) showToast(activity, R.string.play_episode_toast, Toast.LENGTH_SHORT)
} }
ACTION_DOWNLOAD_EPISODE -> { ACTION_DOWNLOAD_EPISODE -> {
val response = currentResponse ?: return ioSafe {
downloadEpisode( val response = currentResponse ?: return@ioSafe
activity, val req = getRequest(click.data) ?: return@ioSafe
click.data, Aria2Starter.client?.downloadFailQueue(req.links) { _, _ -> }
response.isMovie(), }
response.name,
response.type,
response.posterUrl,
response.apiName,
response.getId(),
response.url
)
} }
ACTION_DOWNLOAD_MIRROR -> { ACTION_DOWNLOAD_MIRROR -> {
val response = currentResponse ?: return val response = currentResponse ?: return
@ -1138,8 +1190,7 @@ class ResultViewModel2 : ViewModel() {
txt(R.string.episode_action_download_mirror) txt(R.string.episode_action_download_mirror)
) { (result, index) -> ) { (result, index) ->
ioSafe { ioSafe {
startDownload( val req = getDownloadRequest(
activity,
click.data, click.data,
response.isMovie(), response.isMovie(),
response.name, response.name,
@ -1150,7 +1201,8 @@ class ResultViewModel2 : ViewModel() {
response.url, response.url,
listOf(result.links[index]), listOf(result.links[index]),
result.subs, result.subs,
) ) ?: return@ioSafe
Aria2Starter.client?.downloadFailQueue(req.links) { _, _ -> }
} }
showToast( showToast(
activity, activity,
@ -1592,7 +1644,8 @@ class ResultViewModel2 : ViewModel() {
val idIndex = ep.key.id val idIndex = ep.key.id
for ((index, i) in ep.value.withIndex()) { for ((index, i) in ep.value.withIndex()) {
val episode = i.episode ?: (index + 1) val episode = i.episode ?: (index + 1)
val id = mainId + episode + idIndex * 1_000_000 + (i.season?.times(10_000) ?: 0) val id =
mainId + episode + idIndex * 1_000_000 + (i.season?.times(10_000) ?: 0)
if (!existingEpisodes.contains(id)) { if (!existingEpisodes.contains(id)) {
existingEpisodes.add(id) existingEpisodes.add(id)
val seasonData = loadResponse.seasonNames.getSeason(i.season) val seasonData = loadResponse.seasonNames.getSeason(i.season)

View file

@ -995,7 +995,7 @@ object VideoDownloadManager {
} }
} }
private fun getDisplayName(name: String, extension: String): String { fun getDisplayName(name: String, extension: String): String {
return "$name.$extension" return "$name.$extension"
} }