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 javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Comparator; import java.util.Comparator;
import java.util.function.Function;
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> { public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
@ -51,11 +53,17 @@ public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
streamInfoItem -> streamInfoItem.getUploadDate().offsetDateTime()); streamInfoItem -> streamInfoItem.getUploadDate().offsetDateTime());
comparator = comparator.reversed(); comparator = comparator.reversed();
final StreamInfoItemsCollector collector final StreamInfoItemsCollector collector =
= new StreamInfoItemsCollector(getServiceId(), comparator); new StreamInfoItemsCollector(getServiceId(), comparator);
for (int i = 0; i < events.size(); i++) {
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i))); 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); return new InfoItemsPage<>(collector, null);
} }

View File

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

View File

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