Skip to content

Commit 0e13ddf

Browse files
committed
[YouTube] Add tests for auto-translated captions
1 parent 30a4b36 commit 0e13ddf

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.schabi.newpipe.extractor.stream.StreamExtractor;
5151
import org.schabi.newpipe.extractor.stream.StreamSegment;
5252
import org.schabi.newpipe.extractor.stream.StreamType;
53+
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
5354

5455
import java.io.IOException;
5556
import java.net.MalformedURLException;
@@ -603,4 +604,67 @@ void testCheckDescriptiveAudio() throws Exception {
603604
.anyMatch(s -> s.getAudioTrackType() == AudioTrackType.DESCRIPTIVE));
604605
}
605606
}
607+
608+
public static class GeneratedSubtitles {
609+
private static YoutubeStreamExtractor extractor;
610+
private static List<SubtitlesStream> subtitles;
611+
612+
@BeforeAll
613+
public static void setUp() throws Exception {
614+
YoutubeTestsUtils.ensureStateless();
615+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "generatedSubtitles"));
616+
extractor = (YoutubeStreamExtractor) YouTube
617+
.getStreamExtractor("https://www.youtube.com/watch?v=bvwohQavFV8");
618+
extractor.fetchPage();
619+
subtitles = extractor.getSubtitlesDefault();
620+
}
621+
622+
@Test
623+
void testUploaderProvidedSubtitles() {
624+
assertEquals(1, subtitles.stream().filter(s -> !s.isAutoGenerated()).count());
625+
}
626+
627+
@Test
628+
void testAutoGeneratedSubtitles() {
629+
assertEquals(1, subtitles.stream().filter(
630+
s -> s.isAutoGenerated() && !s.isAutoTranslated()).count());
631+
}
632+
633+
@Test
634+
void testAutoTranslatedSubtitles() {
635+
assertTrue(subtitles.stream().anyMatch(SubtitlesStream::isAutoTranslated));
636+
}
637+
}
638+
639+
public static class GeneratedAndTranslatedSubtitles {
640+
private static YoutubeStreamExtractor extractor;
641+
private static List<SubtitlesStream> subtitles;
642+
643+
@BeforeAll
644+
public static void setUp() throws Exception {
645+
YoutubeTestsUtils.ensureStateless();
646+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "generatedAndTranslatedSubtitles"));
647+
extractor = (YoutubeStreamExtractor) YouTube
648+
.getStreamExtractor("https://www.youtube.com/watch?v=_cMxraX_5RE");
649+
extractor.fetchPage();
650+
subtitles = extractor.getSubtitlesDefault();
651+
}
652+
653+
@Test
654+
void testUploaderProvidedSubtitles() {
655+
System.out.println("Getestet");
656+
assertEquals(9, subtitles.stream().filter(s -> !s.isAutoGenerated()).count());
657+
}
658+
659+
@Test
660+
void testAutoGeneratedSubtitles() {
661+
assertFalse(subtitles.stream().anyMatch(s -> s.isAutoGenerated() && !s.isAutoTranslated()));
662+
}
663+
664+
@Test
665+
void testAutoTranslatedSubtitles() {
666+
assertTrue(subtitles.stream().anyMatch(SubtitlesStream::isAutoTranslated));
667+
}
668+
669+
}
606670
}

0 commit comments

Comments
 (0)