Skip to content

Commit b3c620f

Browse files
StypoxAudricV
authored andcommitted
Apply code review and Streams rework
1 parent d652e05 commit b3c620f

10 files changed

Lines changed: 251 additions & 354 deletions

File tree

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
159159
return getStreams("audio",
160160
dto -> {
161161
final AudioStream.Builder builder = new AudioStream.Builder()
162-
.setId(dto.getUrlValue().getString("tech", ID_UNKNOWN))
163-
.setContent(dto.getUrlValue().getString(URL), true)
162+
.setId(dto.urlValue.getString("tech", ID_UNKNOWN))
163+
.setContent(dto.urlValue.getString(URL), true)
164164
.setAverageBitrate(UNKNOWN_BITRATE);
165165

166-
if ("hls".equals(dto.getUrlKey())) {
166+
if ("hls".equals(dto.urlKey)) {
167167
// We don't know with the type string what media format will
168168
// have HLS streams.
169169
// However, the tech string may contain some information
@@ -172,7 +172,7 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
172172
.build();
173173
}
174174

175-
return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.getUrlKey()))
175+
return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.urlKey))
176176
.build();
177177
});
178178
}
@@ -181,15 +181,15 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
181181
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
182182
return getStreams("video",
183183
dto -> {
184-
final JsonArray videoSize = dto.getStreamJsonObj().getArray("videoSize");
184+
final JsonArray videoSize = dto.streamJsonObj.getArray("videoSize");
185185

186186
final VideoStream.Builder builder = new VideoStream.Builder()
187-
.setId(dto.getUrlValue().getString("tech", ID_UNKNOWN))
188-
.setContent(dto.getUrlValue().getString(URL), true)
187+
.setId(dto.urlValue.getString("tech", ID_UNKNOWN))
188+
.setContent(dto.urlValue.getString(URL), true)
189189
.setIsVideoOnly(false)
190190
.setResolution(videoSize.getInt(0) + "x" + videoSize.getInt(1));
191191

192-
if ("hls".equals(dto.getUrlKey())) {
192+
if ("hls".equals(dto.urlKey)) {
193193
// We don't know with the type string what media format will
194194
// have HLS streams.
195195
// However, the tech string may contain some information
@@ -198,11 +198,32 @@ public List<VideoStream> getVideoStreams() throws IOException, ExtractionExcepti
198198
.build();
199199
}
200200

201-
return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.getUrlKey()))
201+
return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.urlKey))
202202
.build();
203203
});
204204
}
205205

206+
207+
/**
208+
* This is just an internal class used in {@link #getStreams(String, Function)} to tie together
209+
* the stream json object, its URL key and its URL value. An object of this class would be
210+
* temporary and the three values it holds would be <b>convert</b>ed to a proper {@link Stream}
211+
* object based on the wanted stream type.
212+
*/
213+
private static final class MediaCCCLiveStreamMapperDTO {
214+
final JsonObject streamJsonObj;
215+
final String urlKey;
216+
final JsonObject urlValue;
217+
218+
MediaCCCLiveStreamMapperDTO(final JsonObject streamJsonObj,
219+
final String urlKey,
220+
final JsonObject urlValue) {
221+
this.streamJsonObj = streamJsonObj;
222+
this.urlKey = urlKey;
223+
this.urlValue = urlValue;
224+
}
225+
}
226+
206227
private <T extends Stream> List<T> getStreams(
207228
@Nonnull final String streamType,
208229
@Nonnull final Function<MediaCCCLiveStreamMapperDTO, T> converter) {
@@ -220,7 +241,7 @@ private <T extends Stream> List<T> getStreams(
220241
e.getKey(),
221242
(JsonObject) e.getValue())))
222243
// The DASH manifest will be extracted with getDashMpdUrl
223-
.filter(dto -> !"dash".equals(dto.getUrlKey()))
244+
.filter(dto -> !"dash".equals(dto.urlKey))
224245
// Convert
225246
.map(converter)
226247
.collect(Collectors.toList());

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/ItagItem.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,7 @@ public int getSampleRate() {
409409
* @param sampleRate the sample rate of an audio itag
410410
*/
411411
public void setSampleRate(final int sampleRate) {
412-
if (sampleRate > 0) {
413-
this.sampleRate = sampleRate;
414-
} else {
415-
this.sampleRate = SAMPLE_RATE_UNKNOWN;
416-
}
412+
this.sampleRate = sampleRate > 0 ? sampleRate : SAMPLE_RATE_UNKNOWN;
417413
}
418414

419415
/**

0 commit comments

Comments
 (0)