Skip to content

Commit 718ff0f

Browse files
haggaieProfpatsch
authored andcommitted
media browser: pass media ID to parsing error exceptions
1 parent ae2003a commit 718ff0f

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.kt

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
308308
}
309309
}
310310
Log.w(TAG, "Unknown playlist URI: " + parentId)
311-
throw parseError()
311+
throw parseError(parentId)
312312
}
313313

314314
ID_HISTORY -> return populateHistory()
315-
else -> throw parseError()
315+
else -> throw parseError(parentId)
316316
}
317317
} catch (e: ContentNotAvailableException) {
318318
return Single.error(e)
@@ -518,31 +518,33 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
518518
)
519519
}
520520

521-
private fun extractPlayQueueFromMediaId(mediaId: String?): Single<PlayQueue> {
521+
private fun extractPlayQueueFromMediaId(mediaId: String): Single<PlayQueue> {
522522
try {
523523
val mediaIdUri = Uri.parse(mediaId)
524524
val path: MutableList<String> = ArrayList<String>(mediaIdUri.pathSegments)
525525

526526
if (path.isEmpty()) {
527-
throw parseError()
527+
throw parseError(mediaId)
528528
}
529529

530530
val uriType: String? = path.get(0)
531531
path.removeAt(0)
532532

533533
return when (uriType) {
534534
ID_BOOKMARKS -> extractPlayQueueFromPlaylistMediaId(
535+
mediaId,
535536
path,
536537
mediaIdUri.getQueryParameter(ID_URL)
537538
)
538539

539-
ID_HISTORY -> extractPlayQueueFromHistoryMediaId(path)
540+
ID_HISTORY -> extractPlayQueueFromHistoryMediaId(mediaId, path)
540541
ID_INFO_ITEM -> extractPlayQueueFromInfoItemMediaId(
542+
mediaId,
541543
path,
542544
mediaIdUri.getQueryParameter(ID_URL)
543545
)
544546

545-
else -> throw parseError()
547+
else -> throw parseError(mediaId)
546548
}
547549
} catch (e: ContentNotAvailableException) {
548550
return Single.error(e)
@@ -551,11 +553,12 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
551553

552554
@Throws(ContentNotAvailableException::class)
553555
private fun extractPlayQueueFromPlaylistMediaId(
556+
mediaId: String,
554557
path: MutableList<String>,
555558
url: String?
556559
): Single<PlayQueue> {
557560
if (path.isEmpty()) {
558-
throw parseError()
561+
throw parseError(mediaId)
559562
}
560563

561564
val playlistType = path.get(0)
@@ -564,7 +567,7 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
564567
when (playlistType) {
565568
ID_LOCAL, ID_REMOTE -> {
566569
if (path.size != 2) {
567-
throw parseError()
570+
throw parseError(mediaId)
568571
}
569572
val playlistId = path.get(0).toLong()
570573
val index = path.get(1).toInt()
@@ -576,24 +579,25 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
576579

577580
ID_URL -> {
578581
if (path.size != 1) {
579-
throw parseError()
582+
throw parseError(mediaId)
580583
}
581584

582585
val serviceId = path.get(0).toInt()
583586
return ExtractorHelper.getPlaylistInfo(serviceId, url, false)
584587
.map<PlayQueue>({ info: PlaylistInfo? -> PlaylistPlayQueue(info) })
585588
}
586589

587-
else -> throw parseError()
590+
else -> throw parseError(mediaId)
588591
}
589592
}
590593

591594
@Throws(ContentNotAvailableException::class)
592595
private fun extractPlayQueueFromHistoryMediaId(
596+
mediaId: String,
593597
path: List<String>
594598
): Single<PlayQueue> {
595599
if (path.size != 1) {
596-
throw parseError()
600+
throw parseError(mediaId)
597601
}
598602

599603
val streamId = path.get(0).toLong()
@@ -793,17 +797,18 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
793797
}
794798
}
795799

796-
private fun parseError(): ContentNotAvailableException {
797-
return ContentNotAvailableException("Failed to parse media ID")
800+
private fun parseError(mediaId: String): ContentNotAvailableException {
801+
return ContentNotAvailableException("Failed to parse media ID $mediaId")
798802
}
799803

800804
@Throws(ContentNotAvailableException::class)
801805
private fun extractPlayQueueFromInfoItemMediaId(
806+
mediaId: String,
802807
path: List<String>,
803808
url: String?
804809
): Single<PlayQueue> {
805810
if (path.size != 2) {
806-
throw parseError()
811+
throw parseError(mediaId)
807812
}
808813
val infoItemType = infoItemTypeFromString(path.get(0))
809814
val serviceId = path.get(1).toInt()
@@ -832,7 +837,7 @@ class MediaBrowserConnector(playerService: PlayerService) : PlaybackPreparer {
832837
}
833838
}
834839

835-
else -> throw parseError()
840+
else -> throw parseError(mediaId)
836841
}
837842
}
838843
}

0 commit comments

Comments
 (0)