Skip to content

Commit 5434c0b

Browse files
committed
Made code non-nullable (MediaFormatRegistry)
1 parent f8aae59 commit 5434c0b

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCLiveStreamExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
171171

172172
return new SimpleAudioStreamImpl(
173173
// TODO: This looks wrong
174-
new AudioFormatRegistry().getFromSuffix(dto.getUrlKey()),
174+
new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()),
175175
deliveryData
176176
);
177177
})
@@ -196,7 +196,7 @@ public List<VideoAudioStream> getVideoStreams() throws IOException, ExtractionEx
196196

197197
return new SimpleVideoAudioStreamImpl(
198198
// TODO: This looks wrong
199-
new VideoAudioFormatRegistry().getFromSuffix(dto.getUrlKey()),
199+
new VideoAudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()),
200200
deliveryData,
201201
VideoQualityData.fromHeightWidth(
202202
/*height=*/videoSize.getInt(1, VideoQualityData.UNKNOWN),

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public String getUploaderAvatarUrl() {
9898
public List<AudioStream> getAudioStreams() throws ExtractionException {
9999
return getRecordingsByMimeType("audio")
100100
.map(o -> new SimpleAudioStreamImpl(
101-
new AudioFormatRegistry().getFromMimeType(o.getString("mime_type")),
101+
new AudioFormatRegistry().getFromMimeTypeOrThrow(o.getString("mime_type")),
102102
new SimpleProgressiveHTTPDeliveryDataImpl(o.getString("recording_url"))
103103
))
104104
.collect(Collectors.toList());
@@ -108,7 +108,8 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
108108
public List<VideoAudioStream> getVideoStreams() throws ExtractionException {
109109
return getRecordingsByMimeType("video")
110110
.map(o -> new SimpleVideoAudioStreamImpl(
111-
new VideoAudioFormatRegistry().getFromMimeType(o.getString("mime_type")),
111+
new VideoAudioFormatRegistry()
112+
.getFromMimeTypeOrThrow(o.getString("mime_type")),
112113
new SimpleProgressiveHTTPDeliveryDataImpl(o.getString("recording_url")),
113114
VideoQualityData.fromHeightWidth(
114115
o.getInt("height", VideoQualityData.UNKNOWN),

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ private void tryExtractSubtitles() {
403403
return new SimpleSubtitleStreamImpl(
404404
// TODO: Check for null
405405
new SubtitleFormatRegistry()
406-
.getFromSuffix(
406+
.getFromSuffixOrThrow(
407407
url.substring(url.lastIndexOf(".") + 1)),
408408
new SimpleProgressiveHTTPDeliveryDataImpl(url),
409409
false,
@@ -498,7 +498,7 @@ private void addStreamsFromArray(
498498
playlistUrl,
499499
(s, dd) -> new SimpleAudioStreamImpl(
500500
new AudioFormatRegistry()
501-
.getFromSuffix(getExtensionFromStream(s)),
501+
.getFromSuffixOrThrow(getExtensionFromStream(s)),
502502
dd
503503
)
504504
);
@@ -511,7 +511,7 @@ private void addStreamsFromArray(
511511
playlistUrl,
512512
(s, dd) -> new SimpleVideoAudioStreamImpl(
513513
new VideoAudioFormatRegistry()
514-
.getFromSuffix(getExtensionFromStream(s)),
514+
.getFromSuffixOrThrow(getExtensionFromStream(s)),
515515
dd,
516516
VideoQualityData.fromHeightFps(
517517
resJson.getInt("id", VideoQualityData.UNKNOWN),

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ private Optional<AudioStream> extractDownloadableFileIfAvailable() {
334334
}
335335

336336
return Optional.of(new SimpleAudioStreamImpl(
337-
new AudioFormatRegistry().getFromSuffix(fileType),
337+
new AudioFormatRegistry().getFromSuffixOrThrow(fileType),
338338
new SimpleProgressiveHTTPDeliveryDataImpl(downloadUrl)
339339
));
340340
} catch (final Exception ignored) {

extractor/src/main/java/org/schabi/newpipe/extractor/streamdata/format/registry/MediaFormatRegistry.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,29 @@ public String getMimeById(final int id) {
5757
/**
5858
* Return the MediaFormat with the supplied mime type
5959
*
60-
* @return MediaFormat associated with this mime type,
61-
* or null if none match it.
60+
* @return MediaFormat associated with this mime type
61+
* @throws IllegalStateException if there is no matching MediaFormat
6262
*/
63-
@Nullable
64-
public F getFromMimeType(final String mimeType) {
63+
@Nonnull
64+
public F getFromMimeTypeOrThrow(final String mimeType) {
6565
return Arrays.stream(values())
6666
.filter(mediaFormat -> mediaFormat.mimeType().equals(mimeType))
6767
.findFirst()
68-
.orElse(null);
68+
.orElseThrow(() -> new IllegalStateException("No matching MediaFormat"));
6969
}
7070

71-
@Nullable
72-
public F getFromSuffix(final String suffix) {
71+
/**
72+
* Return the MediaFormat with the supplied suffix
73+
*
74+
* @return MediaFormat associated with this suffix
75+
* @throws IllegalStateException if there is no matching MediaFormat
76+
*/
77+
@Nonnull
78+
public F getFromSuffixOrThrow(final String suffix) {
7379
return Arrays.stream(values())
7480
.filter(mediaFormat -> mediaFormat.suffix().equals(suffix))
7581
.findFirst()
76-
.orElse(null);
82+
.orElseThrow(() -> new IllegalStateException("No matching MediaFormat"));
7783
}
7884

7985
}

0 commit comments

Comments
 (0)