Merge remote-tracking branch 'origin/master'

This commit is contained in:
Blatzar 2021-09-25 12:08:34 +02:00
commit 20eafc2e89
8 changed files with 157 additions and 126 deletions

View file

@ -35,6 +35,7 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver import com.lagradost.cloudstream3.receivers.VideoDownloadRestartReceiver
import com.lagradost.cloudstream3.ui.APIRepository import com.lagradost.cloudstream3.ui.APIRepository
import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO import com.lagradost.cloudstream3.ui.download.DOWNLOAD_NAVIGATE_TO
import com.lagradost.cloudstream3.utils.AppUtils.isCastApiAvailable
import com.lagradost.cloudstream3.utils.AppUtils.loadResult import com.lagradost.cloudstream3.utils.AppUtils.loadResult
import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.removeKey import com.lagradost.cloudstream3.utils.DataStore.removeKey
@ -117,14 +118,26 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
mCastSession = mSessionManager.currentCastSession try {
mSessionManager.addSessionManagerListener(mSessionManagerListener) if(isCastApiAvailable()) {
mCastSession = mSessionManager.currentCastSession
mSessionManager.addSessionManagerListener(mSessionManagerListener)
}
} catch (e : Exception) {
logError(e)
}
} }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
mSessionManager.removeSessionManagerListener(mSessionManagerListener) try {
mCastSession = null if(isCastApiAvailable()) {
mSessionManager.removeSessionManagerListener(mSessionManagerListener)
mCastSession = null
}
} catch (e : Exception) {
logError(e)
}
} }
companion object { companion object {
@ -188,7 +201,6 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
fun Context.updateLocale() { fun Context.updateLocale() {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this) val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val localeCode = settingsManager.getString(getString(R.string.locale_key), null) val localeCode = settingsManager.getString(getString(R.string.locale_key), null)
println("LOCALE: " + localeCode)
setLocale(this, localeCode) setLocale(this, localeCode)
} }
} }
@ -219,43 +231,9 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
} }
} }
private fun AppCompatActivity.backPressed(): Boolean {
/*val currentFragment = supportFragmentManager.fragments.last {
it.isVisible
}
if (currentFragment is NavHostFragment) {
val child = currentFragment.childFragmentManager.fragments.last {
it.isVisible
}
if (child is DownloadChildFragment) {
val navController = findNavController(R.id.nav_host_fragment)
navController.navigate(R.id.navigation_downloads, Bundle(), navOptions)
return true
}
if (child is SearchFragment || child is HomeFragment || child is DownloadFragment || child is SettingsFragment) {
this.finish()
return true
}
}
if (currentFragment != null && supportFragmentManager.fragments.size > 2) {
//MainActivity.showNavbar()
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.enter_anim, R.anim.exit_anim, R.anim.pop_enter, R.anim.pop_exit)
.remove(currentFragment)
.commitAllowingStateLoss()
backEvent.invoke(true)
return true
}
*/
backEvent.invoke(false)
return false
}
override fun onBackPressed() { override fun onBackPressed() {
this.updateLocale() this.updateLocale()
if (backPressed()) return backEvent.invoke(true)
super.onBackPressed() super.onBackPressed()
this.updateLocale() this.updateLocale()
} }
@ -315,7 +293,13 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
) // THEME IS SET BEFORE VIEW IS CREATED TO APPLY THE THEME TO THE MAIN VIEW ) // THEME IS SET BEFORE VIEW IS CREATED TO APPLY THE THEME TO THE MAIN VIEW
updateLocale() updateLocale()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
mSessionManager = CastContext.getSharedInstance(this).sessionManager try {
if(isCastApiAvailable()) {
mSessionManager = CastContext.getSharedInstance(this).sessionManager
}
} catch (e : Exception) {
logError(e)
}
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)

View file

@ -7,6 +7,8 @@ import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.loadExtractor import com.lagradost.cloudstream3.utils.loadExtractor
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import java.lang.Thread.sleep
import java.net.URLDecoder
class AllMoviesForYouProvider : MainAPI() { class AllMoviesForYouProvider : MainAPI() {
companion object { companion object {
@ -79,7 +81,7 @@ class AllMoviesForYouProvider : MainAPI() {
document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()?.times(10)?.toInt() document.selectFirst("div.Vote > div.post-ratings > span")?.text()?.toFloatOrNull()?.times(10)?.toInt()
val year = document.selectFirst("span.Date")?.text() val year = document.selectFirst("span.Date")?.text()
val duration = document.selectFirst("span.Time").text() val duration = document.selectFirst("span.Time").text()
val backgroundPoster = fixUrl(document.selectFirst("div.Image > figure > img").attr("src")) val backgroundPoster = fixUrl(document.selectFirst("div.Image > figure > img").attr("data-src"))
if (type == TvType.TvSeries) { if (type == TvType.TvSeries) {
val list = ArrayList<Pair<Int, String>>() val list = ArrayList<Pair<Int, String>>()
@ -142,7 +144,7 @@ class AllMoviesForYouProvider : MainAPI() {
url, url,
this.name, this.name,
type, type,
mapper.writeValueAsString(data), mapper.writeValueAsString(data.filter { it != "about:blank" }),
backgroundPoster, backgroundPoster,
year?.toIntOrNull(), year?.toIntOrNull(),
descipt, descipt,
@ -170,9 +172,43 @@ class AllMoviesForYouProvider : MainAPI() {
} }
return false return false
} else if (data.startsWith(mainUrl) && data != mainUrl) { } else if (data.startsWith(mainUrl) && data != mainUrl) {
val realDataUrl = data.replace("&#038;", "&").replace("&amp;", "&") val realDataUrl = URLDecoder.decode(data, "application/x-www-form-urlencoded")
if (data.contains("trdownload")) { if (data.contains("trdownload")) {
callback(ExtractorLink(this.name, this.name, realDataUrl, mainUrl, Qualities.Unknown.value)) val request = khttp.get(data, stream = true)
if (request.url.startsWith("https://streamhub.to/d/")) {
val document = Jsoup.parse(request.text)
val inputs = document.select("Form > input")
if (inputs.size < 4) return false
var op: String? = null
var id: String? = null
var mode: String? = null
var hash: String? = null
for (input in inputs) {
val value = input.attr("value") ?: continue
when (input.attr("name")) {
"op" -> op = value
"id" -> id = value
"mode" -> mode = value
"hash" -> hash = value
else -> {
}
}
}
if(op == null || id == null || mode == null || hash == null) {
return false
}
sleep(5000) // ye this is needed, wont work with 0 delay
val postResponse = khttp.post(request.url, headers = mapOf("content-type" to "application/x-www-form-urlencoded", "referer" to request.url, "user-agent" to USER_AGENT, "accept" to "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"), data = mapOf("op" to op, "id" to id, "mode" to mode, "hash" to hash))
val postDocument = Jsoup.parse(postResponse.text)
val url = postDocument.selectFirst("a.downloadbtn").attr("href")
if(url.isNullOrEmpty()) return false
callback(ExtractorLink(this.name, this.name, url, mainUrl, Qualities.Unknown.value))
} else {
callback(ExtractorLink(this.name, this.name, realDataUrl, mainUrl, Qualities.Unknown.value))
}
return true return true
} }
val response = khttp.get(realDataUrl) val response = khttp.get(realDataUrl)
@ -188,4 +224,4 @@ class AllMoviesForYouProvider : MainAPI() {
return true return true
} }
} }
} }

View file

@ -14,7 +14,6 @@ import android.widget.TextView
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog

View file

@ -53,6 +53,7 @@ class HomeViewModel : ViewModel() {
val resumeWatching: LiveData<List<SearchResponse>> = _resumeWatching val resumeWatching: LiveData<List<SearchResponse>> = _resumeWatching
fun loadResumeWatching(context: Context) = viewModelScope.launch { fun loadResumeWatching(context: Context) = viewModelScope.launch {
println("Resume::")
val resumeWatching = withContext(Dispatchers.IO) { val resumeWatching = withContext(Dispatchers.IO) {
context.getAllResumeStateIds().mapNotNull { id -> context.getAllResumeStateIds().mapNotNull { id ->
context.getLastWatched(id) context.getLastWatched(id)

View file

@ -70,10 +70,7 @@ import com.lagradost.cloudstream3.MainActivity.Companion.canEnterPipMode
import com.lagradost.cloudstream3.MainActivity.Companion.isInPIPMode import com.lagradost.cloudstream3.MainActivity.Companion.isInPIPMode
import com.lagradost.cloudstream3.MainActivity.Companion.showToast import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.*
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.mvvm.observe
import com.lagradost.cloudstream3.mvvm.observeDirectly
import com.lagradost.cloudstream3.ui.result.ResultEpisode import com.lagradost.cloudstream3.ui.result.ResultEpisode
import com.lagradost.cloudstream3.ui.result.ResultViewModel import com.lagradost.cloudstream3.ui.result.ResultViewModel
import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle import com.lagradost.cloudstream3.ui.subtitles.SaveCaptionStyle
@ -1046,79 +1043,83 @@ class PlayerFragment : Fragment() {
}*/ }*/
if (activity?.isCastApiAvailable() == true && !isDownloadedFile) { if (activity?.isCastApiAvailable() == true && !isDownloadedFile) {
CastButtonFactory.setUpMediaRouteButton(activity, player_media_route_button) try {
val castContext = CastContext.getSharedInstance(requireContext()) CastButtonFactory.setUpMediaRouteButton(activity, player_media_route_button)
val castContext = CastContext.getSharedInstance(requireContext())
if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) player_media_route_button.visibility = VISIBLE if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) player_media_route_button.visibility = VISIBLE
castContext.addCastStateListener { state -> castContext.addCastStateListener { state ->
if (player_media_route_button != null) { if (player_media_route_button != null) {
player_media_route_button.isVisible = state != CastState.NO_DEVICES_AVAILABLE player_media_route_button.isVisible = state != CastState.NO_DEVICES_AVAILABLE
if (state == CastState.CONNECTED) { if (state == CastState.CONNECTED) {
if (!this::exoPlayer.isInitialized) return@addCastStateListener if (!this::exoPlayer.isInitialized) return@addCastStateListener
val links = sortUrls(getUrls() ?: return@addCastStateListener) val links = sortUrls(getUrls() ?: return@addCastStateListener)
val epData = getEpisode() ?: return@addCastStateListener val epData = getEpisode() ?: return@addCastStateListener
val index = links.indexOf(getCurrentUrl()) val index = links.indexOf(getCurrentUrl())
(activity as MainActivity?)?.mCastSession?.startCast( (activity as MainActivity?)?.mCastSession?.startCast(
apiName, apiName,
currentIsMovie ?: return@addCastStateListener, currentIsMovie ?: return@addCastStateListener,
currentHeaderName, currentHeaderName,
currentPoster, currentPoster,
epData.index, epData.index,
episodes, episodes,
links, links,
context?.getSubs(supportsDownloadedFiles = false) ?: emptyList(), context?.getSubs(supportsDownloadedFiles = false) ?: emptyList(),
index, index,
exoPlayer.currentPosition exoPlayer.currentPosition
) )
/* /*
val customData = val customData =
links.map { JSONObject().put("name", it.name) } links.map { JSONObject().put("name", it.name) }
val jsonArray = JSONArray() val jsonArray = JSONArray()
for (item in customData) { for (item in customData) {
jsonArray.put(item) jsonArray.put(item)
}
val mediaItems = links.map {
val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE)
movieMetadata.putString(MediaMetadata.KEY_SUBTITLE,
epData.name ?: "Episode ${epData.episode}")
if (currentHeaderName != null)
movieMetadata.putString(MediaMetadata.KEY_TITLE, currentHeaderName)
val srcPoster = epData.poster ?: currentPoster
if (srcPoster != null) {
movieMetadata.addImage(WebImage(Uri.parse(srcPoster)))
} }
MediaQueueItem.Builder( val mediaItems = links.map {
MediaInfo.Builder(it.url) val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE)
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType(MimeTypes.VIDEO_UNKNOWN)
.setCustomData(JSONObject().put("data", jsonArray)) movieMetadata.putString(MediaMetadata.KEY_SUBTITLE,
.setMetadata(movieMetadata) epData.name ?: "Episode ${epData.episode}")
if (currentHeaderName != null)
movieMetadata.putString(MediaMetadata.KEY_TITLE, currentHeaderName)
val srcPoster = epData.poster ?: currentPoster
if (srcPoster != null) {
movieMetadata.addImage(WebImage(Uri.parse(srcPoster)))
}
MediaQueueItem.Builder(
MediaInfo.Builder(it.url)
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType(MimeTypes.VIDEO_UNKNOWN)
.setCustomData(JSONObject().put("data", jsonArray))
.setMetadata(movieMetadata)
.build()
)
.build() .build()
) }.toTypedArray()
.build()
}.toTypedArray()
val castPlayer = CastPlayer(castContext) val castPlayer = CastPlayer(castContext)
castPlayer.loadItems( castPlayer.loadItems(
mediaItems, mediaItems,
if (index > 0) index else 0, if (index > 0) index else 0,
exoPlayer.currentPosition, exoPlayer.currentPosition,
MediaStatus.REPEAT_MODE_REPEAT_SINGLE MediaStatus.REPEAT_MODE_REPEAT_SINGLE
)*/ )*/
// activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false) // activity?.popCurrentPage(isInPlayer = true, isInExpandedView = false, isInResults = false)
safeReleasePlayer() safeReleasePlayer()
activity?.popCurrentPage() activity?.popCurrentPage()
}
} }
} }
} catch (e : Exception) {
logError(e)
} }
} }

View file

@ -17,7 +17,6 @@ import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
@ -37,8 +36,8 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.APIHolder.getApiFromName import com.lagradost.cloudstream3.APIHolder.getApiFromName
import com.lagradost.cloudstream3.APIHolder.getId import com.lagradost.cloudstream3.APIHolder.getId
import com.lagradost.cloudstream3.MainActivity.Companion.showToast import com.lagradost.cloudstream3.MainActivity.Companion.showToast
import com.lagradost.cloudstream3.MainActivity.Companion.updateLocale
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.observe import com.lagradost.cloudstream3.mvvm.observe
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
@ -304,16 +303,20 @@ class ResultFragment : Fragment() {
activity?.let { activity?.let {
if (it.isCastApiAvailable()) { if (it.isCastApiAvailable()) {
CastButtonFactory.setUpMediaRouteButton(it, media_route_button) try {
val castContext = CastContext.getSharedInstance(it.applicationContext) CastButtonFactory.setUpMediaRouteButton(it, media_route_button)
val castContext = CastContext.getSharedInstance(it.applicationContext)
if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) media_route_button.visibility = VISIBLE if (castContext.castState != CastState.NO_DEVICES_AVAILABLE) media_route_button.visibility = VISIBLE
castContext.addCastStateListener { state -> castContext.addCastStateListener { state ->
if (media_route_button != null) { if (media_route_button != null) {
if (state == CastState.NO_DEVICES_AVAILABLE) media_route_button.visibility = GONE else { if (state == CastState.NO_DEVICES_AVAILABLE) media_route_button.visibility = GONE else {
if (media_route_button.visibility == GONE) media_route_button.visibility = VISIBLE if (media_route_button.visibility == GONE) media_route_button.visibility = VISIBLE
}
} }
} }
} catch (e : Exception) {
logError(e)
} }
} }
} }

View file

@ -110,16 +110,23 @@ class SettingsFragment : PreferenceFragmentCompat() {
currentList.add(allLangs.indexOf(i)) currentList.add(allLangs.indexOf(i))
} }
val names = allLangs.mapNotNull { SubtitleHelper.fromTwoLettersToLanguage(it) } val names = allLangs.mapNotNull {
val fullName = SubtitleHelper.fromTwoLettersToLanguage(it)
if (fullName.isNullOrEmpty()) {
return@mapNotNull null
}
Pair(it, fullName)
}
context?.showMultiDialog( context?.showMultiDialog(
names, names.map { it.second },
currentList, currentList,
getString(R.string.provider_lang_settings), getString(R.string.provider_lang_settings),
{}) { selectedList -> {}) { selectedList ->
settingsManager.edit().putStringSet( settingsManager.edit().putStringSet(
this.getString(R.string.provider_lang_key), this.getString(R.string.provider_lang_key),
selectedList.map { names[it] }.toMutableSet() selectedList.map { names[it].first }.toMutableSet()
).apply() ).apply()
} }
} }

View file

@ -260,7 +260,7 @@ object VideoDownloadManager {
} }
if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) { if (state == DownloadType.IsDownloading || state == DownloadType.IsPaused) {
builder.setProgress(total.toInt(), progress.toInt(), false) builder.setProgress((total / 1000).toInt(), (progress / 1000).toInt(), false)
} }
val rowTwoExtra = if (ep.name != null) " - ${ep.name}\n" else "" val rowTwoExtra = if (ep.name != null) " - ${ep.name}\n" else ""