Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ private static MetaInfo getInfoPanelContent(@Nonnull final JsonObject infoPanelC
throw new ParsingException("Could not get metadata info URL", e);
}

final String metaInfoLinkText = getTextFromObject(
infoPanelContentRenderer.getObject("inlineSource"));
final String metaInfoLinkText;
if (infoPanelContentRenderer.has("inlineSource")) {
metaInfoLinkText = getTextFromObject(
infoPanelContentRenderer.getObject("inlineSource"));
} else {
metaInfoLinkText = getTextFromObject(
infoPanelContentRenderer.getObject("disclaimer"));
}
if (isNullOrEmpty(metaInfoLinkText)) {
throw new ParsingException("Could not get metadata info link text.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ public static void assertContains(
"'" + shouldBeContained + "' should be contained inside '" + container + "'");
}

public static <T> void assertContains(final T shouldBeContained, final List<T> container) {
assertNotNull(shouldBeContained, "shouldBeContained is null");
assertNotNull(container, "container is null");
final String containerString = container.stream()
.map(Object::toString)
.collect(Collectors.joining(", "));
assertTrue(container.contains(shouldBeContained),
"'" + shouldBeContained + "' should be contained inside [" + containerString + "]");
}

public static void assertTabsContain(@Nonnull final List<ListLinkHandler> tabs,
@Nonnull final String... expectedTabs) {
final Set<String> tabSet = tabs.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.schabi.newpipe.extractor.services;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.InfoItemsCollector;
import org.schabi.newpipe.extractor.MediaFormat;
Expand All @@ -20,16 +21,19 @@
import java.time.format.DateTimeFormatter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEqualsOrderIndependent;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertGreaterOrEqual;
Expand Down Expand Up @@ -447,6 +451,7 @@ public void testMetaInfo() throws Exception {
final List<MetaInfo> metaInfoList = extractor().getMetaInfo();
final List<MetaInfo> expectedMetaInfoList = expectedMetaInfo();

final List<Executable> assertions = new ArrayList<>();
for (final MetaInfo expectedMetaInfo : expectedMetaInfoList) {
final List<String> texts = metaInfoList.stream()
.map((metaInfo) -> metaInfo.getContent().getContent())
Expand All @@ -457,16 +462,17 @@ public void testMetaInfo() throws Exception {
final List<String> urlTexts = metaInfoList.stream().flatMap(info -> info.getUrlTexts().stream())
.collect(Collectors.toList());

assertTrue(texts.contains(expectedMetaInfo.getContent().getContent()));
assertTrue(titles.contains(expectedMetaInfo.getTitle()));
assertions.add(() -> assertContains(expectedMetaInfo.getContent().getContent(), texts));
assertions.add(() -> assertContains(expectedMetaInfo.getTitle(), titles));

for (final String expectedUrlText : expectedMetaInfo.getUrlTexts()) {
assertTrue(urlTexts.contains(expectedUrlText));
assertions.add(() -> assertContains(expectedUrlText, urlTexts));
}
for (final URL expectedUrl : expectedMetaInfo.getUrls()) {
assertTrue(urls.contains(expectedUrl));
assertions.add(() -> assertContains(expectedUrl, urls));
}
}
assertAll(assertions);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public void testTags() {}
}

public static class PublicBroadcasterTest extends DefaultStreamExtractorTest
implements InitYoutubeTest {
implements InitYoutubeTest {
private static final String ID = "cJ9to6EmElQ";
private static final int TIMESTAMP = 0;
private static final String URL = BASE_URL + ID;
Expand Down Expand Up @@ -400,10 +400,8 @@ protected StreamExtractor createExtractor() throws Exception {
@Override public List<MetaInfo> expectedMetaInfo() throws MalformedURLException {
return Collections.singletonList(new MetaInfo(
"",
new Description("Arte is a French/German public broadcast service.",
Description.PLAIN_TEXT),
List.of(new URL(
"https://en.wikipedia.org/wiki/Arte?wprov=yicw1")),
new Description("Arte is a French/German public broadcast service.", Description.PLAIN_TEXT),
List.of(new URL("https://en.wikipedia.org/wiki/Arte?wprov=yicw1")),
List.of("Wikipedia")
));
}
Expand All @@ -417,6 +415,59 @@ protected StreamExtractor createExtractor() throws Exception {
// @formatter:on
}

public static class LicensedDoctorTest extends DefaultStreamExtractorTest
implements InitYoutubeTest {
private static final String ID = "rCAS2eD-mcw";
private static final int TIMESTAMP = 0;
private static final String URL = BASE_URL + ID;

@Override
protected StreamExtractor createExtractor() throws Exception {
return YouTube.getStreamExtractor(URL);
}

// @formatter:off
@Override public StreamingService expectedService() { return YouTube; }
@Override public String expectedName() { return "Laryngeal Mask Airway (LMA) insertion | ESSENTIAL TECHNIQUES for standard patients"; }
@Override public String expectedId() { return ID; }
@Override public String expectedUrlContains() { return BASE_URL + ID; }
@Override public String expectedOriginalUrlContains() { return URL; }

@Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; }
@Override public String expectedUploaderName() { return "ABCs of Anaesthesia"; }
@Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCs1fy2n5Ey0c9VZRBL7UCsg"; }
@Override public long expectedUploaderSubscriberCountAtLeast() { return 200_000; }
@Override public List<String> expectedDescriptionContains() { return Arrays.asList("https://www.facebook.com/groups/2082807131964430", "LMA"); }
@Override public long expectedLength() { return 343; }
@Override public long expectedTimestamp() { return TIMESTAMP; }
@Override public long expectedViewCountAtLeast() { return 60_000; }
@Nullable @Override public String expectedUploadDate() { return "2022-07-03 11:00:25.000"; }
@Nullable @Override public String expectedTextualUploadDate() { return "2022-07-03T04:00:25-07:00"; }
@Override public long expectedLikeCountAtLeast() { return 800; }
@Override public long expectedDislikeCountAtLeast() { return -1; }
@Override public List<MetaInfo> expectedMetaInfo() throws MalformedURLException {
return Collections.singletonList(new MetaInfo(
"",
new Description("From a licensed doctor in Australia", Description.PLAIN_TEXT),
List.of(new URL("https://support.google.com/youtube/answer/9795167")),
List.of("Learn more about how experts define health sources")
));
}
@Override public boolean expectedUploaderVerified() { return true; }
@Override public String expectedLicence() { return YOUTUBE_LICENCE; }
@Override public String expectedCategory() { return "Education"; }
@Override public List<String> expectedTags() {
return Arrays.asList("ANZCA", "Anaesthesia", "FANZCA", "LMA", "Vortex", "abcs of anaesthesia",
"airway", "anaesthesiology", "anaesthetics", "anaesthetist", "anesthesia", "anesthesiologist",
"anesthesiology", "anesthetics", "anesthetist", "bag", "basics", "cannula insertion technique",
"cannulation procedure", "cannulation tips and tricks", "cico", "classic", "cuff", "das",
"difficult airway", "igel", "intravenous cannula insertion", "intubation", "laryngeal", "mask",
"medical", "medicine", "nurse", "oxygenation", "procedure", "proseal", "student", "supreme",
"technique", "tips", "venepuncture", "ventilation");
}
// @formatter:on
}

public static class NoVisualMetadataVideoTest extends DefaultStreamExtractorTest
implements InitYoutubeTest {
// Video without visual metadata on YouTube clients (video title, upload date, channel name,
Expand Down
Loading