[YouTube] Add tests for auto-translated captions

This commit is contained in:
TobiGr 2024-05-10 20:08:16 +02:00
parent 30a4b3617d
commit 0e13ddf4c6
1 changed files with 64 additions and 0 deletions

View File

@ -50,6 +50,7 @@ import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamSegment;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
import java.io.IOException;
import java.net.MalformedURLException;
@ -603,4 +604,67 @@ public class YoutubeStreamExtractorDefaultTest {
.anyMatch(s -> s.getAudioTrackType() == AudioTrackType.DESCRIPTIVE));
}
}
public static class GeneratedSubtitles {
private static YoutubeStreamExtractor extractor;
private static List<SubtitlesStream> subtitles;
@BeforeAll
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "generatedSubtitles"));
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=bvwohQavFV8");
extractor.fetchPage();
subtitles = extractor.getSubtitlesDefault();
}
@Test
void testUploaderProvidedSubtitles() {
assertEquals(1, subtitles.stream().filter(s -> !s.isAutoGenerated()).count());
}
@Test
void testAutoGeneratedSubtitles() {
assertEquals(1, subtitles.stream().filter(
s -> s.isAutoGenerated() && !s.isAutoTranslated()).count());
}
@Test
void testAutoTranslatedSubtitles() {
assertTrue(subtitles.stream().anyMatch(SubtitlesStream::isAutoTranslated));
}
}
public static class GeneratedAndTranslatedSubtitles {
private static YoutubeStreamExtractor extractor;
private static List<SubtitlesStream> subtitles;
@BeforeAll
public static void setUp() throws Exception {
YoutubeTestsUtils.ensureStateless();
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "generatedAndTranslatedSubtitles"));
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=_cMxraX_5RE");
extractor.fetchPage();
subtitles = extractor.getSubtitlesDefault();
}
@Test
void testUploaderProvidedSubtitles() {
System.out.println("Getestet");
assertEquals(9, subtitles.stream().filter(s -> !s.isAutoGenerated()).count());
}
@Test
void testAutoGeneratedSubtitles() {
assertFalse(subtitles.stream().anyMatch(s -> s.isAutoGenerated() && !s.isAutoTranslated()));
}
@Test
void testAutoTranslatedSubtitles() {
assertTrue(subtitles.stream().anyMatch(SubtitlesStream::isAutoTranslated));
}
}
}