Fixed ``MediaCCCRecentKiosk``

Ignore faulty data/items (with duration <= 0)
This commit is contained in:
litetex 2022-03-17 14:10:28 +01:00
parent 49dfdae5d2
commit 164e21b5af
3 changed files with 17 additions and 9 deletions

View File

@ -16,7 +16,9 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Comparator;
import java.util.function.Function;
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
@ -51,11 +53,17 @@ public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
streamInfoItem -> streamInfoItem.getUploadDate().offsetDateTime());
comparator = comparator.reversed();
final StreamInfoItemsCollector collector
= new StreamInfoItemsCollector(getServiceId(), comparator);
for (int i = 0; i < events.size(); i++) {
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i)));
}
final StreamInfoItemsCollector collector =
new StreamInfoItemsCollector(getServiceId(), comparator);
events.stream()
.filter(JsonObject.class::isInstance)
.map(JsonObject.class::cast)
.map(MediaCCCRecentKioskExtractor::new)
// #813 / voc/voctoweb#609 -> returns faulty data -> filter it out
.filter(extractor -> extractor.getDuration() > 0)
.forEach(collector::commit);
return new InfoItemsPage<>(collector, null);
}

View File

@ -45,9 +45,9 @@ public class MediaCCCRecentKioskExtractor implements StreamInfoItemExtractor {
}
@Override
public long getDuration() throws ParsingException {
// duration and length have the same value, see
// https://github.com/voc/voctoweb/blob/master/app/views/public/shared/_event.json.jbuilder
public long getDuration() {
// duration and length have the same value
// see https://github.com/voc/voctoweb/blob/master/app/views/public/shared/_event.json.jbuilder
return event.getInt("duration");
}

View File

@ -30,7 +30,7 @@ public class MediaCCCRecentListExtractorTest {
@Test
void testStreamList() throws Exception {
final List<StreamInfoItem> items = extractor.getInitialPage().getItems();
assertEquals(100, items.size());
assertFalse(items.isEmpty(), "No items returned");
assertAll(items.stream().flatMap(this::getAllConditionsForItem));
}