Skip to content

Commit

Permalink
Cleanup MediaCCCLiveStreamExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
litetex committed Jun 24, 2022
1 parent 60488db commit b66323d
Showing 1 changed file with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -159,53 +160,54 @@ private String getManifestOfDeliveryMethodWanted(@Nonnull final String deliveryM
public List<AudioStream> 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());
}

@Override
public List<VideoAudioStream> 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<MediaCCCLiveStreamMapperDTO> getStreamDTOs(@Nonnull final String streamType) {
return room.getArray(STREAMS).stream()
// Ensure that we use only process JsonObjects
Expand Down

0 comments on commit b66323d

Please sign in to comment.