1515import java .util .ArrayList ;
1616import java .util .Collections ;
1717import java .util .List ;
18+ import java .util .stream .IntStream ;
1819
1920import static org .schabi .newpipe .extractor .stream .AudioStream .UNKNOWN_BITRATE ;
2021import static org .schabi .newpipe .extractor .utils .Utils .EMPTY_STRING ;
@@ -24,21 +25,18 @@ public class MediaCCCLiveStreamExtractor extends StreamExtractor {
2425 private String group = "" ;
2526 private JsonObject room = null ;
2627
27- private final List <AudioStream > audioStreams = new ArrayList <>() ;
28- private final List <VideoStream > videoStreams = new ArrayList <>() ;
28+ private List <AudioStream > audioStreams = null ;
29+ private List <VideoStream > videoStreams = null ;
2930 private String firstDashUrlFound = null ;
3031 private String firstHlsUrlFound = null ;
3132
32- public MediaCCCLiveStreamExtractor (final StreamingService service ,
33- final LinkHandler linkHandler ) {
33+ public MediaCCCLiveStreamExtractor (final StreamingService service , final LinkHandler linkHandler ) {
3434 super (service , linkHandler );
3535 }
3636
3737 @ Override
38- public void onFetchPage (@ Nonnull final Downloader downloader )
39- throws IOException , ExtractionException {
40- final JsonArray doc = MediaCCCParsingHelper .getLiveStreams (downloader ,
41- getExtractorLocalization ());
38+ public void onFetchPage (@ Nonnull final Downloader downloader ) throws IOException , ExtractionException {
39+ final JsonArray doc = MediaCCCParsingHelper .getLiveStreams (downloader , getExtractorLocalization ());
4240 // Find the correct room
4341 for (int c = 0 ; c < doc .size (); c ++) {
4442 final JsonObject conferenceObject = doc .getObject (c );
@@ -48,8 +46,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
4846 final JsonArray rooms = groups .getObject (g ).getArray ("rooms" );
4947 for (int r = 0 ; r < rooms .size (); r ++) {
5048 final JsonObject roomObject = rooms .getObject (r );
51- if (getId ().equals (conferenceObject .getString ("slug" ) + "/"
52- + roomObject .getString ("slug" ))) {
49+ if (getId ().equals (conferenceObject .getString ("slug" ) + "/" + roomObject .getString ("slug" ))) {
5350 this .conference = conferenceObject ;
5451 this .group = groupObject ;
5552 this .room = roomObject ;
@@ -76,8 +73,7 @@ public String getThumbnailUrl() throws ParsingException {
7673 @ Nonnull
7774 @ Override
7875 public Description getDescription () throws ParsingException {
79- return new Description (conference .getString ("description" ) + " - " + group ,
80- Description .PLAIN_TEXT );
76+ return new Description (conference .getString ("description" ) + " - " + group , Description .PLAIN_TEXT );
8177 }
8278
8379 @ Override
@@ -149,77 +145,73 @@ public String getHlsUrl() {
149145
150146 @ Override
151147 public List <AudioStream > getAudioStreams () throws IOException , ExtractionException {
152- if (audioStreams .isEmpty ()) {
153- for (int s = 0 ; s < room .getArray ("streams" ).size (); s ++) {
154- final JsonObject stream = room .getArray ("streams" ).getObject (s );
155- if (stream .getString ("type" ).equals ("audio" )) {
156- for (final String type : stream .getObject ("urls" ).keySet ()) {
157- final JsonObject urlObject = stream .getObject ("urls" ).getObject (type );
158- // The DASH manifest will be extracted with getDashMpdUrl
159- if (!type .equals ("dash" )) {
160- if (type .equals ("hls" )) {
161- audioStreams .add (new AudioStream (urlObject .getString ("tech" ),
162- urlObject .getString ("url" ),
163- true ,
164- // We don't know with the type string what media format
165- // will have HLS streams.
166- // However, the tech string may contain some information
167- // about the media format used.
168- null ,
169- DeliveryMethod .HLS ,
170- UNKNOWN_BITRATE ));
171- } else {
172- audioStreams .add (new AudioStream (urlObject .getString ("tech" ),
173- urlObject .getString ("url" ),
174- MediaFormat .getFromSuffix (type ),
175- UNKNOWN_BITRATE ));
148+ if (audioStreams == null ) {
149+ audioStreams = new ArrayList <>();
150+ IntStream .range (0 , room .getArray ("streams" ).size ())
151+ .mapToObj (s -> room .getArray ("streams" ).getObject (s ))
152+ .filter (stream -> stream .getString ("type" ).equals ("audio" ))
153+ .forEachOrdered (stream -> {
154+ for (final String type : stream .getObject ("urls" ).keySet ()) {
155+ final JsonObject urlObject = stream .getObject ("urls" ).getObject (type );
156+ // The DASH manifest will be extracted with getDashMpdUrl
157+ if (!type .equals ("dash" )) {
158+ if (type .equals ("hls" )) {
159+ audioStreams .add (new AudioStream (urlObject .getString ("tech" ),
160+ urlObject .getString ("url" ),
161+ true ,
162+ // We don't know with the type string what media format
163+ // will have HLS streams.
164+ // However, the tech string may contain some information
165+ // about the media format used.
166+ null ,
167+ DeliveryMethod .HLS ,
168+ UNKNOWN_BITRATE ));
169+ } else {
170+ audioStreams .add (new AudioStream (urlObject .getString ("tech" ),
171+ urlObject .getString ("url" ),
172+ MediaFormat .getFromSuffix (type ),
173+ UNKNOWN_BITRATE ));
174+ }
176175 }
177176 }
178- }
179- }
180- }
177+ });
181178 }
182179 return audioStreams ;
183180 }
184181
185182 @ Override
186183 public List <VideoStream > getVideoStreams () throws IOException , ExtractionException {
187- if (videoStreams .isEmpty ()) {
188- for (int s = 0 ; s < room .getArray ("streams" ).size (); s ++) {
189- final JsonObject stream = room .getArray ("streams" ).getObject (s );
190- if (stream .getString ("type" ).equals ("video" )) {
191- final String resolution = stream .getArray ("videoSize" ).getInt (0 ) + "x"
192- + stream .getArray ("videoSize" ).getInt (1 );
193- for (final String type : stream .getObject ("urls" ).keySet ()) {
194- final JsonObject urlObject = stream .getObject ("urls" ).getObject (type );
195- // The DASH manifest will be extracted with getDashMpdUrl
196- if (!type .equals ("dash" )) {
197- if (type .equals ("hls" )) {
198- videoStreams .add (new VideoStream (urlObject .getString ("tech" ),
199- urlObject .getString ("url" ),
200- true ,
201- // We don't know with the type string what type will have
202- // HLS
203- // streams.
204- // However, the tech string may contain some information
205- // about
206- // the media format used.
207- null ,
208- DeliveryMethod .HLS ,
209- resolution ,
210- false ,
211- null ));
212- } else {
213- videoStreams .add (new VideoStream (urlObject .getString ("tech" ),
214- urlObject .getString ("url" ),
215- MediaFormat .getFromSuffix (type ),
216- resolution ,
217- false ));
184+ if (videoStreams == null ) {
185+ videoStreams = new ArrayList <>();
186+ IntStream .range (0 , room .getArray ("streams" ).size ())
187+ .mapToObj (s -> room .getArray ("streams" ).getObject (s ))
188+ .filter (stream -> stream .getString ("type" ).equals ("video" ))
189+ .forEachOrdered (stream -> {
190+ final String resolution = stream .getArray ("videoSize" ).getInt (0 ) + "x"
191+ + stream .getArray ("videoSize" ).getInt (1 );
192+ for (final String type : stream .getObject ("urls" ).keySet ()) {
193+ final JsonObject urlObject = stream .getObject ("urls" ).getObject (type );
194+ // The DASH manifest will be extracted with getDashMpdUrl
195+ if (!type .equals ("dash" )) {
196+ if (type .equals ("hls" )) {
197+ videoStreams .add (new VideoStream (urlObject .getString ("tech" ),
198+ urlObject .getString ("url" ),
199+ true ,
200+ // We don't know with the type string what type will have
201+ // HLS streams.
202+ // However, the tech string may contain some information about
203+ // the media format used.
204+ null , DeliveryMethod .HLS , resolution , false , null ));
205+ } else {
206+ videoStreams .add (new VideoStream (urlObject .getString ("tech" ),
207+ urlObject .getString ("url" ),
208+ MediaFormat .getFromSuffix (type ),
209+ resolution ,
210+ false ));
211+ }
218212 }
219213 }
220- }
221- }
222- }
214+ });
223215 }
224216 return videoStreams ;
225217 }
0 commit comments