feat: add mpv+ytdl app

This commit is contained in:
aicynide 2024-08-13 21:34:28 +05:30 committed by Your Name
parent 4d3ab40093
commit 6fcbf27b23
6 changed files with 72 additions and 5 deletions

View file

@ -34,6 +34,7 @@
<package android:name="org.videolan.vlc" />
<package android:name="com.instantbits.cast.webvideo" />
<package android:name="is.xyz.mpv" />
<package android:name="is.xyz.mpv.ytdl" />
</queries>
<!-- Without the large heap Exoplayer buffering gets reset due to OOM. -->

View file

@ -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
)

View file

@ -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
}
}

View file

@ -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<SubtitleData>,
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 =

View file

@ -54,6 +54,7 @@
<item>@string/player_settings_play_in_app</item>
<item>@string/player_settings_play_in_vlc</item>
<item>@string/player_settings_play_in_mpv</item>
<item>@string/player_settings_play_in_mpvytdl</item>
<item>@string/player_settings_play_in_web</item>
<item>@string/player_settings_play_in_browser</item>
</array>

View file

@ -664,6 +664,7 @@
<string name="player_settings_play_in_app">Internal player</string>
<string name="player_settings_play_in_vlc">VLC</string>
<string name="player_settings_play_in_mpv">MPV</string>
<string name="player_settings_play_in_mpvytdl">MPV YTDL</string>
<string name="player_settings_play_in_web">Web Video Cast</string>
<string name="player_settings_play_in_fcast">Fcast</string>
<string name="player_settings_play_in_browser">Web browser</string>