Cleanup ``MediaCCCLiveStreamExtractor``

This commit is contained in:
litetex 2022-06-24 21:21:59 +02:00
parent 3f1f2b291c
commit 53909820f8
1 changed files with 35 additions and 33 deletions

View File

@ -27,6 +27,7 @@ import org.schabi.newpipe.extractor.streamdata.stream.simpleimpl.SimpleVideoAudi
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -162,22 +163,16 @@ public class MediaCCCLiveStreamExtractor extends StreamExtractor {
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException { public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
return getStreamDTOs("audio") return getStreamDTOs("audio")
.map(dto -> { .map(dto -> {
final String url = dto.getUrlValue().getString(URL); try {
final DeliveryData deliveryData; return new SimpleAudioStreamImpl(
if ("hls".equals(dto.getUrlKey())) { new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()),
deliveryData = new SimpleHLSDeliveryDataImpl(url); buildDeliveryData(dto)
} else if ("dash".equals(dto.getUrlKey())) { );
deliveryData = new SimpleDASHUrlDeliveryDataImpl(url); } catch (final Exception ignored) {
} else { return null;
deliveryData = new SimpleProgressiveHTTPDeliveryDataImpl(url);
} }
return new SimpleAudioStreamImpl(
// TODO: This looks wrong
new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()),
deliveryData
);
}) })
.filter(Objects::nonNull)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -185,30 +180,37 @@ public class MediaCCCLiveStreamExtractor extends StreamExtractor {
public List<VideoAudioStream> getVideoStreams() throws IOException, ExtractionException { public List<VideoAudioStream> getVideoStreams() throws IOException, ExtractionException {
return getStreamDTOs("video") return getStreamDTOs("video")
.map(dto -> { .map(dto -> {
final String url = dto.getUrlValue().getString(URL); try {
final DeliveryData deliveryData; final JsonArray videoSize =
if ("hls".equals(dto.getUrlKey())) { dto.getStreamJsonObj().getArray("videoSize");
deliveryData = new SimpleHLSDeliveryDataImpl(url);
} else if ("dash".equals(dto.getUrlKey())) { return new SimpleVideoAudioStreamImpl(
deliveryData = new SimpleDASHUrlDeliveryDataImpl(url); // TODO: This looks wrong
} else { new VideoAudioFormatRegistry()
deliveryData = new SimpleProgressiveHTTPDeliveryDataImpl(url); .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()); .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<MediaCCCLiveStreamMapperDTO> getStreamDTOs(@Nonnull final String streamType) { private Stream<MediaCCCLiveStreamMapperDTO> getStreamDTOs(@Nonnull final String streamType) {
return room.getArray(STREAMS).stream() return room.getArray(STREAMS).stream()
// Ensure that we use only process JsonObjects // Ensure that we use only process JsonObjects