Skip to content

Commit

Permalink
Apply code review and Streams rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed May 27, 2022
1 parent 3d1fd97 commit 2cbb6ba
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
return getStreams("audio",
dto -> {
final AudioStream.Builder builder = new AudioStream.Builder()
.setId(dto.getUrlValue().getString("tech", ID_UNKNOWN))
.setContent(dto.getUrlValue().getString(URL), true)
.setId(dto.urlValue.getString("tech", ID_UNKNOWN))
.setContent(dto.urlValue.getString(URL), true)
.setAverageBitrate(UNKNOWN_BITRATE);

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

return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.getUrlKey()))
return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.urlKey))
.build();
});
}
Expand All @@ -181,15 +181,15 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
return getStreams("video",
dto -> {
final JsonArray videoSize = dto.getStreamJsonObj().getArray("videoSize");
final JsonArray videoSize = dto.streamJsonObj.getArray("videoSize");

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

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

return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.getUrlKey()))
return builder.setMediaFormat(MediaFormat.getFromSuffix(dto.urlKey))
.build();
});
}


/**
* This is just an internal class used in {@link #getStreams(String, Function)} to tie together
* the stream json object, its URL key and its URL value. An object of this class would be
* temporary and the three values it holds would be <b>convert</b>ed to a proper {@link Stream}
* object based on the wanted stream type.
*/
private static final class MediaCCCLiveStreamMapperDTO {
final JsonObject streamJsonObj;
final String urlKey;
final JsonObject urlValue;

MediaCCCLiveStreamMapperDTO(final JsonObject streamJsonObj,
final String urlKey,
final JsonObject urlValue) {
this.streamJsonObj = streamJsonObj;
this.urlKey = urlKey;
this.urlValue = urlValue;
}
}

private <T extends Stream> List<T> getStreams(
@Nonnull final String streamType,
@Nonnull final Function<MediaCCCLiveStreamMapperDTO, T> converter) {
Expand All @@ -220,7 +241,7 @@ private <T extends Stream> List<T> getStreams(
e.getKey(),
(JsonObject) e.getValue())))
// The DASH manifest will be extracted with getDashMpdUrl
.filter(dto -> !"dash".equals(dto.getUrlKey()))
.filter(dto -> !"dash".equals(dto.urlKey))
// Convert
.map(converter)
.collect(Collectors.toList());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ public int getSampleRate() {
* @param sampleRate the sample rate of an audio itag
*/
public void setSampleRate(final int sampleRate) {
if (sampleRate > 0) {
this.sampleRate = sampleRate;
} else {
this.sampleRate = SAMPLE_RATE_UNKNOWN;
}
this.sampleRate = sampleRate > 0 ? sampleRate : SAMPLE_RATE_UNKNOWN;
}

/**
Expand Down
Loading

0 comments on commit 2cbb6ba

Please sign in to comment.