shit not working due to android storage fuckery

This commit is contained in:
reduplicated 2022-09-23 22:05:06 +02:00
parent 45ea1a8d8e
commit 572aa6de3e
14 changed files with 134 additions and 95 deletions

View file

@ -201,7 +201,7 @@ dependencies {
implementation 'me.xdrop:fuzzywuzzy:1.4.0'
// aria2c downloader
implementation 'com.github.LagradOst:Aria2cButton:v0.0.3'
implementation 'com.github.LagradOst:Aria2cButton:v0.0.4'
}
task androidSourcesJar(type: Jar) {

View file

@ -137,9 +137,9 @@ object CommonActivity {
Aria2Starter.start(
act,
Aria2Settings(
UUID.randomUUID().toString(),
"1337", //UUID.randomUUID().toString()
4337,
act.filesDir.path,
"/storage/emulated/0/Download",// act.filesDir.path,
"${act.filesDir.path}/session"
)
)

View file

@ -4,6 +4,7 @@ import android.content.Context
import android.util.AttributeSet
import android.widget.TextView
import androidx.core.view.isVisible
import com.google.android.material.button.MaterialButton
import com.lagradost.cloudstream3.R
import com.lagradost.fetchbutton.aria2c.DownloadStatusTell
import com.lagradost.fetchbutton.aria2c.Metadata
@ -14,10 +15,22 @@ class DownloadButton(context: Context, attributeSet: AttributeSet) :
var progressText: TextView? = null
var mainText: TextView? = null
override fun onAttachedToWindow() {
super.onAttachedToWindow()
var bigButton: MaterialButton? = null
override fun onInflate() {
overrideLayout = R.layout.download_button_layout
super.onInflate()
progressText = findViewById(R.id.result_movie_download_text_precentage)
mainText = findViewById(R.id.result_movie_download_text)
bigButton = findViewById(R.id.download_big_button)
}
override fun setOnClickListener(l: OnClickListener?) {
bigButton?.setOnClickListener(l)
}
override fun setOnLongClickListener(l: OnLongClickListener?) {
bigButton?.setOnLongClickListener(l)
}
override fun setStatus(status: DownloadStatusTell?) {

View file

@ -1,12 +1,17 @@
package com.lagradost.cloudstream3.ui.result
import android.app.Activity
import android.net.Uri
import android.widget.Toast
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_LONG_CLICK
import com.lagradost.cloudstream3.ui.download.DownloadEpisodeClickEvent
import com.lagradost.cloudstream3.ui.player.DownloadFileGenerator
import com.lagradost.cloudstream3.utils.ExtractorUri
import com.lagradost.cloudstream3.utils.UIHelper.popupMenuNoIcons
import com.lagradost.fetchbutton.aria2c.Aria2Starter
import com.lagradost.fetchbutton.aria2c.DownloadStatusTell
import com.lagradost.fetchbutton.ui.PieFetchButton
@ -39,9 +44,17 @@ object DownloadHelper {
downloadClickCallback: (DownloadEpisodeClickEvent) -> Unit
) {
setPersistentId(card.id.toLong())
val play = if (card.episode <= 0) R.string.play_movie_button else R.string.play_episode
setOnClickListener { view ->
if (view !is PieFetchButton) return@setOnClickListener
setOnLongClickListener { //Aria2Starter.saveActivity.get()
downloadClickCallback.invoke(DownloadEpisodeClickEvent(DOWNLOAD_ACTION_LONG_CLICK, card))
//showToast(it.context as? Activity, R.string.download, Toast.LENGTH_SHORT)
return@setOnLongClickListener true
}
setOnClickListener {
val view = this
//if (view !is PieFetchButton) return@setOnClickListener
when (view.currentStatus) {
null, DownloadStatusTell.Removed -> {
view.setStatus(DownloadStatusTell.Waiting)
@ -56,7 +69,7 @@ object DownloadHelper {
view.popupMenuNoIcons(
listOf(
1 to R.string.resume,
2 to R.string.play_episode,
2 to play,
3 to R.string.delete
)
) {
@ -69,29 +82,21 @@ object DownloadHelper {
)
)
}
2 -> {
play(card)
}
3 -> {
view.deleteAllFiles()
}
2 -> play(card)
3 -> view.deleteAllFiles()
}
}
}
DownloadStatusTell.Complete -> {
view.popupMenuNoIcons(
listOf(
2 to R.string.play_episode,
2 to play,
3 to R.string.delete
)
) {
when (itemId) {
2 -> {
play(card)
}
3 -> {
view.deleteAllFiles()
}
2 -> play(card)
3 -> view.deleteAllFiles()
}
}
}
@ -99,20 +104,14 @@ object DownloadHelper {
view.popupMenuNoIcons(
listOf(
4 to R.string.pause,
2 to R.string.play_episode,
2 to play,
3 to R.string.delete
)
) {
when (itemId) {
4 -> {
view.pauseDownload()
}
2 -> {
play(card)
}
3 -> {
view.deleteAllFiles()
}
4 -> view.pauseDownload()
2 -> play(card)
3 -> view.deleteAllFiles()
}
}
}

View file

@ -34,28 +34,32 @@ import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.mvvm.*
import com.lagradost.cloudstream3.syncproviders.providers.Kitsu
import com.lagradost.cloudstream3.ui.WatchType
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_DOWNLOAD
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_ACTION_LONG_CLICK
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
import com.lagradost.cloudstream3.ui.result.DownloadHelper.setUp
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTrueTvSettings
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.isTvSettings
import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.getNameFull
import com.lagradost.cloudstream3.utils.AppUtils.html
import com.lagradost.cloudstream3.utils.AppUtils.loadCache
import com.lagradost.cloudstream3.utils.AppUtils.openBrowser
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.DataStoreHelper.getViewPos
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showBottomDialog
import com.lagradost.cloudstream3.utils.UIHelper
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe
import com.lagradost.cloudstream3.utils.UIHelper.fixPaddingStatusbar
import com.lagradost.cloudstream3.utils.UIHelper.hideKeyboard
import kotlinx.android.synthetic.main.download_button.*
import kotlinx.android.synthetic.main.fragment_result.*
import kotlinx.android.synthetic.main.fragment_result.result_cast_items
import kotlinx.android.synthetic.main.fragment_result.result_cast_text
import kotlinx.android.synthetic.main.fragment_result.result_coming_soon
import kotlinx.android.synthetic.main.fragment_result.result_data_holder
import kotlinx.android.synthetic.main.fragment_result.result_description
import kotlinx.android.synthetic.main.fragment_result.result_download_movie
import kotlinx.android.synthetic.main.fragment_result.result_episode_loading
import kotlinx.android.synthetic.main.fragment_result.result_episodes
import kotlinx.android.synthetic.main.fragment_result.result_error_text
@ -334,7 +338,13 @@ open class ResultFragment : ResultTrailerPlayer() {
result_download_movie?.setUp(ep) {
viewModel.download(it.data)
when (it.action) {
DOWNLOAD_ACTION_DOWNLOAD -> viewModel.download(activity, it.data)
DOWNLOAD_ACTION_LONG_CLICK -> viewModel.handleAction(
activity,
EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, ep)
)
}
}
result_download_movie?.isVisible = true
/*main {
@ -509,7 +519,13 @@ open class ResultFragment : ResultTrailerPlayer() {
viewModel.handleAction(activity, episodeClick)
},
{ clickEvent ->
viewModel.download(clickEvent.data)
when (clickEvent.action) {
DOWNLOAD_ACTION_DOWNLOAD -> viewModel.download(activity, clickEvent.data)
DOWNLOAD_ACTION_LONG_CLICK -> viewModel.handleAction(
activity,
EpisodeClickEvent(ACTION_DOWNLOAD_MIRROR, clickEvent.data)
)
}
//handleDownloadClick(activity, downloadClickEvent)
}
)

View file

@ -56,10 +56,12 @@ import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import com.lagradost.cloudstream3.utils.UIHelper.requestRW
import com.lagradost.cloudstream3.utils.VideoDownloadManager.getBasePath
import com.lagradost.cloudstream3.utils.VideoDownloadManager.gotoDir
import com.lagradost.fetchbutton.NotificationMetaData
import com.lagradost.fetchbutton.aria2c.Aria2Starter
import com.lagradost.fetchbutton.aria2c.UriRequest
import com.lagradost.fetchbutton.aria2c.newUriRequest
import com.lagradost.fetchbutton.utils.Coroutines.mainThread
import kotlinx.coroutines.*
import java.io.File
import java.lang.Math.abs
@ -534,24 +536,16 @@ class ResultViewModel2 : ViewModel() {
}
private fun downloadSubtitle(
context: Context?,
link: ExtractorSubtitleLink,
fileName: String,
folder: String
) {
ioSafe {
VideoDownloadManager.downloadThing(
context ?: return@ioSafe,
link,
"$fileName ${link.name}",
folder,
if (link.url.contains(".srt")) ".srt" else "vtt",
false,
null
) {
// no notification
}
}
Aria2Starter.download(
newUriRequest(
null, link.url, fileName, folder, link.headers,
USER_AGENT
)
)
}
private fun getFolder(currentType: TvType, titleName: String): String {
@ -581,7 +575,6 @@ class ResultViewModel2 : ViewModel() {
val fileName = VideoDownloadManager.getFileName(ctx, meta)
val folder = getFolder(meta.type ?: return, meta.mainName)
downloadSubtitle(
ctx,
ExtractorSubtitleLink(link.name, link.url, ""),
fileName,
folder
@ -611,10 +604,12 @@ class ResultViewModel2 : ViewModel() {
currentType
)
val topFolder = AcraApplication.context?.getBasePath()?.first?.filePath
val topFolder = VideoDownloadManager.getDownloadDir()?.filePath ?: throw RuntimeException("FUCK YOU")//AcraApplication.context?.getBasePath()?.first //?.second?.also { println("URIIIIII: $it") } ?: throw RuntimeException("FUCK YOU")
//?: VideoDownloadManager.getDownloadDir()?.filePath ?: return null
val folder =
topFolder + "/" + getFolder(currentType, currentHeaderName).replace(".", "")
val folder = topFolder//topFolder?.gotoDir(getFolder(currentType, currentHeaderName).replace(".", ""), true)?.uri?.toString() ?: throw RuntimeException("FUCK YOU")
//val folder =
// topFolder + "/" + getFolder(currentType, currentHeaderName).replace(".", "")
//val src = "$DOWNLOAD_NAVIGATE_TO/$parentId" // url ?: return@let
// SET VISUAL KEYS
@ -667,8 +662,7 @@ class ResultViewModel2 : ViewModel() {
contentTitle = currentHeaderName,
secondRow = rowTwo,
subText = null,
linkName = currentHeaderName,
rowTwoExtra = null
linkName = null,
)
}
@ -680,9 +674,16 @@ class ResultViewModel2 : ViewModel() {
VideoDownloadManager.getFileName(
AcraApplication.context ?: return null,
meta
), ".mp4"
), folder, link.headers, USER_AGENT,
notificationMetaData = notification
), "mp4"
), null,
link.headers, USER_AGENT,
notificationMetaData = notification?.copy(
linkName = "${link.name} ${
Qualities.getStringByInt(
link.quality
)
}"
)
)
}
@ -694,17 +695,24 @@ class ResultViewModel2 : ViewModel() {
true
)
)
}.distinctBy { it.url }
//.map { ExtractorSubtitleLink(it.name, it.url, "") }
.map { link ->
val fileName = VideoDownloadManager.getFileName(
}.distinctBy { it.url }.groupBy { link ->
SubtitleHelper.fromLanguageToTwoLetters(
link.name,
true
)
}.map {
it.value.map { link ->
val fileName = VideoDownloadManager.getDisplayName(
VideoDownloadManager.getFileName(
AcraApplication.context ?: return null,
meta
) + ".vtt"
), "vtt"
)
newUriRequest(0, link.url, fileName, folder, link.headers, USER_AGENT)
newUriRequest(null, link.url, fileName, folder, link.headers, USER_AGENT)
//downloadSubtitle(context, link, fileName, folder)
}
}
return DownloadRequest(linkRequests, downloadSubsList)
@ -740,7 +748,7 @@ class ResultViewModel2 : ViewModel() {
data class DownloadRequest(
val links: List<UriRequest>,
val subs: List<UriRequest>,
val subs: List<List<UriRequest>>,
)
@ -1093,16 +1101,24 @@ class ResultViewModel2 : ViewModel() {
handleEpisodeClickEvent(activity, click)
}
private fun downloadFromRequest(req: DownloadRequest) {
private fun downloadFromRequest(activity: Activity?, req: DownloadRequest) {
Aria2Starter.download(req.links)
for (sub in req.subs.take(5)) {
for (sub in req.subs.take(4)) { // download max 4 langs to not block real download
Aria2Starter.download(sub)
}
val linksFound = req.links.isNotEmpty()
mainThread {
showToast(
activity,
if (linksFound) R.string.download_started else R.string.no_links_found_toast,
Toast.LENGTH_SHORT
)
}
}
fun download(card: ResultEpisode) = ioSafe {
fun download(activity: Activity?, card: ResultEpisode) = ioSafe {
getRequest(card)?.let { req ->
downloadFromRequest(req)
downloadFromRequest(activity, req)
}
}
@ -1242,13 +1258,8 @@ class ResultViewModel2 : ViewModel() {
listOf(result.links[index]),
result.subs,
) ?: return@ioSafe
downloadFromRequest(req)
downloadFromRequest(activity, req)
}
showToast(
activity,
R.string.download_started,
Toast.LENGTH_SHORT
)
}
}
ACTION_RELOAD_EPISODE -> {

View file

@ -426,7 +426,7 @@ object VideoDownloadManager {
}
private const val reservedChars = "|\\?*<\":>+[]/\'"
fun sanitizeFilename(name: String, removeSpaces: Boolean= false): String {
fun sanitizeFilename(name: String, removeSpaces: Boolean = false): String {
var tempName = name
for (c in reservedChars) {
tempName = tempName.replace(c, ' ')
@ -941,7 +941,7 @@ object VideoDownloadManager {
* @param directoryName if null will use the current path.
* @return UniFile / null if createMissingDirectories = false and folder is not found.
* */
private fun UniFile.gotoDir(
fun UniFile.gotoDir(
directoryName: String?,
createMissingDirectories: Boolean = true
): UniFile? {
@ -1612,7 +1612,7 @@ object VideoDownloadManager {
.mapIndexed { index, any -> DownloadQueueResumePackage(index, any) }
.toTypedArray()
setKey(KEY_RESUME_QUEUE_PACKAGES, dQueue)
} catch (t : Throwable) {
} catch (t: Throwable) {
logError(t)
}
}

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<com.lagradost.cloudstream3.ui.DownloadButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/result_download_movie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:aria2c_layout="@layout/download_button_layout" />

View file

@ -9,6 +9,7 @@
<com.google.android.material.button.MaterialButton
style="@style/BlackButton"
android:id="@+id/download_big_button"
android:layout_width="match_parent"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
@ -20,9 +21,10 @@
android:layout_gravity="center">
<include
android:layout_gravity="center"
layout="@layout/download_button_view"
android:layout_width="40dp"
android:layout_height="40dp" />
android:layout_width="35dp"
android:layout_height="35dp" />
<TextView
android:id="@+id/result_movie_download_text"

View file

@ -569,8 +569,12 @@
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent" />-->
<include layout="@layout/download_button" />
<com.lagradost.cloudstream3.ui.DownloadButton
android:id="@+id/result_download_movie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:aria2c_layout="@layout/download_button_layout" />
<!--<androidx.core.widget.ContentLoadingProgressBar
android:layout_width="match_parent"

View file

@ -418,8 +418,8 @@
</com.google.android.material.button.MaterialButton>
<include
layout="@layout/download_button"
<com.lagradost.cloudstream3.ui.DownloadButton
android:id="@+id/result_download_movie"
android:layout_width="wrap_content"
android:layout_weight="1"
android:minWidth="250dp"

View file

@ -99,6 +99,7 @@
android:background="?selectableItemBackgroundBorderless"
android:id="@+id/result_episode_download"
android:layout_gravity="center"
android:padding="10dp"
android:layout_width="50dp"
android:layout_height="50dp">
</com.lagradost.fetchbutton.ui.PieFetchButton>

View file

@ -109,6 +109,7 @@
android:background="?selectableItemBackgroundBorderless"
android:id="@+id/result_episode_download"
android:layout_gravity="center"
android:padding="5dp"
android:layout_width="50dp"
android:layout_height="50dp">
</com.lagradost.fetchbutton.ui.PieFetchButton>

View file

@ -69,6 +69,7 @@
<item name="aria2c_icon_color">?attr/white</item>
<item name="aria2c_fill_color">?attr/white</item>
<item name="aria2c_outline_color">?attr/white</item>
<item name="aria2c_icon_scale">0.7</item>
</style>
<style name="ListViewStyle" parent="Widget.AppCompat.ListView">