Skip to content

Commit 624ffdf

Browse files
committed
Apply some requested changes
1 parent 7191ece commit 624ffdf

4 files changed

Lines changed: 203 additions & 149 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class BandcampStreamExtractor extends StreamExtractor {
3535
private JsonObject current;
3636
private Document document;
3737

38-
private final List<AudioStream> audioStreams = new ArrayList<>();
38+
private List<AudioStream> audioStreams = null;
3939

4040
public BandcampStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
4141
super(service, linkHandler);
@@ -115,8 +115,9 @@ public DateWrapper getUploadDate() throws ParsingException {
115115
public String getThumbnailUrl() throws ParsingException {
116116
if (albumJson.isNull("art_id")) {
117117
return EMPTY_STRING;
118+
} else {
119+
return getImageUrl(albumJson.getLong("art_id"), true);
118120
}
119-
else return getImageUrl(albumJson.getLong("art_id"), true);
120121
}
121122

122123
@Nonnull
@@ -145,9 +146,15 @@ public Description getDescription() {
145146

146147
@Override
147148
public List<AudioStream> getAudioStreams() {
148-
if (audioStreams.isEmpty()) {
149-
audioStreams.add(new AudioStream("mp3-128", albumJson.getArray("trackinfo")
150-
.getObject(0).getObject("file").getString("mp3-128"), MediaFormat.MP3, 128));
149+
if (audioStreams == null) {
150+
audioStreams = new ArrayList<>();
151+
audioStreams.add(new AudioStream("mp3-128",
152+
albumJson.getArray("trackinfo")
153+
.getObject(0)
154+
.getObject("file")
155+
.getString("mp3-128"),
156+
MediaFormat.MP3,
157+
128));
151158
}
152159
return audioStreams;
153160
}
@@ -169,8 +176,8 @@ public StreamType getStreamType() {
169176

170177
@Override
171178
public PlaylistInfoItemsCollector getRelatedItems() {
172-
final PlaylistInfoItemsCollector collector = new PlaylistInfoItemsCollector(
173-
getServiceId());
179+
final PlaylistInfoItemsCollector collector =
180+
new PlaylistInfoItemsCollector(getServiceId());
174181
final Elements recommendedAlbums = document.getElementsByClass("recommended-album");
175182

176183
for (final Element album : recommendedAlbums) {

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

Lines changed: 65 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.ArrayList;
1616
import java.util.Collections;
1717
import java.util.List;
18+
import java.util.stream.IntStream;
1819

1920
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
2021
import 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

Comments
 (0)