2017-08-06 22:20:15 +02:00
|
|
|
package org.schabi.newpipe.extractor;
|
|
|
|
|
2022-05-09 20:59:25 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
2017-08-16 04:40:03 +02:00
|
|
|
import static org.schabi.newpipe.extractor.NewPipe.getServiceByUrl;
|
2020-06-27 15:47:49 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
2017-08-07 18:12:51 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2022-05-09 20:59:25 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
public class NewPipeTest {
|
|
|
|
@Test
|
|
|
|
public void getAllServicesTest() throws Exception {
|
2018-02-10 03:46:05 +01:00
|
|
|
assertEquals(NewPipe.getServices().size(), ServiceList.all().size());
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAllServicesHaveDifferentId() throws Exception {
|
2022-05-09 20:59:25 +02:00
|
|
|
final HashSet<Integer> servicesId = new HashSet<>();
|
|
|
|
for (final StreamingService streamingService : NewPipe.getServices()) {
|
2021-12-27 21:08:08 +01:00
|
|
|
final String errorMsg =
|
|
|
|
"There are services with the same id = " + streamingService.getServiceId()
|
|
|
|
+ " (current service > " + streamingService.getServiceInfo().getName() + ")";
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2021-12-27 21:08:08 +01:00
|
|
|
assertTrue(servicesId.add(streamingService.getServiceId()), errorMsg);
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getServiceWithId() throws Exception {
|
2018-02-10 03:46:05 +01:00
|
|
|
assertEquals(NewPipe.getService(YouTube.getServiceId()), YouTube);
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getServiceWithUrl() throws Exception {
|
2018-02-10 03:46:05 +01:00
|
|
|
assertEquals(getServiceByUrl("https://www.youtube.com/watch?v=_r6CgaFNAGg"), YouTube);
|
|
|
|
assertEquals(getServiceByUrl("https://www.youtube.com/channel/UCi2bIyFtz-JdI-ou8kaqsqg"), YouTube);
|
|
|
|
assertEquals(getServiceByUrl("https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH"), YouTube);
|
2020-06-27 15:47:49 +02:00
|
|
|
assertEquals(getServiceByUrl("https://www.google.it/url?sa=t&rct=j&q=&esrc=s&cd=&cad=rja&uact=8&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DHu80uDzh8RY&source=video"), YouTube);
|
2018-02-10 03:46:05 +01:00
|
|
|
|
2020-06-27 15:47:49 +02:00
|
|
|
assertEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), SoundCloud);
|
|
|
|
assertEquals(getServiceByUrl("https://www.google.com/url?sa=t&url=https%3A%2F%2Fsoundcloud.com%2Fciaoproduction&rct=j&q=&esrc=s&source=web&cd="), SoundCloud);
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
}
|