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