[media.ccc.de] Live stream kiosk: detect break "talks" segements
Add and improve tests for MediaCCCLiveStreamKioskExtractor: - test stream items if a live stream is running - use mock tests to check live talk extraction and testing conferences
This commit is contained in:
parent
55a2af20ad
commit
a97c058090
|
@ -9,6 +9,7 @@ import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCParsingHelper.getThumbnailsFromLiveStreamItem;
|
import static org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCParsingHelper.getThumbnailsFromLiveStreamItem;
|
||||||
|
@ -19,17 +20,25 @@ public class MediaCCCLiveStreamKioskExtractor implements StreamInfoItemExtractor
|
||||||
private final String group;
|
private final String group;
|
||||||
private final JsonObject roomInfo;
|
private final JsonObject roomInfo;
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private final JsonObject currentTalk;
|
||||||
|
|
||||||
public MediaCCCLiveStreamKioskExtractor(final JsonObject conferenceInfo,
|
public MediaCCCLiveStreamKioskExtractor(final JsonObject conferenceInfo,
|
||||||
final String group,
|
final String group,
|
||||||
final JsonObject roomInfo) {
|
final JsonObject roomInfo) {
|
||||||
this.conferenceInfo = conferenceInfo;
|
this.conferenceInfo = conferenceInfo;
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.roomInfo = roomInfo;
|
this.roomInfo = roomInfo;
|
||||||
|
this.currentTalk = roomInfo.getObject("talks").getObject("current");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
return roomInfo.getObject("talks").getObject("current").getString("title");
|
if (isBreak()) {
|
||||||
|
return roomInfo.getString("display") + " - Pause";
|
||||||
|
} else {
|
||||||
|
return currentTalk.getString("title");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,6 +104,18 @@ public class MediaCCCLiveStreamKioskExtractor implements StreamInfoItemExtractor
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public DateWrapper getUploadDate() throws ParsingException {
|
public DateWrapper getUploadDate() throws ParsingException {
|
||||||
return null;
|
if (isBreak()) {
|
||||||
|
return new DateWrapper(OffsetDateTime.parse(currentTalk.getString("fstart")));
|
||||||
|
} else {
|
||||||
|
return new DateWrapper(OffsetDateTime.parse(conferenceInfo.getString("startsAt")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the current "talk" is a talk or a pause.
|
||||||
|
*/
|
||||||
|
private boolean isBreak() {
|
||||||
|
return OffsetDateTime.parse(currentTalk.getString("fstart")).isBefore(OffsetDateTime.now())
|
||||||
|
|| "gap".equals(currentTalk.getString("special"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,15 @@ public final class MediaCCCParsingHelper {
|
||||||
return liveStreams;
|
return liveStreams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Reset cached live stream data.</p>
|
||||||
|
* This is a temporary method which can be used to reset the cached live stream data until a
|
||||||
|
* caching policy for {@link #getLiveStreams(Downloader, Localization)} is implemented.
|
||||||
|
*/
|
||||||
|
public static void resetCachedLiveStreamInfo() {
|
||||||
|
liveStreams = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an {@link Image} list from a given image logo URL.
|
* Get an {@link Image} list from a given image logo URL.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,29 +2,106 @@ package org.schabi.newpipe.extractor.services.media_ccc;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.schabi.newpipe.downloader.DownloaderFactory;
|
||||||
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
||||||
|
import org.schabi.newpipe.downloader.MockOnly;
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
|
import org.schabi.newpipe.extractor.ListExtractor;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCLiveStreamKiosk;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
|
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems;
|
||||||
|
|
||||||
public class MediaCCCLiveStreamListExtractorTest {
|
public class MediaCCCLiveStreamListExtractorTest {
|
||||||
private static KioskExtractor extractor;
|
|
||||||
|
|
||||||
@BeforeAll
|
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH
|
||||||
public static void setUpClass() throws Exception {
|
+ "services/media.ccc.de/kiosk/live/";
|
||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
private static final String LIVE_KIOSK_ID = MediaCCCLiveStreamKiosk.KIOSK_ID;
|
||||||
extractor = MediaCCC.getKioskList().getExtractorById("live", null);
|
|
||||||
extractor.fetchPage();
|
/**
|
||||||
|
* Test against the media.ccc.de livestream API endpoint
|
||||||
|
* and ensure that no exceptions are thrown.
|
||||||
|
*/
|
||||||
|
public static class LiveDataTest {
|
||||||
|
private static KioskExtractor extractor;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setUpClass() throws Exception {
|
||||||
|
MediaCCCTestUtils.ensureStateless();
|
||||||
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
|
extractor = MediaCCC.getKioskList().getExtractorById(LIVE_KIOSK_ID, null);
|
||||||
|
extractor.fetchPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getConferencesListTest() throws Exception {
|
||||||
|
final ListExtractor.InfoItemsPage liveStreamPage = extractor.getInitialPage();
|
||||||
|
final List<InfoItem> items = liveStreamPage.getItems();
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
// defaultTestListOfItems() fails, if items is empty.
|
||||||
|
// This can happen if there are no current live streams.
|
||||||
|
// In this case, we just check if an exception was thrown
|
||||||
|
assertTrue(liveStreamPage.getErrors().isEmpty());
|
||||||
|
} else {
|
||||||
|
defaultTestListOfItems(MediaCCC, items, liveStreamPage.getErrors());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void getConferencesListTest() throws Exception {
|
* Test conferences which are available via the API for C3voc internal testing,
|
||||||
final List<InfoItem> items = extractor.getInitialPage().getItems();
|
* but not intended to be shown to users.
|
||||||
// just test if there is an exception thrown
|
*/
|
||||||
|
@MockOnly("The live stream API returns different data depending on if and what conferences"
|
||||||
|
+ " are running. The PreparationTest tests a conference which is used "
|
||||||
|
+ "for internal testing.")
|
||||||
|
public static class PreparationTest {
|
||||||
|
private static KioskExtractor extractor;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setUpClass() throws Exception {
|
||||||
|
MediaCCCTestUtils.ensureStateless();
|
||||||
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "preparation"));
|
||||||
|
extractor = MediaCCC.getKioskList().getExtractorById(LIVE_KIOSK_ID, null);
|
||||||
|
extractor.fetchPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getConferencesListTest() throws Exception {
|
||||||
|
// Testing conferences and the corresponding talks should not be extracted.
|
||||||
|
assertTrue(extractor.getInitialPage().getItems().isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test a running conference.
|
||||||
|
*/
|
||||||
|
@MockOnly("The live stream API returns different data depending on if and what conferences"
|
||||||
|
+ " are running. Using mocks to ensure that there are conferences & talks to extract.")
|
||||||
|
public static class LiveConferenceTest {
|
||||||
|
private static KioskExtractor extractor;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public static void setUpClass() throws Exception {
|
||||||
|
MediaCCCTestUtils.ensureStateless();
|
||||||
|
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "running"));
|
||||||
|
extractor = MediaCCC.getKioskList().getExtractorById(LIVE_KIOSK_ID, null);
|
||||||
|
extractor.fetchPage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getConferencesListTest() throws Exception {
|
||||||
|
final ListExtractor.InfoItemsPage liveStreamPage = extractor.getInitialPage();
|
||||||
|
final List<InfoItem> items = liveStreamPage.getItems();
|
||||||
|
assertEquals(6, items.size());
|
||||||
|
defaultTestListOfItems(MediaCCC, items, liveStreamPage.getErrors());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package org.schabi.newpipe.extractor.services.media_ccc;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCParsingHelper;
|
||||||
|
|
||||||
|
public final class MediaCCCTestUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears static media.ccc.de states.
|
||||||
|
* <p>This method needs to be called in every class before running and recording mock tests.</p>
|
||||||
|
*/
|
||||||
|
public static void ensureStateless() {
|
||||||
|
MediaCCCParsingHelper.resetCachedLiveStreamInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue