Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class ResultFragmentTv : BaseFragment<FragmentResultTvBinding>(
resultEpisodes.setRecycledViewPool(EpisodeAdapter.sharedPool)
resultEpisodes.adapter =
EpisodeAdapter(
false,
true,
{ episodeClick ->
viewModel.handleAction(episodeClick)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ class ResultViewModel2 : ViewModel() {
listOf(
txt(R.string.episode_action_auto_download) to ACTION_DOWNLOAD_EPISODE,
txt(R.string.episode_action_download_mirror) to ACTION_DOWNLOAD_MIRROR,
txt("Download (Nova Server / USB Fallback)") to 9999,
txt(R.string.episode_action_download_subtitle) to ACTION_DOWNLOAD_EPISODE_SUBTITLE_MIRROR,
txt(R.string.episode_action_reload_links) to ACTION_RELOAD_EPISODE,
)
Expand Down Expand Up @@ -1486,6 +1487,89 @@ class ResultViewModel2 : ViewModel() {
response.url,
).toWrapper()
)
} 9999 -> {
val response = currentResponse ?: return
acquireSingleLink(
click.data,
LOADTYPE_INAPP_DOWNLOAD,
txt("Download: Choose Source & Quality")
) { (result, index) ->
ioSafe {
val link = result.links[index]
val fullTitle = activity?.getNameFull(
click.data.name,
click.data.episode,
click.data.season
) ?: response.name

var novaSuccess = false
try {
val payload = org.json.JSONObject().apply {
put("title", fullTitle)
put("url", link.url)
put("referer", link.referer)
put("quality", Qualities.getStringByInt(link.quality))
put("type", link.type.name)
val headersJson = org.json.JSONObject()
link.headers.forEach { (k, v) -> headersJson.put(k, v) }
put("headers", headersJson)
}
val conn = (java.net.URL("http://192.168.1.9:8765/api/download").openConnection() as java.net.HttpURLConnection).apply {
requestMethod = "POST"
setRequestProperty("Authorization", "Bearer nova-cloudstream-secure-token-2026")
setRequestProperty("Content-Type", "application/json")
doOutput = true
connectTimeout = 4000
readTimeout = 4000
}
conn.outputStream.use { os ->
os.write(payload.toString().toByteArray(Charsets.UTF_8))
}
val code = conn.responseCode
conn.disconnect()
novaSuccess = (code in 200..299)
} catch (e: Exception) {
com.lagradost.cloudstream3.mvvm.logError(e)
novaSuccess = false
}

main {
if (novaSuccess) {
showToast("Queued on Nova Server: " + fullTitle, Toast.LENGTH_LONG)
} else {
// Fallback: Nova server unavailable -> Detect connected USB storage on TV
val ctx = activity ?: com.lagradost.cloudstream3.CloudStreamApp.context
if (ctx != null) {
val extDirs = ctx.getExternalFilesDirs("")
// Index 0 is internal flash; index 1+ are external USB / SD card mounts
val usbDir = if (extDirs.size > 1 && extDirs[1] != null) extDirs[1]?.path else null

if (!usbDir.isNullOrBlank()) {
val settings = androidx.preference.PreferenceManager.getDefaultSharedPreferences(ctx)
settings.edit().putString(ctx.getString(R.string.download_path_key), usbDir).apply()
settings.edit().putString(ctx.getString(R.string.download_path_key_visual), usbDir).apply()
}
}

DownloadQueueManager.addToQueue(
DownloadObjects.DownloadQueueItem(
click.data,
response.isMovie(),
response.name,
response.type,
response.posterUrl,
response.apiName,
response.getId(),
response.url,
listOf(link),
result.subs,
).toWrapper()
)
showToast("Nova unreachable! Downloading to TV USB storage: " + fullTitle, Toast.LENGTH_LONG)
}
}
}
}
}

ACTION_DOWNLOAD_MIRROR -> {
Expand Down
Loading
Loading