diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java index 55e159cdb8..10a4fe9419 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -159,22 +160,16 @@ private String getManifestOfDeliveryMethodWanted(@Nonnull final String deliveryM public List getAudioStreams() throws IOException, ExtractionException { return getStreamDTOs("audio") .map(dto -> { - final String url = dto.getUrlValue().getString(URL); - final DeliveryData deliveryData; - if ("hls".equals(dto.getUrlKey())) { - deliveryData = new SimpleHLSDeliveryDataImpl(url); - } else if ("dash".equals(dto.getUrlKey())) { - deliveryData = new SimpleDASHUrlDeliveryDataImpl(url); - } else { - deliveryData = new SimpleProgressiveHTTPDeliveryDataImpl(url); + try { + return new SimpleAudioStreamImpl( + new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()), + buildDeliveryData(dto) + ); + } catch (final Exception ignored) { + return null; } - - return new SimpleAudioStreamImpl( - // TODO: This looks wrong - new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()), - deliveryData - ); }) + .filter(Objects::nonNull) .collect(Collectors.toList()); } @@ -182,30 +177,37 @@ public List getAudioStreams() throws IOException, ExtractionExcepti public List getVideoStreams() throws IOException, ExtractionException { return getStreamDTOs("video") .map(dto -> { - final String url = dto.getUrlValue().getString(URL); - final DeliveryData deliveryData; - if ("hls".equals(dto.getUrlKey())) { - deliveryData = new SimpleHLSDeliveryDataImpl(url); - } else if ("dash".equals(dto.getUrlKey())) { - deliveryData = new SimpleDASHUrlDeliveryDataImpl(url); - } else { - deliveryData = new SimpleProgressiveHTTPDeliveryDataImpl(url); + try { + final JsonArray videoSize = + dto.getStreamJsonObj().getArray("videoSize"); + + return new SimpleVideoAudioStreamImpl( + // TODO: This looks wrong + new VideoAudioFormatRegistry() + .getFromSuffixOrThrow(dto.getUrlKey()), + buildDeliveryData(dto), + VideoQualityData.fromHeightWidth( + videoSize.getInt(1, VideoQualityData.UNKNOWN), + videoSize.getInt(0, VideoQualityData.UNKNOWN)) + ); + } catch (final Exception ignored) { + return null; } - - final JsonArray videoSize = dto.getStreamJsonObj().getArray("videoSize"); - - return new SimpleVideoAudioStreamImpl( - // TODO: This looks wrong - new VideoAudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()), - deliveryData, - VideoQualityData.fromHeightWidth( - /*height=*/videoSize.getInt(1, VideoQualityData.UNKNOWN), - /*width=*/videoSize.getInt(0, VideoQualityData.UNKNOWN)) - ); }) + .filter(Objects::nonNull) .collect(Collectors.toList()); } + private DeliveryData buildDeliveryData(final MediaCCCLiveStreamMapperDTO dto) { + final String url = dto.getUrlValue().getString(URL); + if ("hls".equals(dto.getUrlKey())) { + return new SimpleHLSDeliveryDataImpl(url); + } else if ("dash".equals(dto.getUrlKey())) { + return new SimpleDASHUrlDeliveryDataImpl(url); + } + return new SimpleProgressiveHTTPDeliveryDataImpl(url); + } + private Stream getStreamDTOs(@Nonnull final String streamType) { return room.getArray(STREAMS).stream() // Ensure that we use only process JsonObjects