NewPipeExtractor/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java

54 lines
2.3 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor.services.youtube;
2021-12-27 21:08:08 +01:00
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
2021-01-17 18:55:37 +01:00
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2020-05-30 17:20:54 +02:00
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2020-02-29 17:18:50 +01:00
import java.io.IOException;
import java.util.Random;
2020-02-29 17:18:50 +01:00
2021-12-27 21:08:08 +01:00
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class YoutubeParsingHelperTest {
2021-01-17 18:55:37 +01:00
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/";
2021-12-27 21:08:08 +01:00
@BeforeAll
2021-01-17 18:55:37 +01:00
public static void setUp() throws IOException {
YoutubeParsingHelper.resetClientVersionAndKey();
YoutubeParsingHelper.setNumberGenerator(new Random(1));
2021-01-17 18:55:37 +01:00
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "youtubeParsingHelper"));
}
@Test
2021-06-02 19:51:50 +02:00
public void testAreHardcodedClientVersionAndKeyValid() throws IOException, ExtractionException {
2021-12-27 21:08:08 +01:00
assertTrue(YoutubeParsingHelper.areHardcodedClientVersionAndKeyValid(),
"Hardcoded client version and key are not valid anymore");
}
2020-03-20 12:23:58 +01:00
@Test
public void testAreHardcodedYoutubeMusicKeysValid() throws IOException, ExtractionException {
2021-12-27 21:08:08 +01:00
assertTrue(YoutubeParsingHelper.isHardcodedYoutubeMusicKeyValid(),
"Hardcoded YouTube Music keys are not valid anymore");
2020-03-20 12:23:58 +01:00
}
2020-05-30 17:20:54 +02:00
@Test
public void testParseDurationString() throws ParsingException {
assertEquals(1162567, YoutubeParsingHelper.parseDurationString("12:34:56:07"));
assertEquals(4445767, YoutubeParsingHelper.parseDurationString("1,234:56:07"));
assertEquals(754, YoutubeParsingHelper.parseDurationString("12:34 "));
}
@Test
public void testConvertFromGoogleCacheUrl() {
assertEquals("https://mohfw.gov.in/",
YoutubeParsingHelper.extractCachedUrlIfNeeded("https://webcache.googleusercontent.com/search?q=cache:https://mohfw.gov.in/"));
assertEquals("https://www.infektionsschutz.de/coronavirus-sars-cov-2.html",
YoutubeParsingHelper.extractCachedUrlIfNeeded("https://www.infektionsschutz.de/coronavirus-sars-cov-2.html"));
}
}