mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-08-05 21:43:53 +00:00
Properly handle item errors during media browser loading
Non-item errors, i.e. critical parsing errors of the page, are still handled properly.
This commit is contained in:
parent
dc62d211f5
commit
e5458bcb14
@ -13,7 +13,6 @@ import androidx.media.MediaBrowserServiceCompat.Result
|
|||||||
import androidx.media.utils.MediaConstants
|
import androidx.media.utils.MediaConstants
|
||||||
import io.reactivex.rxjava3.core.Flowable
|
import io.reactivex.rxjava3.core.Flowable
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import io.reactivex.rxjava3.core.SingleSource
|
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import io.reactivex.rxjava3.schedulers.Schedulers
|
import io.reactivex.rxjava3.schedulers.Schedulers
|
||||||
import org.schabi.newpipe.MainActivity.DEBUG
|
import org.schabi.newpipe.MainActivity.DEBUG
|
||||||
@ -25,10 +24,8 @@ import org.schabi.newpipe.database.playlist.PlaylistStreamEntry
|
|||||||
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity
|
import org.schabi.newpipe.database.playlist.model.PlaylistRemoteEntity
|
||||||
import org.schabi.newpipe.extractor.InfoItem
|
import org.schabi.newpipe.extractor.InfoItem
|
||||||
import org.schabi.newpipe.extractor.InfoItem.InfoType
|
import org.schabi.newpipe.extractor.InfoItem.InfoType
|
||||||
import org.schabi.newpipe.extractor.ListInfo
|
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException
|
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
|
||||||
import org.schabi.newpipe.extractor.search.SearchInfo
|
import org.schabi.newpipe.extractor.search.SearchInfo
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem
|
||||||
@ -86,6 +83,10 @@ class MediaBrowserImpl(
|
|||||||
|
|
||||||
//region onLoadChildren
|
//region onLoadChildren
|
||||||
fun onLoadChildren(parentId: String, result: Result<List<MediaBrowserCompat.MediaItem>>) {
|
fun onLoadChildren(parentId: String, result: Result<List<MediaBrowserCompat.MediaItem>>) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onLoadChildren($parentId)")
|
||||||
|
}
|
||||||
|
|
||||||
result.detach() // allows sendResult() to happen later
|
result.detach() // allows sendResult() to happen later
|
||||||
disposables.add(
|
disposables.add(
|
||||||
onLoadChildren(parentId)
|
onLoadChildren(parentId)
|
||||||
@ -101,10 +102,6 @@ class MediaBrowserImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun onLoadChildren(parentId: String): Single<List<MediaBrowserCompat.MediaItem>> {
|
private fun onLoadChildren(parentId: String): Single<List<MediaBrowserCompat.MediaItem>> {
|
||||||
if (DEBUG) {
|
|
||||||
Log.d(TAG, "onLoadChildren($parentId)")
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val parentIdUri = Uri.parse(parentId)
|
val parentIdUri = Uri.parse(parentId)
|
||||||
val path = ArrayList(parentIdUri.pathSegments)
|
val path = ArrayList(parentIdUri.pathSegments)
|
||||||
@ -353,15 +350,12 @@ class MediaBrowserImpl(
|
|||||||
private fun populateRemotePlaylist(playlistId: Long): Single<List<MediaBrowserCompat.MediaItem>> {
|
private fun populateRemotePlaylist(playlistId: Long): Single<List<MediaBrowserCompat.MediaItem>> {
|
||||||
return RemotePlaylistManager(database).getPlaylist(playlistId).firstOrError()
|
return RemotePlaylistManager(database).getPlaylist(playlistId).firstOrError()
|
||||||
.flatMap { ExtractorHelper.getPlaylistInfo(it.serviceId, it.url, false) }
|
.flatMap { ExtractorHelper.getPlaylistInfo(it.serviceId, it.url, false) }
|
||||||
.flatMap { info ->
|
.map {
|
||||||
info.errors.firstOrNull { it !is ContentNotSupportedException }?.let {
|
// ignore it.errors, i.e. ignore errors about specific items, since there would
|
||||||
return@flatMap Single.error(it)
|
// be no way to show the error properly in Android Auto anyway
|
||||||
}
|
it.relatedItems.mapIndexed { index, item ->
|
||||||
Single.just(
|
|
||||||
info.relatedItems.mapIndexed { index, item ->
|
|
||||||
createRemotePlaylistStreamMediaItem(playlistId, item, index)
|
createRemotePlaylistStreamMediaItem(playlistId, item, index)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
@ -371,10 +365,16 @@ class MediaBrowserImpl(
|
|||||||
query: String,
|
query: String,
|
||||||
result: Result<List<MediaBrowserCompat.MediaItem>>
|
result: Result<List<MediaBrowserCompat.MediaItem>>
|
||||||
) {
|
) {
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "onSearch($query)")
|
||||||
|
}
|
||||||
|
|
||||||
result.detach() // allows sendResult() to happen later
|
result.detach() // allows sendResult() to happen later
|
||||||
disposables.add(
|
disposables.add(
|
||||||
searchMusicBySongTitle(query)
|
searchMusicBySongTitle(query)
|
||||||
.flatMap { this.mediaItemsFromInfoItemList(it) }
|
// ignore it.errors, i.e. ignore errors about specific items, since there would
|
||||||
|
// be no way to show the error properly in Android Auto anyway
|
||||||
|
.map { it.relatedItems.mapNotNull(this::createInfoItemMediaItem) }
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe(
|
.subscribe(
|
||||||
{ result.sendResult(it) },
|
{ result.sendResult(it) },
|
||||||
@ -391,20 +391,6 @@ class MediaBrowserImpl(
|
|||||||
val serviceId = ServiceHelper.getSelectedServiceId(context)
|
val serviceId = ServiceHelper.getSelectedServiceId(context)
|
||||||
return ExtractorHelper.searchFor(serviceId, query, listOf(), "")
|
return ExtractorHelper.searchFor(serviceId, query, listOf(), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun mediaItemsFromInfoItemList(
|
|
||||||
result: ListInfo<InfoItem>
|
|
||||||
): SingleSource<List<MediaBrowserCompat.MediaItem>> {
|
|
||||||
result.errors.firstOrNull()?.let { return@mediaItemsFromInfoItemList Single.error(it) }
|
|
||||||
|
|
||||||
return try {
|
|
||||||
Single.just(
|
|
||||||
result.relatedItems.mapNotNull { item -> this.createInfoItemMediaItem(item) }
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Single.error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -17,7 +17,6 @@ import org.schabi.newpipe.NewPipeDatabase
|
|||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.extractor.InfoItem.InfoType
|
import org.schabi.newpipe.extractor.InfoItem.InfoType
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException
|
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler
|
||||||
import org.schabi.newpipe.local.playlist.LocalPlaylistManager
|
import org.schabi.newpipe.local.playlist.LocalPlaylistManager
|
||||||
import org.schabi.newpipe.local.playlist.RemotePlaylistManager
|
import org.schabi.newpipe.local.playlist.RemotePlaylistManager
|
||||||
@ -131,12 +130,9 @@ class MediaBrowserPlaybackPreparer(
|
|||||||
private fun extractRemotePlayQueue(playlistId: Long, index: Int): Single<PlayQueue> {
|
private fun extractRemotePlayQueue(playlistId: Long, index: Int): Single<PlayQueue> {
|
||||||
return RemotePlaylistManager(database).getPlaylist(playlistId).firstOrError()
|
return RemotePlaylistManager(database).getPlaylist(playlistId).firstOrError()
|
||||||
.flatMap { ExtractorHelper.getPlaylistInfo(it.serviceId, it.url, false) }
|
.flatMap { ExtractorHelper.getPlaylistInfo(it.serviceId, it.url, false) }
|
||||||
.flatMap { info ->
|
// ignore info.errors, i.e. ignore errors about specific items, since there would
|
||||||
info.errors.firstOrNull { it !is ContentNotSupportedException }?.let {
|
// be no way to show the error properly in Android Auto anyway
|
||||||
return@flatMap Single.error(it)
|
.map { info -> PlaylistPlayQueue(info, index) }
|
||||||
}
|
|
||||||
Single.just(PlaylistPlayQueue(info, index))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractPlayQueueFromMediaId(mediaId: String): Single<PlayQueue> {
|
private fun extractPlayQueueFromMediaId(mediaId: String): Single<PlayQueue> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user