Add isM3u8 to raw stream button

This commit is contained in:
Blatzar 2022-09-05 20:45:56 +02:00
parent 6f3e9891c5
commit afb35f73b3
4 changed files with 90 additions and 53 deletions

View file

@ -38,6 +38,9 @@ import com.lagradost.cloudstream3.utils.VideoDownloadManager
import kotlinx.android.synthetic.main.fragment_downloads.* import kotlinx.android.synthetic.main.fragment_downloads.*
import kotlinx.android.synthetic.main.stream_input.* import kotlinx.android.synthetic.main.stream_input.*
import android.text.format.Formatter.formatShortFileSize import android.text.format.Formatter.formatShortFileSize
import androidx.core.widget.doOnTextChanged
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import java.net.URI
const val DOWNLOAD_NAVIGATE_TO = "downloadpage" const val DOWNLOAD_NAVIGATE_TO = "downloadpage"
@ -183,10 +186,29 @@ class DownloadFragment : Fragment() {
dialog.show() dialog.show()
// If user has clicked the switch do not interfere
var preventAutoSwitching = false
dialog.hls_switch?.setOnClickListener {
preventAutoSwitching = true
}
fun activateSwitchOnHls(text: String?) {
dialog.hls_switch?.isChecked = normalSafeApiCall {
URI(text).path?.substringAfterLast(".")?.contains("m3u")
} == true
}
dialog.stream_referer?.doOnTextChanged { text, _, _, _ ->
if (!preventAutoSwitching)
activateSwitchOnHls(text?.toString())
}
(activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?)?.primaryClip?.getItemAt( (activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager?)?.primaryClip?.getItemAt(
0 0
)?.text?.toString()?.let { copy -> )?.text?.toString()?.let { copy ->
dialog.stream_url?.setText(copy) val fixedText = copy.trim()
dialog.stream_url?.setText(fixedText)
activateSwitchOnHls(fixedText)
} }
dialog.apply_btt?.setOnClickListener { dialog.apply_btt?.setOnClickListener {
@ -202,7 +224,8 @@ class DownloadFragment : Fragment() {
LinkGenerator( LinkGenerator(
listOf(url), listOf(url),
extract = true, extract = true,
referer = referer referer = referer,
isM3u8 = dialog.hls_switch?.isChecked
) )
) )
) )

View file

@ -1,12 +1,15 @@
package com.lagradost.cloudstream3.ui.player package com.lagradost.cloudstream3.ui.player
import com.lagradost.cloudstream3.apmap import com.lagradost.cloudstream3.apmap
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.*
import java.net.URI
class LinkGenerator( class LinkGenerator(
private val links: List<String>, private val links: List<String>,
private val extract: Boolean = true, private val extract: Boolean = true,
private val referer: String? = null, private val referer: String? = null,
private val isM3u8: Boolean? = null
) : IGenerator { ) : IGenerator {
override val hasCache = false override val hasCache = false
@ -57,7 +60,9 @@ class LinkGenerator(
link, link,
unshortenLinkSafe(link), // unshorten because it might be a raw link unshortenLinkSafe(link), // unshorten because it might be a raw link
referer ?: "", referer ?: "",
Qualities.Unknown.value, link.contains(".m3u") // TODO USE REAL PARSER Qualities.Unknown.value, isM3u8 ?: normalSafeApiCall {
URI(link).path?.substringAfterLast(".")?.contains("m3u")
} ?: false
) to null ) to null
) )
} }

View file

@ -1,73 +1,81 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
<TextView <TextView
android:id="@+id/text1" android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="?attr/textColor"
android:layout_width="match_parent"
android:layout_rowWeight="1"
android:text="@string/stream" android:text="@string/stream"
android:layout_height="wrap_content" /> android:textColor="?attr/textColor"
android:textSize="20sp"
android:textStyle="bold" />
<EditText <EditText
android:layout_weight="20"
android:id="@+id/stream_url" android:id="@+id/stream_url"
android:inputType="textUri"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="20"
android:hint="@string/network_adress_example" android:hint="@string/network_adress_example"
android:inputType="textUri"
tools:ignore="LabelFor" /> tools:ignore="LabelFor" />
<EditText <EditText
android:layout_weight="20"
android:id="@+id/stream_referer" android:id="@+id/stream_referer"
android:inputType="textUri"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="20"
android:hint="@string/referer" android:hint="@string/referer"
android:inputType="textUri"
tools:ignore="LabelFor" /> tools:ignore="LabelFor" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/hls_switch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="@string/hls_playlist"
android:textColor="?attr/textColor"
android:textSize="16sp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:gravity="bottom|end" android:gravity="bottom|end"
android:layout_width="match_parent" android:orientation="horizontal">
android:layout_height="60dp">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="@style/WhiteButton"
android:layout_gravity="center_vertical|end"
android:visibility="visible"
android:text="@string/home_play"
android:id="@+id/apply_btt" android:id="@+id/apply_btt"
android:layout_width="wrap_content"> style="@style/WhiteButton"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end"
android:text="@string/home_play"
android:visibility="visible">
<requestFocus /> <requestFocus />
</com.google.android.material.button.MaterialButton> </com.google.android.material.button.MaterialButton>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
style="@style/BlackButton"
android:layout_gravity="center_vertical|end"
android:text="@string/sort_cancel"
android:id="@+id/cancel_btt" android:id="@+id/cancel_btt"
android:layout_width="wrap_content" /> style="@style/BlackButton"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical|end"
android:text="@string/sort_cancel" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -615,4 +615,5 @@
<string name="safe_mode_title">Safe Mode enabled</string> <string name="safe_mode_title">Safe Mode enabled</string>
<string name="safe_mode_description">An unrecoverable crash occurred and we\'ve automatically disabled all extensions, so you can find and remove the extension which is causing trouble.</string> <string name="safe_mode_description">An unrecoverable crash occurred and we\'ve automatically disabled all extensions, so you can find and remove the extension which is causing trouble.</string>
<string name="safe_mode_crash_info">View crash info</string> <string name="safe_mode_crash_info">View crash info</string>
<string name="hls_playlist">HLS Playlist</string>
</resources> </resources>