Skip to content

Commit

Permalink
media browser: pass media ID to parsing error exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
haggaie authored and snaik20 committed Dec 6, 2024
1 parent fad463a commit b462c97
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
}
}
Log.w(TAG, "Unknown playlist URI: $parentId")
throw parseError()
throw parseError(parentId)
}

ID_HISTORY -> return populateHistory()
else -> throw parseError()
else -> throw parseError(parentId)
}
} catch (e: ContentNotAvailableException) {
return Single.error(e)
Expand Down Expand Up @@ -432,25 +432,27 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
val path = ArrayList(mediaIdUri.pathSegments)

if (path.isEmpty()) {
throw parseError()
throw parseError(mediaId)
}

val uriType = path[0]
path.removeAt(0)

return when (uriType) {
ID_BOOKMARKS -> extractPlayQueueFromPlaylistMediaId(
mediaId,
path,
mediaIdUri.getQueryParameter(ID_URL)
)

ID_HISTORY -> extractPlayQueueFromHistoryMediaId(path)
ID_HISTORY -> extractPlayQueueFromHistoryMediaId(mediaId, path)
ID_INFO_ITEM -> extractPlayQueueFromInfoItemMediaId(
mediaId,
path,
mediaIdUri.getQueryParameter(ID_URL)
)

else -> throw parseError()
else -> throw parseError(mediaId)
}
} catch (error: ContentNotAvailableException) {
return Single.error(error)
Expand All @@ -459,11 +461,12 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback

@Throws(ContentNotAvailableException::class)
private fun extractPlayQueueFromPlaylistMediaId(
mediaId: String,
mediaIdSegments: ArrayList<String>,
url: String?,
): Single<PlayQueue> {
if (mediaIdSegments.isEmpty()) {
throw parseError()
throw parseError(mediaId)
}

val playlistType = mediaIdSegments.first()
Expand All @@ -472,7 +475,7 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
when (playlistType) {
ID_LOCAL, ID_REMOTE -> {
if (mediaIdSegments.size != 2) {
throw parseError()
throw parseError(mediaId)
}
val playlistId = mediaIdSegments[0].toLong()
val index = mediaIdSegments[1].toInt()
Expand All @@ -485,7 +488,7 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback

ID_URL -> {
if (mediaIdSegments.size != 1) {
throw parseError()
throw parseError(mediaId)
}

val serviceId = mediaIdSegments[0].toInt()
Expand All @@ -494,16 +497,17 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
.map(::PlaylistPlayQueue)
}

else -> throw parseError()
else -> throw parseError(mediaId)
}
}

@Throws(ContentNotAvailableException::class)
private fun extractPlayQueueFromHistoryMediaId(
mediaId: String,
path: List<String>
): Single<PlayQueue> {
if (path.size != 1) {
throw parseError()
throw parseError(mediaId)
}

val streamId = path[0].toLong()
Expand Down Expand Up @@ -692,17 +696,18 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
}
}

private fun parseError(): ContentNotAvailableException {
return ContentNotAvailableException("Failed to parse media ID")
private fun parseError(mediaId: String): ContentNotAvailableException {
return ContentNotAvailableException("Failed to parse media ID $mediaId")
}

@Throws(ContentNotAvailableException::class)
private fun extractPlayQueueFromInfoItemMediaId(
mediaId: String,
path: List<String>,
url: String?
): Single<PlayQueue> {
if (path.size != 2) {
throw parseError()
throw parseError(mediaId)
}
val infoItemType = infoItemTypeFromString(path[0])
val serviceId = path[1].toInt()
Expand All @@ -729,7 +734,7 @@ class MediaBrowserConnector(private val playerService: PlayerService) : Playback
}
}

else -> throw parseError()
else -> throw parseError(mediaId)
}
}
}
Expand Down

0 comments on commit b462c97

Please sign in to comment.