2021-07-17 19:10:09 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube;
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.allOf;
|
|
|
|
import static org.hamcrest.CoreMatchers.containsString;
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
|
2021-07-20 20:48:11 +02:00
|
|
|
public class YoutubeJavaScriptExtractorTest {
|
2021-07-17 19:10:09 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setup() throws IOException {
|
|
|
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-07-20 20:48:11 +02:00
|
|
|
public void testExtractJavaScript__success() throws ParsingException {
|
|
|
|
String playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptCode("d4IGg5dqeO8");
|
2021-07-17 19:10:09 +02:00
|
|
|
assertPlayerJsCode(playerJsCode);
|
|
|
|
|
2021-07-20 20:48:11 +02:00
|
|
|
playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptCode();
|
2021-07-17 19:10:09 +02:00
|
|
|
assertPlayerJsCode(playerJsCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2021-07-20 20:48:11 +02:00
|
|
|
public void testExtractJavaScript__invalidVideoId__success() throws ParsingException {
|
|
|
|
String playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptCode("not_a_video_id");
|
2021-07-17 19:10:09 +02:00
|
|
|
assertPlayerJsCode(playerJsCode);
|
|
|
|
|
2021-07-20 20:48:11 +02:00
|
|
|
playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptCode("11-chars123");
|
2021-07-17 19:10:09 +02:00
|
|
|
assertPlayerJsCode(playerJsCode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-27 17:24:27 +02:00
|
|
|
private void assertPlayerJsCode(final String playerJsCode) {
|
2021-07-17 19:10:09 +02:00
|
|
|
assertThat(playerJsCode, allOf(
|
|
|
|
containsString(" Copyright The Closure Library Authors.\n"
|
|
|
|
+ " SPDX-License-Identifier: Apache-2.0"),
|
|
|
|
containsString("var _yt_player")));
|
|
|
|
}
|
|
|
|
}
|