|
24 | 24 |
|
25 | 25 | import java.io.IOException; |
26 | 26 | import java.util.List; |
| 27 | +import java.util.Objects; |
27 | 28 | import java.util.stream.Collectors; |
28 | 29 | import java.util.stream.Stream; |
29 | 30 |
|
@@ -159,53 +160,54 @@ private String getManifestOfDeliveryMethodWanted(@Nonnull final String deliveryM |
159 | 160 | public List<AudioStream> getAudioStreams() throws IOException, ExtractionException { |
160 | 161 | return getStreamDTOs("audio") |
161 | 162 | .map(dto -> { |
162 | | - final String url = dto.getUrlValue().getString(URL); |
163 | | - final DeliveryData deliveryData; |
164 | | - if ("hls".equals(dto.getUrlKey())) { |
165 | | - deliveryData = new SimpleHLSDeliveryDataImpl(url); |
166 | | - } else if ("dash".equals(dto.getUrlKey())) { |
167 | | - deliveryData = new SimpleDASHUrlDeliveryDataImpl(url); |
168 | | - } else { |
169 | | - deliveryData = new SimpleProgressiveHTTPDeliveryDataImpl(url); |
| 163 | + try { |
| 164 | + return new SimpleAudioStreamImpl( |
| 165 | + new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()), |
| 166 | + buildDeliveryData(dto) |
| 167 | + ); |
| 168 | + } catch (final Exception ignored) { |
| 169 | + return null; |
170 | 170 | } |
171 | | - |
172 | | - return new SimpleAudioStreamImpl( |
173 | | - // TODO: This looks wrong |
174 | | - new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()), |
175 | | - deliveryData |
176 | | - ); |
177 | 171 | }) |
| 172 | + .filter(Objects::nonNull) |
178 | 173 | .collect(Collectors.toList()); |
179 | 174 | } |
180 | 175 |
|
181 | 176 | @Override |
182 | 177 | public List<VideoAudioStream> getVideoStreams() throws IOException, ExtractionException { |
183 | 178 | return getStreamDTOs("video") |
184 | 179 | .map(dto -> { |
185 | | - final String url = dto.getUrlValue().getString(URL); |
186 | | - final DeliveryData deliveryData; |
187 | | - if ("hls".equals(dto.getUrlKey())) { |
188 | | - deliveryData = new SimpleHLSDeliveryDataImpl(url); |
189 | | - } else if ("dash".equals(dto.getUrlKey())) { |
190 | | - deliveryData = new SimpleDASHUrlDeliveryDataImpl(url); |
191 | | - } else { |
192 | | - deliveryData = new SimpleProgressiveHTTPDeliveryDataImpl(url); |
| 180 | + try { |
| 181 | + final JsonArray videoSize = |
| 182 | + dto.getStreamJsonObj().getArray("videoSize"); |
| 183 | + |
| 184 | + return new SimpleVideoAudioStreamImpl( |
| 185 | + // TODO: This looks wrong |
| 186 | + new VideoAudioFormatRegistry() |
| 187 | + .getFromSuffixOrThrow(dto.getUrlKey()), |
| 188 | + buildDeliveryData(dto), |
| 189 | + VideoQualityData.fromHeightWidth( |
| 190 | + videoSize.getInt(1, VideoQualityData.UNKNOWN), |
| 191 | + videoSize.getInt(0, VideoQualityData.UNKNOWN)) |
| 192 | + ); |
| 193 | + } catch (final Exception ignored) { |
| 194 | + return null; |
193 | 195 | } |
194 | | - |
195 | | - final JsonArray videoSize = dto.getStreamJsonObj().getArray("videoSize"); |
196 | | - |
197 | | - return new SimpleVideoAudioStreamImpl( |
198 | | - // TODO: This looks wrong |
199 | | - new VideoAudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()), |
200 | | - deliveryData, |
201 | | - VideoQualityData.fromHeightWidth( |
202 | | - /*height=*/videoSize.getInt(1, VideoQualityData.UNKNOWN), |
203 | | - /*width=*/videoSize.getInt(0, VideoQualityData.UNKNOWN)) |
204 | | - ); |
205 | 196 | }) |
| 197 | + .filter(Objects::nonNull) |
206 | 198 | .collect(Collectors.toList()); |
207 | 199 | } |
208 | 200 |
|
| 201 | + private DeliveryData buildDeliveryData(final MediaCCCLiveStreamMapperDTO dto) { |
| 202 | + final String url = dto.getUrlValue().getString(URL); |
| 203 | + if ("hls".equals(dto.getUrlKey())) { |
| 204 | + return new SimpleHLSDeliveryDataImpl(url); |
| 205 | + } else if ("dash".equals(dto.getUrlKey())) { |
| 206 | + return new SimpleDASHUrlDeliveryDataImpl(url); |
| 207 | + } |
| 208 | + return new SimpleProgressiveHTTPDeliveryDataImpl(url); |
| 209 | + } |
| 210 | + |
209 | 211 | private Stream<MediaCCCLiveStreamMapperDTO> getStreamDTOs(@Nonnull final String streamType) { |
210 | 212 | return room.getArray(STREAMS).stream() |
211 | 213 | // Ensure that we use only process JsonObjects |
|
0 commit comments