2020-02-28 16:36:14 +01:00
|
|
|
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;
|
2020-02-28 16:36:14 +01:00
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
2020-02-29 22:42:43 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2020-05-30 17:20:54 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2020-02-28 16:36:14 +01:00
|
|
|
|
2020-02-29 17:18:50 +01:00
|
|
|
import java.io.IOException;
|
2021-04-09 11:58:05 +02:00
|
|
|
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;
|
2020-02-28 16:36:14 +01:00
|
|
|
|
|
|
|
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();
|
2021-04-09 11:58:05 +02:00
|
|
|
YoutubeParsingHelper.setNumberGenerator(new Random(1));
|
2021-01-17 18:55:37 +01:00
|
|
|
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "youtubeParsingHelper"));
|
2020-02-28 16:36:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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-02-28 16:36:14 +01:00
|
|
|
}
|
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 "));
|
|
|
|
}
|
2020-12-20 19:54:12 +01:00
|
|
|
|
|
|
|
@Test
|
2021-07-09 18:23:46 +02:00
|
|
|
public void testConvertFromGoogleCacheUrl() {
|
2020-12-20 19:54:12 +01:00
|
|
|
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"));
|
|
|
|
}
|
2020-02-28 16:36:14 +01:00
|
|
|
}
|