@@ -1140,17 +1140,11 @@ private JsonObject getVideoSecondaryInfoRenderer() throws ParsingException {
11401140 return videoSecondaryInfoRenderer ;
11411141 }
11421142
1143- @ FunctionalInterface
1144- private interface StreamBuilderHelper <T extends Stream > {
1145- @ Nonnull
1146- T buildStream (ItagInfo itagInfo );
1147- }
1148-
11491143 @ Nonnull
11501144 private <T extends Stream > List <T > getItags (
11511145 final String streamingDataKey ,
11521146 final ItagItem .ItagType itagTypeWanted ,
1153- final StreamBuilderHelper < T > streamBuilderHelper ,
1147+ final java . util . function . Function < ItagInfo , T > streamBuilderHelper ,
11541148 final String streamTypeExceptionMessage ) throws ParsingException {
11551149 try {
11561150 final List <ItagInfo > itagInfos = new ArrayList <>();
@@ -1176,7 +1170,7 @@ private <T extends Stream> List<T> getItags(
11761170
11771171 final List <T > streamList = new ArrayList <>();
11781172 for (final ItagInfo itagInfo : itagInfos ) {
1179- final T stream = streamBuilderHelper .buildStream (itagInfo );
1173+ final T stream = streamBuilderHelper .apply (itagInfo );
11801174 if (!Stream .containSimilarStream (stream , streamList )) {
11811175 streamList .add (stream );
11821176 }
@@ -1190,8 +1184,8 @@ private <T extends Stream> List<T> getItags(
11901184 }
11911185
11921186 /**
1193- * Get the {@link StreamBuilderHelper} which will be used to build {@link AudioStream}s in
1194- * {@link #getItags(String, ItagItem.ItagType, StreamBuilderHelper , String)}
1187+ * Get the stream builder helper which will be used to build {@link AudioStream}s in
1188+ * {@link #getItags(String, ItagItem.ItagType, java.util.function.Function , String)}
11951189 *
11961190 * <p>
11971191 * The {@code StreamBuilderHelper} will set the following attributes in the
@@ -1213,38 +1207,34 @@ private <T extends Stream> List<T> getItags(
12131207 * Note that the {@link ItagItem} comes from an {@link ItagInfo} instance.
12141208 * </p>
12151209 *
1216- * @return a {@link StreamBuilderHelper} to build {@link AudioStream}s
1210+ * @return a stream builder helper to build {@link AudioStream}s
12171211 */
12181212 @ Nonnull
1219- private StreamBuilderHelper <AudioStream > getAudioStreamBuilderHelper () {
1220- return new StreamBuilderHelper <AudioStream >() {
1221- @ Nonnull
1222- @ Override
1223- public AudioStream buildStream (@ Nonnull final ItagInfo itagInfo ) {
1224- final ItagItem itagItem = itagInfo .getItagItem ();
1225- final AudioStream .Builder builder = new AudioStream .Builder ()
1226- .setId (String .valueOf (itagItem .id ))
1227- .setContent (itagInfo .getContent (), itagInfo .getIsUrl ())
1228- .setMediaFormat (itagItem .getMediaFormat ())
1229- .setAverageBitrate (itagItem .getAverageBitrate ())
1230- .setItagItem (itagItem );
1231-
1232- if (streamType == StreamType .LIVE_STREAM
1233- || streamType == StreamType .POST_LIVE_STREAM
1234- || !itagInfo .getIsUrl ()) {
1235- // For YouTube videos on OTF streams and for all streams of post-live streams
1236- // and live streams, only the DASH delivery method can be used.
1237- builder .setDeliveryMethod (DeliveryMethod .DASH );
1238- }
1239-
1240- return builder .build ();
1213+ private java .util .function .Function <ItagInfo , AudioStream > getAudioStreamBuilderHelper () {
1214+ return (itagInfo ) -> {
1215+ final ItagItem itagItem = itagInfo .getItagItem ();
1216+ final AudioStream .Builder builder = new AudioStream .Builder ()
1217+ .setId (String .valueOf (itagItem .id ))
1218+ .setContent (itagInfo .getContent (), itagInfo .getIsUrl ())
1219+ .setMediaFormat (itagItem .getMediaFormat ())
1220+ .setAverageBitrate (itagItem .getAverageBitrate ())
1221+ .setItagItem (itagItem );
1222+
1223+ if (streamType == StreamType .LIVE_STREAM
1224+ || streamType == StreamType .POST_LIVE_STREAM
1225+ || !itagInfo .getIsUrl ()) {
1226+ // For YouTube videos on OTF streams and for all streams of post-live streams
1227+ // and live streams, only the DASH delivery method can be used.
1228+ builder .setDeliveryMethod (DeliveryMethod .DASH );
12411229 }
1230+
1231+ return builder .build ();
12421232 };
12431233 }
12441234
12451235 /**
1246- * Get the {@link StreamBuilderHelper} which will be used to build {@link VideoStream}s in
1247- * {@link #getItags(String, ItagItem.ItagType, StreamBuilderHelper , String)}
1236+ * Get the stream builder helper which will be used to build {@link VideoStream}s in
1237+ * {@link #getItags(String, ItagItem.ItagType, java.util.function.Function , String)}
12481238 *
12491239 * <p>
12501240 * The {@code StreamBuilderHelper} will set the following attributes in the
@@ -1272,37 +1262,33 @@ public AudioStream buildStream(@Nonnull final ItagInfo itagInfo) {
12721262 * Note that the {@link ItagItem} comes from an {@link ItagInfo} instance.
12731263 * </p>
12741264 *
1275- * @param areStreamsVideoOnly whether the {@link StreamBuilderHelper} will set the video
1265+ * @param areStreamsVideoOnly whether the stream builder helper will set the video
12761266 * streams as video-only streams
1277- * @return a {@link StreamBuilderHelper} to build {@link VideoStream}s
1267+ * @return a stream builder helper to build {@link VideoStream}s
12781268 */
12791269 @ Nonnull
1280- private StreamBuilderHelper < VideoStream > getVideoStreamBuilderHelper (
1270+ private java . util . function . Function < ItagInfo , VideoStream > getVideoStreamBuilderHelper (
12811271 final boolean areStreamsVideoOnly ) {
1282- return new StreamBuilderHelper <VideoStream >() {
1283- @ Nonnull
1284- @ Override
1285- public VideoStream buildStream (@ Nonnull final ItagInfo itagInfo ) {
1286- final ItagItem itagItem = itagInfo .getItagItem ();
1287- final VideoStream .Builder builder = new VideoStream .Builder ()
1288- .setId (String .valueOf (itagItem .id ))
1289- .setContent (itagInfo .getContent (), itagInfo .getIsUrl ())
1290- .setMediaFormat (itagItem .getMediaFormat ())
1291- .setIsVideoOnly (areStreamsVideoOnly )
1292- .setItagItem (itagItem );
1293-
1294- final String resolutionString = itagItem .getResolutionString ();
1295- builder .setResolution (resolutionString != null ? resolutionString
1296- : EMPTY_STRING );
1297-
1298- if (streamType != StreamType .VIDEO_STREAM || !itagInfo .getIsUrl ()) {
1299- // For YouTube videos on OTF streams and for all streams of post-live streams
1300- // and live streams, only the DASH delivery method can be used.
1301- builder .setDeliveryMethod (DeliveryMethod .DASH );
1302- }
1303-
1304- return builder .build ();
1272+ return (itagInfo ) -> {
1273+ final ItagItem itagItem = itagInfo .getItagItem ();
1274+ final VideoStream .Builder builder = new VideoStream .Builder ()
1275+ .setId (String .valueOf (itagItem .id ))
1276+ .setContent (itagInfo .getContent (), itagInfo .getIsUrl ())
1277+ .setMediaFormat (itagItem .getMediaFormat ())
1278+ .setIsVideoOnly (areStreamsVideoOnly )
1279+ .setItagItem (itagItem );
1280+
1281+ final String resolutionString = itagItem .getResolutionString ();
1282+ builder .setResolution (resolutionString != null ? resolutionString
1283+ : EMPTY_STRING );
1284+
1285+ if (streamType != StreamType .VIDEO_STREAM || !itagInfo .getIsUrl ()) {
1286+ // For YouTube videos on OTF streams and for all streams of post-live streams
1287+ // and live streams, only the DASH delivery method can be used.
1288+ builder .setDeliveryMethod (DeliveryMethod .DASH );
13051289 }
1290+
1291+ return builder .build ();
13061292 };
13071293 }
13081294
0 commit comments