Skip to content

Commit 1925dcf

Browse files
authored
Merge pull request #597 from fynngodau/related-items
Rename getRelatedStreams to getRelatedItems and change return type
2 parents 9dbc152 + c877712 commit 1925dcf

16 files changed

Lines changed: 73 additions & 29 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public StreamType getStreamType() {
245245
}
246246

247247
@Override
248-
public StreamInfoItemsCollector getRelatedStreams() {
248+
public StreamInfoItemsCollector getRelatedItems() {
249249
return null;
250250
}
251251

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public StreamType getStreamType() throws ParsingException {
240240

241241
@Nullable
242242
@Override
243-
public StreamInfoItemsCollector getRelatedStreams() {
243+
public StreamInfoItemsCollector getRelatedItems() {
244244
return null;
245245
}
246246

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public StreamType getStreamType() {
219219

220220
@Nullable
221221
@Override
222-
public StreamInfoItemsCollector getRelatedStreams() {
222+
public StreamInfoItemsCollector getRelatedItems() {
223223
return null;
224224
}
225225

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ public StreamType getStreamType() {
264264

265265
@Nullable
266266
@Override
267-
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
267+
public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException {
268268
final List<String> tags = getTags();
269269
final String apiUrl;
270270
if (tags.isEmpty()) {
271271
apiUrl = baseUrl + "/api/v1/accounts/" + JsonUtils.getString(json, "account.name")
272272
+ "@" + JsonUtils.getString(json, "account.host") +
273273
"/videos?start=0&count=8";
274274
} else {
275-
apiUrl = getRelatedStreamsUrl(tags);
275+
apiUrl = getRelatedItemsUrl(tags);
276276
}
277277

278278
if (Utils.isBlank(apiUrl)) {
@@ -312,7 +312,7 @@ public List<MetaInfo> getMetaInfo() {
312312
return Collections.emptyList();
313313
}
314314

315-
private String getRelatedStreamsUrl(final List<String> tags) throws UnsupportedEncodingException {
315+
private String getRelatedItemsUrl(final List<String> tags) throws UnsupportedEncodingException {
316316
final String url = baseUrl + PeertubeSearchQueryHandlerFactory.SEARCH_ENDPOINT;
317317
final StringBuilder params = new StringBuilder();
318318
params.append("start=0&count=8&sort=-createdAt");

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public StreamType getStreamType() {
353353

354354
@Nullable
355355
@Override
356-
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
356+
public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException {
357357
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
358358

359359
final String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId())

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ private StreamInfoItemExtractor getNextStream() throws ExtractionException {
643643

644644
@Nullable
645645
@Override
646-
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
646+
public StreamInfoItemsCollector getRelatedItems() throws ExtractionException {
647647
assertPageFetched();
648648

649649
if (getAgeLimit() != NO_AGE_LIMIT) {

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23+
import org.schabi.newpipe.extractor.InfoItem;
24+
import org.schabi.newpipe.extractor.InfoItemsCollector;
25+
import org.schabi.newpipe.extractor.InfoItemExtractor;
2326
import org.schabi.newpipe.extractor.Extractor;
2427
import org.schabi.newpipe.extractor.MediaFormat;
2528
import org.schabi.newpipe.extractor.MetaInfo;
@@ -331,7 +334,24 @@ public StreamExtractor(StreamingService service, LinkHandler linkHandler) {
331334
* @throws ExtractionException
332335
*/
333336
@Nullable
334-
public abstract StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException;
337+
public abstract InfoItemsCollector<? extends InfoItem, ? extends InfoItemExtractor>
338+
getRelatedItems() throws IOException, ExtractionException;
339+
340+
/**
341+
* @deprecated Use {@link #getRelatedItems()}. May be removed in a future version.
342+
* @return The result of {@link #getRelatedItems()} if it is a
343+
* StreamInfoItemsCollector, null otherwise
344+
* @throws IOException
345+
* @throws ExtractionException
346+
*/
347+
@Deprecated
348+
@Nullable
349+
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
350+
InfoItemsCollector<?, ?> collector = getRelatedItems();
351+
if (collector instanceof StreamInfoItemsCollector) {
352+
return (StreamInfoItemsCollector) collector;
353+
} else return null;
354+
}
335355

336356
/**
337357
* Should return a list of Frameset object that contains preview of stream frames

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
335335
streamInfo.addError(e);
336336
}
337337

338-
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
338+
streamInfo.setRelatedItems(ExtractorHelper.getRelatedItemsOrLogError(streamInfo, extractor));
339339

340340
return streamInfo;
341341
}
@@ -371,7 +371,7 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
371371

372372

373373
private String hlsUrl = "";
374-
private List<InfoItem> relatedStreams = new ArrayList<>();
374+
private List<InfoItem> relatedItems = new ArrayList<>();
375375

376376
private long startPosition = 0;
377377
private List<SubtitlesStream> subtitles = new ArrayList<>();
@@ -603,12 +603,28 @@ public void setHlsUrl(String hlsUrl) {
603603
this.hlsUrl = hlsUrl;
604604
}
605605

606+
public List<InfoItem> getRelatedItems() {
607+
return relatedItems;
608+
}
609+
610+
/**
611+
* @deprecated Use {@link #getRelatedItems()}
612+
*/
613+
@Deprecated
606614
public List<InfoItem> getRelatedStreams() {
607-
return relatedStreams;
615+
return getRelatedItems();
608616
}
609617

610-
public void setRelatedStreams(List<InfoItem> relatedStreams) {
611-
this.relatedStreams = relatedStreams;
618+
public void setRelatedItems(List<InfoItem> relatedItems) {
619+
this.relatedItems = relatedItems;
620+
}
621+
622+
/**
623+
* @deprecated Use {@link #setRelatedItems(List)}
624+
*/
625+
@Deprecated
626+
public void setRelatedStreams(List<InfoItem> relatedItems) {
627+
setRelatedItems(relatedItems);
612628
}
613629

614630
public long getStartPosition() {

extractor/src/main/java/org/schabi/newpipe/extractor/utils/ExtractorHelper.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public static <T extends InfoItem> InfoItemsPage<T> getItemsPageOrLogError(Info
2727
}
2828

2929

30-
public static List<InfoItem> getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) {
30+
public static List<InfoItem> getRelatedItemsOrLogError(StreamInfo info, StreamExtractor extractor) {
3131
try {
32-
InfoItemsCollector<? extends InfoItem, ?> collector = extractor.getRelatedStreams();
32+
InfoItemsCollector<? extends InfoItem, ?> collector = extractor.getRelatedItems();
3333
if (collector == null) return Collections.emptyList();
3434
info.addAllErrors(collector.getErrors());
3535

@@ -41,4 +41,12 @@ public static List<InfoItem> getRelatedVideosOrLogError(StreamInfo info, StreamE
4141
}
4242
}
4343

44+
/**
45+
* @deprecated Use {@link #getRelatedItemsOrLogError(StreamInfo, StreamExtractor)}
46+
*/
47+
@Deprecated
48+
public static List<InfoItem> getRelatedVideosOrLogError(StreamInfo info, StreamExtractor extractor) {
49+
return getRelatedItemsOrLogError(info, extractor);
50+
}
51+
4452
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface BaseStreamExtractorTest extends BaseExtractorTest {
1717
void testTextualUploadDate() throws Exception;
1818
void testLikeCount() throws Exception;
1919
void testDislikeCount() throws Exception;
20-
void testRelatedStreams() throws Exception;
20+
void testRelatedItems() throws Exception;
2121
void testAgeLimit() throws Exception;
2222
void testErrorMessage() throws Exception;
2323
void testAudioStreams() throws Exception;

0 commit comments

Comments
 (0)