From 6fcbf27b236f6d4954e10f3324195625fb521b74 Mon Sep 17 00:00:00 2001 From: aicynide <97217381+aicynide@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:34:28 +0530 Subject: [PATCH] feat: add mpv+ytdl app --- app/src/main/AndroidManifest.xml | 3 +- .../lagradost/cloudstream3/MainActivity.kt | 23 +++++++++- .../cloudstream3/ui/result/EpisodeAdapter.kt | 2 + .../ui/result/ResultViewModel2.kt | 45 ++++++++++++++++++- app/src/main/res/values/array.xml | 1 + app/src/main/res/values/strings.xml | 3 +- 6 files changed, 72 insertions(+), 5 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 888be999..eb6565f9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,6 +34,7 @@ + @@ -220,4 +221,4 @@ - \ No newline at end of file + diff --git a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt index 5408d2a8..a880bc6d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/MainActivity.kt @@ -192,10 +192,12 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa companion object { const val VLC_PACKAGE = "org.videolan.vlc" const val MPV_PACKAGE = "is.xyz.mpv" + const val MPV_YTDL_PACKAGE = "is.xyz.mpv.ytdl" const val WEB_VIDEO_CAST_PACKAGE = "com.instantbits.cast.webvideo" val VLC_COMPONENT = ComponentName(VLC_PACKAGE, "$VLC_PACKAGE.gui.video.VideoPlayerActivity") val MPV_COMPONENT = ComponentName(MPV_PACKAGE, "$MPV_PACKAGE.MPVActivity") + val MPV_YTDL_COMPONENT = ComponentName(MPV_YTDL_PACKAGE, "is.xyz.mpv.ytdl/is.xyz.mpv.MPVActivity") //TODO REFACTOR AF open class ResultResume( @@ -267,10 +269,27 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa } } + val MPV_YTDL = object : ResultResume( + MPV_YTDL_PACKAGE, + //"is.xyz.mpv.ytdl/is.xyz.mpv.MPVActivity.result", // resume not working :pensive: + position = "position", + duration = "duration", + ) { + override fun getPosition(intent: Intent?): Long { + return intent?.getIntExtra(this.position, defaultTime.toInt())?.toLong() + ?: defaultTime + } + + override fun getDuration(intent: Intent?): Long { + return intent?.getIntExtra(this.duration, defaultTime.toInt())?.toLong() + ?: defaultTime + } + } + val WEB_VIDEO = ResultResume(WEB_VIDEO_CAST_PACKAGE) val resumeApps = arrayOf( - VLC, MPV, WEB_VIDEO + VLC, MPV, MPV_YTDL, WEB_VIDEO ) @@ -1861,4 +1880,4 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa false } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt index d12521b3..4cd9cc9e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/EpisodeAdapter.kt @@ -54,6 +54,7 @@ const val ACTION_DOWNLOAD_EPISODE_SUBTITLE_MIRROR = 14 const val ACTION_PLAY_EPISODE_IN_WEB_VIDEO = 16 const val ACTION_PLAY_EPISODE_IN_MPV = 17 +const val ACTION_PLAY_EPISODE_IN_MPV_YTDL = 20 const val ACTION_MARK_AS_WATCHED = 18 const val ACTION_FCAST = 19 @@ -81,6 +82,7 @@ class EpisodeAdapter( 3 -> ACTION_PLAY_EPISODE_IN_BROWSER 4 -> ACTION_PLAY_EPISODE_IN_WEB_VIDEO 5 -> ACTION_PLAY_EPISODE_IN_MPV + 6 -> ACTION_PLAY_EPISODE_IN_MPV_YTDL else -> ACTION_PLAY_EPISODE_IN_PLAYER } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt index 6443a923..a29941d1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt @@ -33,6 +33,9 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.readIdFromString import com.lagradost.cloudstream3.MainActivity.Companion.MPV import com.lagradost.cloudstream3.MainActivity.Companion.MPV_COMPONENT import com.lagradost.cloudstream3.MainActivity.Companion.MPV_PACKAGE +import com.lagradost.cloudstream3.MainActivity.Companion.MPV_YTDL +import com.lagradost.cloudstream3.MainActivity.Companion.MPV_YTDL_COMPONENT +import com.lagradost.cloudstream3.MainActivity.Companion.MPV_YTDL_PACKAGE import com.lagradost.cloudstream3.MainActivity.Companion.VLC import com.lagradost.cloudstream3.MainActivity.Companion.VLC_COMPONENT import com.lagradost.cloudstream3.MainActivity.Companion.VLC_PACKAGE @@ -1454,6 +1457,25 @@ class ResultViewModel2 : ViewModel() { putExtra("position", position.toInt()) } + private fun playWithMpvYtdl( + activity: Activity?, + id: Int, + link: ExtractorLink, + subtitles: List, + resume: Boolean = true, + ) = launchActivity(activity, MPV_YTDL, id) { + putExtra("subs", subtitles.map { it.url.toUri() }.toTypedArray()) + putExtra("subs.name", subtitles.map { it.name }.toTypedArray()) + putExtra("subs.filename", subtitles.map { it.name }.toTypedArray()) + setDataAndType(Uri.parse(link.url), "video/*") + component = MPV_YTDL_COMPONENT + putExtra("secure_uri", true) + putExtra("return_result", true) + val position = getViewPos(id)?.position + if (resume && position != null) + putExtra("position", position.toInt()) + } + // https://wiki.videolan.org/Android_Player_Intents/ private fun playWithVlc( activity: Activity?, @@ -1538,6 +1560,11 @@ class ResultViewModel2 : ViewModel() { MPV_PACKAGE, R.string.player_settings_play_in_mpv, ACTION_PLAY_EPISODE_IN_MPV + ), + ExternalApp( + MPV_YTDL_PACKAGE, + R.string.player_settings_play_in_mpvytdl, + ACTION_PLAY_EPISODE_IN_MPV_YTDL ) ) @@ -1849,6 +1876,22 @@ class ResultViewModel2 : ViewModel() { ) } + ACTION_PLAY_EPISODE_IN_MPV_YTDL -> acquireSingleLink( + click.data, + LoadType.Chromecast, + txt( + R.string.episode_action_play_in_format, + txt(R.string.player_settings_play_in_mpvytdl) + ) + ) { (result, index) -> + playWithMpvYtdl( + activity, + click.data.id, + result.links[index], + result.subs + ) + } + ACTION_PLAY_EPISODE_IN_PLAYER -> { val data = currentResponse?.syncData?.toList() ?: emptyList() val list = @@ -2861,4 +2904,4 @@ class ResultViewModel2 : ViewModel() { } } } -} \ No newline at end of file +} diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 03715faf..f04e2a80 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -54,6 +54,7 @@ @string/player_settings_play_in_app @string/player_settings_play_in_vlc @string/player_settings_play_in_mpv + @string/player_settings_play_in_mpvytdl @string/player_settings_play_in_web @string/player_settings_play_in_browser diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8156abbf..8cf25c09 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -664,6 +664,7 @@ Internal player VLC MPV + MPV YTDL Web Video Cast Fcast Web browser @@ -814,4 +815,4 @@ preview_seekbar_key Seekbar preview Enable preview thumbnail on seekbar - \ No newline at end of file +