Skip to content

Commit 164e21b

Browse files
committed
Fixed MediaCCCRecentKiosk
Ignore faulty data/items (with duration <= 0)
1 parent 49dfdae commit 164e21b

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
import javax.annotation.Nonnull;
1818
import java.io.IOException;
19+
import java.time.OffsetDateTime;
1920
import java.util.Comparator;
21+
import java.util.function.Function;
2022

2123
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
2224

@@ -51,11 +53,17 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, Extrac
5153
streamInfoItem -> streamInfoItem.getUploadDate().offsetDateTime());
5254
comparator = comparator.reversed();
5355

54-
final StreamInfoItemsCollector collector
55-
= new StreamInfoItemsCollector(getServiceId(), comparator);
56-
for (int i = 0; i < events.size(); i++) {
57-
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i)));
58-
}
56+
final StreamInfoItemsCollector collector =
57+
new StreamInfoItemsCollector(getServiceId(), comparator);
58+
59+
events.stream()
60+
.filter(JsonObject.class::isInstance)
61+
.map(JsonObject.class::cast)
62+
.map(MediaCCCRecentKioskExtractor::new)
63+
// #813 / voc/voctoweb#609 -> returns faulty data -> filter it out
64+
.filter(extractor -> extractor.getDuration() > 0)
65+
.forEach(collector::commit);
66+
5967
return new InfoItemsPage<>(collector, null);
6068
}
6169

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public boolean isAd() {
4545
}
4646

4747
@Override
48-
public long getDuration() throws ParsingException {
49-
// duration and length have the same value, see
50-
// https://github.com/voc/voctoweb/blob/master/app/views/public/shared/_event.json.jbuilder
48+
public long getDuration() {
49+
// duration and length have the same value
50+
// see https://github.com/voc/voctoweb/blob/master/app/views/public/shared/_event.json.jbuilder
5151
return event.getInt("duration");
5252
}
5353

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCRecentListExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void setUpClass() throws Exception {
3030
@Test
3131
void testStreamList() throws Exception {
3232
final List<StreamInfoItem> items = extractor.getInitialPage().getItems();
33-
assertEquals(100, items.size());
33+
assertFalse(items.isEmpty(), "No items returned");
3434

3535
assertAll(items.stream().flatMap(this::getAllConditionsForItem));
3636
}

0 commit comments

Comments
 (0)