Skip to content

Commit 34d11af

Browse files
committed
Made code non-nullable (MediaFormatRegistry)
1 parent 7f9e895 commit 34d11af

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

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
@@ -174,7 +174,7 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
174174

175175
return new SimpleAudioStreamImpl(
176176
// TODO: This looks wrong
177-
new AudioFormatRegistry().getFromSuffix(dto.getUrlKey()),
177+
new AudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()),
178178
deliveryData
179179
);
180180
})
@@ -199,7 +199,7 @@ public List<VideoAudioStream> getVideoStreams() throws IOException, ExtractionEx
199199

200200
return new SimpleVideoAudioStreamImpl(
201201
// TODO: This looks wrong
202-
new VideoAudioFormatRegistry().getFromSuffix(dto.getUrlKey()),
202+
new VideoAudioFormatRegistry().getFromSuffixOrThrow(dto.getUrlKey()),
203203
deliveryData,
204204
VideoQualityData.fromHeightWidth(
205205
/*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
@@ -402,7 +402,7 @@ private void tryExtractSubtitles() {
402402
return new SimpleSubtitleStreamImpl(
403403
// TODO: Check for null
404404
new SubtitleFormatRegistry()
405-
.getFromSuffix(
405+
.getFromSuffixOrThrow(
406406
url.substring(url.lastIndexOf(".") + 1)),
407407
new SimpleProgressiveHTTPDeliveryDataImpl(url),
408408
false,
@@ -497,7 +497,7 @@ private void addStreamsFromArray(
497497
playlistUrl,
498498
(s, dd) -> new SimpleAudioStreamImpl(
499499
new AudioFormatRegistry()
500-
.getFromSuffix(getExtensionFromStream(s)),
500+
.getFromSuffixOrThrow(getExtensionFromStream(s)),
501501
dd
502502
)
503503
);
@@ -510,7 +510,7 @@ private void addStreamsFromArray(
510510
playlistUrl,
511511
(s, dd) -> new SimpleVideoAudioStreamImpl(
512512
new VideoAudioFormatRegistry()
513-
.getFromSuffix(getExtensionFromStream(s)),
513+
.getFromSuffixOrThrow(getExtensionFromStream(s)),
514514
dd,
515515
VideoQualityData.fromHeightFps(
516516
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
@@ -324,7 +324,7 @@ private Optional<AudioStream> extractDownloadableFileIfAvailable() {
324324
}
325325

326326
return Optional.of(new SimpleAudioStreamImpl(
327-
new AudioFormatRegistry().getFromSuffix(fileType),
327+
new AudioFormatRegistry().getFromSuffixOrThrow(fileType),
328328
new SimpleProgressiveHTTPDeliveryDataImpl(downloadUrl)
329329
));
330330
} 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)