[media.ccc.de] Recent kiosk: order streams by upload date
This commit is contained in:
parent
3c8c8e7307
commit
5dc9a76e3c
|
@ -3,8 +3,10 @@ package org.schabi.newpipe.extractor;
|
|||
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
|
@ -32,17 +34,31 @@ public abstract class InfoItemsCollector<I extends InfoItem, E extends InfoItemE
|
|||
private final List<I> itemList = new ArrayList<>();
|
||||
private final List<Throwable> errors = new ArrayList<>();
|
||||
private final int serviceId;
|
||||
@Nullable
|
||||
private final Comparator<I> comparator;
|
||||
|
||||
/**
|
||||
* Create a new collector with no comparator / sorting function
|
||||
* @param serviceId the service id
|
||||
*/
|
||||
public InfoItemsCollector(final int serviceId) {
|
||||
this(serviceId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collector
|
||||
* @param serviceId the service id
|
||||
*/
|
||||
public InfoItemsCollector(int serviceId) {
|
||||
public InfoItemsCollector(final int serviceId, @Nullable final Comparator<I> comparator) {
|
||||
this.serviceId = serviceId;
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<I> getItems() {
|
||||
if (comparator != null) {
|
||||
itemList.sort(comparator);
|
||||
}
|
||||
return Collections.unmodifiableList(itemList);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
|
||||
|
||||
|
@ -40,7 +41,14 @@ public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
|
|||
@Override
|
||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||
final JsonArray events = doc.getArray("events");
|
||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||
|
||||
// Streams in the recent kiosk are not ordered by the release date.
|
||||
// Sort them to have the latest stream at the beginning of the list.
|
||||
Comparator<StreamInfoItem> comparator = Comparator.comparing(
|
||||
streamInfoItem -> streamInfoItem.getUploadDate().offsetDateTime());
|
||||
comparator = comparator.reversed();
|
||||
|
||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId(), comparator);
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i)));
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.schabi.newpipe.extractor.InfoItemsCollector;
|
|||
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
|
@ -34,6 +35,10 @@ public class StreamInfoItemsCollector extends InfoItemsCollector<StreamInfoItem,
|
|||
super(serviceId);
|
||||
}
|
||||
|
||||
public StreamInfoItemsCollector(int serviceId, Comparator<StreamInfoItem> comparator) {
|
||||
super(serviceId, comparator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfoItem extract(StreamInfoItemExtractor extractor) throws ParsingException {
|
||||
if (extractor.isAd()) {
|
||||
|
|
Loading…
Reference in New Issue