mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-19 19:14:51 +00:00
Channel shorts tab, Forced batch parallelization, Playlist download support for live sources, hardware codec query
This commit is contained in:
parent
2cd01eb1fe
commit
83b35183d0
14 changed files with 144 additions and 20 deletions
|
@ -11,7 +11,8 @@ let Type = {
|
|||
Streams: "STREAMS",
|
||||
Mixed: "MIXED",
|
||||
Live: "LIVE",
|
||||
Subscriptions: "SUBSCRIPTIONS"
|
||||
Subscriptions: "SUBSCRIPTIONS",
|
||||
Shorts: "SHORTS"
|
||||
},
|
||||
Order: {
|
||||
Chronological: "CHRONOLOGICAL"
|
||||
|
@ -244,6 +245,7 @@ class PlatformVideo extends PlatformContent {
|
|||
this.viewCount = obj.viewCount ?? -1; //Long
|
||||
|
||||
this.isLive = obj.isLive ?? false; //Boolean
|
||||
this.isShort = !!obj.isShort ?? false;
|
||||
}
|
||||
}
|
||||
class PlatformVideoDetails extends PlatformVideo {
|
||||
|
@ -260,6 +262,7 @@ class PlatformVideoDetails extends PlatformVideo {
|
|||
|
||||
this.rating = obj.rating ?? null; //IRating
|
||||
this.subtitles = obj.subtitles ?? [];
|
||||
this.isShort = !!obj.isShort ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ class ResultCapabilities(
|
|||
const val TYPE_POSTS = "POSTS";
|
||||
const val TYPE_MIXED = "MIXED";
|
||||
const val TYPE_SUBSCRIPTIONS = "SUBSCRIPTIONS";
|
||||
const val TYPE_SHORTS = "SHORTS";
|
||||
|
||||
const val ORDER_CHONOLOGICAL = "CHRONOLOGICAL";
|
||||
|
||||
|
|
|
@ -13,4 +13,6 @@ interface IPlatformVideo : IPlatformContent {
|
|||
val viewCount: Long;
|
||||
|
||||
val isLive : Boolean;
|
||||
|
||||
val isShort: Boolean;
|
||||
}
|
|
@ -25,6 +25,7 @@ open class SerializedPlatformVideo(
|
|||
|
||||
override val duration: Long,
|
||||
override val viewCount: Long,
|
||||
override val isShort: Boolean = false
|
||||
) : IPlatformVideo, SerializedPlatformContent {
|
||||
override val contentType: ContentType = ContentType.MEDIA;
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ open class SerializedPlatformVideoDetails(
|
|||
override val video: ISerializedVideoSourceDescriptor,
|
||||
override val preview: ISerializedVideoSourceDescriptor?,
|
||||
|
||||
override val subtitles: List<SubtitleRawSource> = listOf()
|
||||
override val subtitles: List<SubtitleRawSource> = listOf(),
|
||||
override val isShort: Boolean = false
|
||||
) : IPlatformVideo, IPlatformVideoDetails {
|
||||
final override val contentType: ContentType get() = ContentType.MEDIA;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.futo.platformplayer.api.media.models.Thumbnails
|
|||
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||
import com.futo.platformplayer.api.media.models.video.IPlatformVideo
|
||||
import com.futo.platformplayer.api.media.platforms.js.SourcePluginConfig
|
||||
import com.futo.platformplayer.getOrDefault
|
||||
import com.futo.platformplayer.getOrThrow
|
||||
|
||||
open class JSVideo : JSContent, IPlatformVideo, IPluginSourced {
|
||||
|
@ -17,6 +18,7 @@ open class JSVideo : JSContent, IPlatformVideo, IPluginSourced {
|
|||
final override val viewCount: Long;
|
||||
|
||||
final override val isLive: Boolean;
|
||||
final override val isShort: Boolean;
|
||||
|
||||
constructor(config: SourcePluginConfig, obj: V8ValueObject): super(config, obj) {
|
||||
val contextName = "PlatformVideo";
|
||||
|
@ -26,5 +28,6 @@ open class JSVideo : JSContent, IPlatformVideo, IPluginSourced {
|
|||
duration = _content.getOrThrow<Int>(config, "duration", contextName).toLong();
|
||||
viewCount = _content.getOrThrow(config, "viewCount", contextName);
|
||||
isLive = _content.getOrThrow(config, "isLive", contextName);
|
||||
isShort = _content.getOrDefault(config, "isShort", contextName, false) ?: false;
|
||||
}
|
||||
}
|
|
@ -310,6 +310,10 @@ class VideoDownload {
|
|||
if(vsource == null)
|
||||
vsource = VideoHelper.selectBestVideoSource(videoSources, targetPixelCount!!.toInt(), arrayOf())
|
||||
// ?: throw IllegalStateException("Could not find a valid video source for video");
|
||||
if(vsource is JSSource) {
|
||||
this.hasVideoRequestExecutor = this.hasVideoRequestExecutor || vsource.hasRequestExecutor;
|
||||
this.requiresLiveVideoSource = this.hasVideoRequestExecutor || (vsource is JSDashManifestRawSource && vsource.hasGenerate);
|
||||
}
|
||||
|
||||
if(vsource == null) {
|
||||
videoSource = null;
|
||||
|
@ -361,6 +365,12 @@ class VideoDownload {
|
|||
asource = VideoHelper.selectBestAudioSource(audioSources, arrayOf(), null, targetBitrate)
|
||||
?: if(videoSource != null ) null
|
||||
else throw DownloadException("Could not find a valid video or audio source for download")
|
||||
|
||||
if(asource is JSSource) {
|
||||
this.hasVideoRequestExecutor = this.hasVideoRequestExecutor || asource.hasRequestExecutor;
|
||||
this.requiresLiveVideoSource = this.hasVideoRequestExecutor || (asource is JSDashManifestRawSource && asource.hasGenerate);
|
||||
}
|
||||
|
||||
if(asource == null) {
|
||||
audioSource = null;
|
||||
if(!original.video.isUnMuxed || original.video.videoSources.size == 0)
|
||||
|
|
|
@ -70,6 +70,8 @@ class VideoLocal: IPlatformVideoDetails, IStoreItem {
|
|||
|
||||
override val isLive: Boolean get() = videoSerialized.isLive;
|
||||
|
||||
override val isShort: Boolean get() = videoSerialized.isShort;
|
||||
|
||||
//TODO: Offline subtitles
|
||||
override val subtitles: List<ISubtitleSource> = listOf();
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.futo.platformplayer.engine.packages
|
||||
|
||||
import android.media.MediaCodec
|
||||
import android.media.MediaCodecList
|
||||
import com.caoccao.javet.annotations.V8Function
|
||||
import com.caoccao.javet.annotations.V8Property
|
||||
import com.caoccao.javet.utils.JavetResourceUtils
|
||||
|
@ -187,7 +189,44 @@ class PackageBridge : V8Package {
|
|||
return false;
|
||||
}
|
||||
|
||||
@V8Function
|
||||
fun getHardwareCodecs(): List<String>{
|
||||
return getSupportedHardwareMediaCodecs();
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
private const val TAG = "PackageBridge";
|
||||
|
||||
private var _mediaCodecList: MutableList<String> = mutableListOf();
|
||||
private var _mediaCodecListHardware: MutableList<String> = mutableListOf();
|
||||
|
||||
fun getSupportedMediaCodecs(): List<String>{
|
||||
synchronized(_mediaCodecList) {
|
||||
if(_mediaCodecList.size <= 0)
|
||||
updateMediaCodecList();
|
||||
return _mediaCodecList;
|
||||
}
|
||||
}
|
||||
fun getSupportedHardwareMediaCodecs(): List<String>{
|
||||
synchronized(_mediaCodecList) {
|
||||
if(_mediaCodecList.size <= 0)
|
||||
updateMediaCodecList();
|
||||
return _mediaCodecListHardware;
|
||||
}
|
||||
}
|
||||
private fun updateMediaCodecList() {
|
||||
_mediaCodecList.clear();
|
||||
_mediaCodecListHardware.clear();
|
||||
for(codec in MediaCodecList(MediaCodecList.ALL_CODECS).codecInfos) {
|
||||
if(!codec.isEncoder) {
|
||||
_mediaCodecList.add(codec.canonicalName);
|
||||
if (codec.isHardwareAccelerated)
|
||||
_mediaCodecListHardware.add(codec.canonicalName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -25,6 +25,9 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.net.SocketTimeoutException
|
||||
import java.util.concurrent.ForkJoinPool
|
||||
import java.util.concurrent.ForkJoinTask
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
class PackageHttp: V8Package {
|
||||
|
@ -43,6 +46,9 @@ class PackageHttp: V8Package {
|
|||
override val name: String get() = "Http";
|
||||
override val variableName: String get() = "http";
|
||||
|
||||
private var _batchPoolLock: Any = Any();
|
||||
private var _batchPool: ForkJoinPool? = null;
|
||||
|
||||
|
||||
constructor(plugin: V8Plugin, config: IV8PluginConfig): super(plugin) {
|
||||
_config = config;
|
||||
|
@ -52,6 +58,37 @@ class PackageHttp: V8Package {
|
|||
_packageClientAuth = PackageHttpClient(this, _clientAuth);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Automatically adjusting threadpool dedicated per PackageHttp for batch requests.
|
||||
*/
|
||||
private fun <T, R> autoParallelPool(data: List<T>, parallelism: Int, handle: (T)->R): List<Pair<R?, Throwable?>> {
|
||||
synchronized(_batchPoolLock) {
|
||||
val threadsToUse = if (parallelism <= 0) data.size else Math.min(parallelism, data.size);
|
||||
if(_batchPool == null)
|
||||
_batchPool = ForkJoinPool(threadsToUse);
|
||||
var pool = _batchPool ?: return listOf();
|
||||
if(pool.poolSize < threadsToUse) { //Resize pool
|
||||
pool.shutdown();
|
||||
_batchPool = ForkJoinPool(threadsToUse);
|
||||
pool = _batchPool ?: return listOf();
|
||||
}
|
||||
|
||||
val resultTasks = mutableListOf<ForkJoinTask<Pair<R?, Throwable?>>>();
|
||||
for(item in data){
|
||||
resultTasks.add(pool.submit<Pair<R?, Throwable?>> {
|
||||
try {
|
||||
return@submit Pair<R?, Throwable?>(handle(item), null);
|
||||
}
|
||||
catch(ex: Throwable) {
|
||||
return@submit Pair<R?, Throwable?>(null, ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
return resultTasks.map { it.join() };
|
||||
}
|
||||
}
|
||||
|
||||
@V8Function
|
||||
fun newClient(withAuth: Boolean): PackageHttpClient {
|
||||
val httpClient = if(withAuth) _clientAuth.clone() else _client.clone();
|
||||
|
@ -235,16 +272,19 @@ class PackageHttp: V8Package {
|
|||
//Finalizer
|
||||
@V8Function
|
||||
fun execute(): List<IBridgeHttpResponse?> {
|
||||
return _reqs.parallelStream().map {
|
||||
return _package.autoParallelPool(_reqs, -1) {
|
||||
if(it.second.method == "DUMMY")
|
||||
return@map null;
|
||||
return@autoParallelPool null;
|
||||
if(it.second.body != null)
|
||||
return@map it.first.requestWithBody(it.second.method, it.second.url, it.second.body!!, it.second.headers, it.second.respType);
|
||||
return@autoParallelPool it.first.requestWithBody(it.second.method, it.second.url, it.second.body!!, it.second.headers, it.second.respType);
|
||||
else
|
||||
return@map it.first.request(it.second.method, it.second.url, it.second.headers, it.second.respType);
|
||||
}
|
||||
.asSequence()
|
||||
.toList();
|
||||
return@autoParallelPool it.first.request(it.second.method, it.second.url, it.second.headers, it.second.respType);
|
||||
}.map {
|
||||
if(it.second != null)
|
||||
throw it.second!!;
|
||||
else
|
||||
return@map it.first;
|
||||
}.toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -438,11 +478,8 @@ class PackageHttp: V8Package {
|
|||
else {
|
||||
headers?.forEach { (header, values) ->
|
||||
val lowerCaseHeader = header.lowercase()
|
||||
if(lowerCaseHeader == "set-cookie") {
|
||||
result[lowerCaseHeader] = values.filter{
|
||||
!it.lowercase().contains("httponly")
|
||||
};
|
||||
}
|
||||
if(lowerCaseHeader == "set-cookie" && !values.any { it.lowercase().contains("httponly") })
|
||||
result[lowerCaseHeader] = values;
|
||||
else
|
||||
result[lowerCaseHeader] = values;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlin.math.max
|
||||
|
||||
class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
||||
class ChannelContentsFragment(private val subType: String? = null) : Fragment(), IChannelTabFragment {
|
||||
private var _recyclerResults: RecyclerView? = null;
|
||||
private var _glmVideo: GridLayoutManager? = null;
|
||||
private var _loading = false;
|
||||
|
@ -73,9 +73,12 @@ class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
|||
if (lastPolycentricProfile != null)
|
||||
pager= StatePolycentric.instance.getChannelContent(lifecycleScope, lastPolycentricProfile);
|
||||
|
||||
if(pager == null)
|
||||
pager = StatePlatform.instance.getChannelContent(channel.url);
|
||||
|
||||
if(pager == null) {
|
||||
if(subType != null)
|
||||
pager = StatePlatform.instance.getChannelContent(channel.url, subType);
|
||||
else
|
||||
pager = StatePlatform.instance.getChannelContent(channel.url);
|
||||
}
|
||||
return pager;
|
||||
}
|
||||
|
||||
|
@ -367,6 +370,6 @@ class ChannelContentsFragment : Fragment(), IChannelTabFragment {
|
|||
|
||||
companion object {
|
||||
val TAG = "VideoListFragment";
|
||||
fun newInstance() = ChannelContentsFragment().apply { }
|
||||
fun newInstance(subType: String? = null) = ChannelContentsFragment(subType).apply { }
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import com.futo.platformplayer.UISlideOverlays
|
|||
import com.futo.platformplayer.api.media.PlatformID
|
||||
import com.futo.platformplayer.api.media.exceptions.NoPlatformClientException
|
||||
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
||||
import com.futo.platformplayer.api.media.models.ResultCapabilities
|
||||
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
||||
import com.futo.platformplayer.api.media.models.channels.SerializedChannel
|
||||
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||
|
@ -457,6 +458,12 @@ class ChannelFragment : MainFragment() {
|
|||
|
||||
_fragment.topBar?.assume<NavigationTopBarFragment>()?.setMenuItems(buttons)
|
||||
}
|
||||
if(plugin != null && plugin.capabilities.hasGetChannelCapabilities) {
|
||||
if(plugin.getChannelCapabilities()?.types?.contains(ResultCapabilities.TYPE_SHORTS) ?: false &&
|
||||
!(_viewPager.adapter as ChannelViewPagerAdapter).containsItem(ChannelTab.SHORTS.ordinal.toLong())) {
|
||||
(_viewPager.adapter as ChannelViewPagerAdapter).insert(1, ChannelTab.SHORTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ class TutorialFragment : MainFragment() {
|
|||
override val rating: IRating = RatingLikes(-1)
|
||||
override val viewCount: Long = -1
|
||||
override val video: IVideoSourceDescriptor = TutorialVideoSourceDescriptor(videoUrl, duration, width, height)
|
||||
override val isShort: Boolean = false;
|
||||
override fun getComments(client: IPlatformClient): IPager<IPlatformComment> {
|
||||
return EmptyPager()
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import androidx.fragment.app.FragmentManager
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.futo.platformplayer.api.media.models.PlatformAuthorLink
|
||||
import com.futo.platformplayer.api.media.models.ResultCapabilities
|
||||
import com.futo.platformplayer.api.media.models.channels.IPlatformChannel
|
||||
import com.futo.platformplayer.api.media.models.contents.ContentType
|
||||
import com.futo.platformplayer.api.media.models.contents.IPlatformContent
|
||||
|
@ -21,7 +22,7 @@ import com.google.android.material.tabs.TabLayout
|
|||
|
||||
|
||||
enum class ChannelTab {
|
||||
VIDEOS, CHANNELS, PLAYLISTS, SUPPORT, ABOUT
|
||||
VIDEOS, SHORTS, CHANNELS, PLAYLISTS, SUPPORT, ABOUT
|
||||
}
|
||||
|
||||
class ChannelViewPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle) :
|
||||
|
@ -91,6 +92,19 @@ class ChannelViewPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifec
|
|||
}
|
||||
}
|
||||
|
||||
ChannelTab.SHORTS -> {
|
||||
fragment = ChannelContentsFragment.newInstance(ResultCapabilities.TYPE_SHORTS).apply {
|
||||
onContentClicked.subscribe(this@ChannelViewPagerAdapter.onContentClicked::emit)
|
||||
onContentUrlClicked.subscribe(this@ChannelViewPagerAdapter.onContentUrlClicked::emit)
|
||||
onUrlClicked.subscribe(this@ChannelViewPagerAdapter.onUrlClicked::emit)
|
||||
onChannelClicked.subscribe(this@ChannelViewPagerAdapter.onChannelClicked::emit)
|
||||
onAddToClicked.subscribe(this@ChannelViewPagerAdapter.onAddToClicked::emit)
|
||||
onAddToQueueClicked.subscribe(this@ChannelViewPagerAdapter.onAddToQueueClicked::emit)
|
||||
onAddToWatchLaterClicked.subscribe(this@ChannelViewPagerAdapter.onAddToWatchLaterClicked::emit)
|
||||
onLongPress.subscribe(this@ChannelViewPagerAdapter.onLongPress::emit)
|
||||
}
|
||||
}
|
||||
|
||||
ChannelTab.CHANNELS -> {
|
||||
fragment = ChannelListFragment.newInstance()
|
||||
.apply { onClickChannel.subscribe(onChannelClicked::emit) }
|
||||
|
|
Loading…
Add table
Reference in a new issue