Improve ServiceList class

- [Minor] Fix wrong arguments order in KioskInfo
This commit is contained in:
Mauricio Colli 2018-02-10 00:46:05 -02:00
parent 42411099db
commit f3865445f5
33 changed files with 153 additions and 177 deletions

View File

@ -22,6 +22,8 @@ package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import java.util.List;
/**
* Provides access to streaming services supported by NewPipe.
*/
@ -44,37 +46,32 @@ public class NewPipe {
// Utils
//////////////////////////////////////////////////////////////////////////*/
public static StreamingService[] getServices() {
final ServiceList[] values = ServiceList.values();
final StreamingService[] streamingServices = new StreamingService[values.length];
for (int i = 0; i < values.length; i++) streamingServices[i] = values[i].getService();
return streamingServices;
public static List<StreamingService> getServices() {
return ServiceList.all();
}
public static StreamingService getService(int serviceId) throws ExtractionException {
for (ServiceList item : ServiceList.values()) {
if (item.getService().getServiceId() == serviceId) {
return item.getService();
for (StreamingService service : ServiceList.all()) {
if (service.getServiceId() == serviceId) {
return service;
}
}
throw new ExtractionException("There's no service with the id = \"" + serviceId + "\"");
}
public static StreamingService getService(String serviceName) throws ExtractionException {
for (ServiceList item : ServiceList.values()) {
if (item.getService().getServiceInfo().name.equals(serviceName)) {
return item.getService();
for (StreamingService service : ServiceList.all()) {
if (service.getServiceInfo().getName().equals(serviceName)) {
return service;
}
}
throw new ExtractionException("There's no service with the name = \"" + serviceName + "\"");
}
public static StreamingService getServiceByUrl(String url) throws ExtractionException {
for (ServiceList item : ServiceList.values()) {
if (item.getService().getLinkTypeByUrl(url) != StreamingService.LinkType.NONE) {
return item.getService();
for (StreamingService service : ServiceList.all()) {
if (service.getLinkTypeByUrl(url) != StreamingService.LinkType.NONE) {
return service;
}
}
throw new ExtractionException("No service can handle the url = \"" + url + "\"");
@ -92,7 +89,7 @@ public class NewPipe {
public static String getNameOfService(int id) {
try {
//noinspection ConstantConditions
return getService(id).getServiceInfo().name;
return getService(id).getServiceInfo().getName();
} catch (Exception e) {
System.err.println("Service id not known");
e.printStackTrace();

View File

@ -3,34 +3,34 @@ package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService;
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
import java.util.List;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
/**
* A list of supported services.
*/
public enum ServiceList {
YouTube(new YoutubeService(0, "YouTube")),
SoundCloud(new SoundcloudService(1, "SoundCloud"));
// DailyMotion(new DailyMotionService(2, "DailyMotion"));
private final StreamingService service;
ServiceList(StreamingService service) {
this.service = service;
public final class ServiceList {
private ServiceList() {
//no instance
}
public StreamingService getService() {
return service;
}
public static final YoutubeService YouTube;
public static final SoundcloudService SoundCloud;
public StreamingService.ServiceInfo getServiceInfo() {
return service.getServiceInfo();
}
private static final List<StreamingService> SERVICES = unmodifiableList(asList(
YouTube = new YoutubeService(0),
SoundCloud = new SoundcloudService(1)
// DailyMotion = new DailyMotionService(2);
));
public int getId() {
return service.getServiceId();
}
@Override
public String toString() {
return service.getServiceInfo().name;
/**
* Get all the supported services.
*
* @return a unmodifiable list of all the supported services
*/
public static List<StreamingService> all() {
return SERVICES;
}
}

View File

@ -8,13 +8,29 @@ import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
public abstract class StreamingService {
public class ServiceInfo {
public final String name;
public static class ServiceInfo {
private final String name;
private final List<MediaCapability> mediaCapabilities;
public ServiceInfo(String name) {
public ServiceInfo(String name, List<MediaCapability> mediaCapabilities) {
this.name = name;
this.mediaCapabilities = Collections.unmodifiableList(mediaCapabilities);
}
public String getName() {
return name;
}
public List<MediaCapability> getMediaCapabilities() {
return mediaCapabilities;
}
public enum MediaCapability {
AUDIO, VIDEO, LIVE
}
}
@ -28,9 +44,9 @@ public abstract class StreamingService {
private final int serviceId;
private final ServiceInfo serviceInfo;
public StreamingService(int id, String name) {
public StreamingService(int id, String name, List<ServiceInfo.MediaCapability> capabilities) {
this.serviceId = id;
this.serviceInfo = new ServiceInfo(name);
this.serviceInfo = new ServiceInfo(name, capabilities);
}
public final int getServiceId() {
@ -41,6 +57,11 @@ public abstract class StreamingService {
return serviceInfo;
}
@Override
public String toString() {
return serviceId + ":" + serviceInfo.getName();
}
public abstract UrlIdHandler getStreamUrlIdHandler();
public abstract UrlIdHandler getChannelUrlIdHandler();
public abstract UrlIdHandler getPlaylistUrlIdHandler();

View File

@ -3,7 +3,6 @@ package org.schabi.newpipe.extractor.channel;
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -38,11 +37,7 @@ public class ChannelInfo extends ListInfo {
}
public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
}
public static NextItemsResult getMoreItems(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
public static NextItemsResult getMoreItems(StreamingService service, String url, String nextStreamsUrl, String contentLanguage) throws IOException, ExtractionException {
return service.getChannelExtractor(url, nextStreamsUrl).getNextStreams();
}
@ -50,10 +45,6 @@ public class ChannelInfo extends ListInfo {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static ChannelInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException {
return getInfo(serviceItem.getService(), url);
}
public static ChannelInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
ChannelExtractor extractor = service.getChannelExtractor(url);
extractor.fetchPage();

View File

@ -20,7 +20,10 @@ package org.schabi.newpipe.extractor.kiosk;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
@ -32,13 +35,6 @@ public class KioskInfo extends ListInfo {
super(serviceId, id, url, name);
}
public static ListExtractor.NextItemsResult getMoreItems(ServiceList serviceItem,
String url,
String nextStreamsUrl,
String contentCountry) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl, contentCountry);
}
public static ListExtractor.NextItemsResult getMoreItems(StreamingService service,
String url,
String nextStreamsUrl,
@ -54,12 +50,6 @@ public class KioskInfo extends ListInfo {
return getInfo(NewPipe.getServiceByUrl(url), url, contentCountry);
}
public static KioskInfo getInfo(ServiceList serviceItem,
String url,
String contentContry) throws IOException, ExtractionException {
return getInfo(serviceItem.getService(), url, contentContry);
}
public static KioskInfo getInfo(StreamingService service,
String url,
String contentCountry) throws IOException, ExtractionException {
@ -82,7 +72,7 @@ public class KioskInfo extends ListInfo {
String id = extractor.getId();
String url = extractor.getCleanUrl();
KioskInfo info = new KioskInfo(serviceId, name, id, url);
KioskInfo info = new KioskInfo(serviceId, id, name, url);
info.related_streams = ExtractorHelper.getStreamsOrLogError(info, extractor);

View File

@ -1,7 +1,9 @@
package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -15,10 +17,6 @@ public class PlaylistInfo extends ListInfo {
super(serviceId, id, url, name);
}
public static NextItemsResult getMoreItems(ServiceList serviceItem, String url, String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), url, nextStreamsUrl);
}
public static NextItemsResult getMoreItems(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
return service.getPlaylistExtractor(url, nextStreamsUrl).getNextStreams();
}
@ -27,10 +25,6 @@ public class PlaylistInfo extends ListInfo {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static PlaylistInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException {
return getInfo(serviceItem.getService(), url);
}
public static PlaylistInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
PlaylistExtractor extractor = service.getPlaylistExtractor(url);
extractor.fetchPage();

View File

@ -1,7 +1,5 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import java.io.IOException;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.SuggestionExtractor;
import org.schabi.newpipe.extractor.UrlIdHandler;
@ -13,10 +11,15 @@ import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import java.io.IOException;
import static java.util.Collections.singletonList;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
public class SoundcloudService extends StreamingService {
public SoundcloudService(int id, String name) {
super(id, name);
public SoundcloudService(int id) {
super(id, "SoundCloud", singletonList(AUDIO));
}
@Override

View File

@ -13,6 +13,9 @@ import org.schabi.newpipe.extractor.stream.StreamExtractor;
import java.io.IOException;
import static java.util.Arrays.asList;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.*;
/*
* Created by Christian Schabesberger on 23.08.15.
@ -36,8 +39,8 @@ import java.io.IOException;
public class YoutubeService extends StreamingService {
public YoutubeService(int id, String name) {
super(id, name);
public YoutubeService(int id) {
super(id, "YouTube", asList(AUDIO, VIDEO, LIVE));
}
@Override
@ -60,7 +63,6 @@ public class YoutubeService extends StreamingService {
return YoutubePlaylistUrlIdHandler.getInstance();
}
@Override
public StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException {
return new YoutubeStreamExtractor(this, url);

View File

@ -232,10 +232,6 @@ public class StreamInfo extends Info {
return getInfo(NewPipe.getServiceByUrl(url), url);
}
public static StreamInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException {
return getInfo(serviceItem.getService(), url);
}
public static StreamInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
return getInfo(service.getStreamExtractor(url));
}

View File

@ -12,14 +12,14 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
public class NewPipeTest {
@Test
public void getAllServicesTest() throws Exception {
assertEquals(NewPipe.getServices().length, ServiceList.values().length);
assertEquals(NewPipe.getServices().size(), ServiceList.all().size());
}
@Test
public void testAllServicesHaveDifferentId() throws Exception {
HashSet<Integer> servicesId = new HashSet<>();
for (StreamingService streamingService : NewPipe.getServices()) {
String errorMsg = "There are services with the same id = " + streamingService.getServiceId() + " (current service > " + streamingService.getServiceInfo().name + ")";
String errorMsg = "There are services with the same id = " + streamingService.getServiceId() + " (current service > " + streamingService.getServiceInfo().getName() + ")";
assertTrue(errorMsg, servicesId.add(streamingService.getServiceId()));
}
@ -27,46 +27,46 @@ public class NewPipeTest {
@Test
public void getServiceWithId() throws Exception {
assertEquals(NewPipe.getService(YouTube.getId()), YouTube.getService());
assertEquals(NewPipe.getService(SoundCloud.getId()), SoundCloud.getService());
assertEquals(NewPipe.getService(YouTube.getServiceId()), YouTube);
assertEquals(NewPipe.getService(SoundCloud.getServiceId()), SoundCloud);
assertNotEquals(NewPipe.getService(SoundCloud.getId()), YouTube.getService());
assertNotEquals(NewPipe.getService(SoundCloud.getServiceId()), YouTube);
}
@Test
public void getServiceWithName() throws Exception {
assertEquals(NewPipe.getService(YouTube.getServiceInfo().name), YouTube.getService());
assertEquals(NewPipe.getService(SoundCloud.getServiceInfo().name), SoundCloud.getService());
assertEquals(NewPipe.getService(YouTube.getServiceInfo().getName()), YouTube);
assertEquals(NewPipe.getService(SoundCloud.getServiceInfo().getName()), SoundCloud);
assertNotEquals(NewPipe.getService(YouTube.getServiceInfo().name), SoundCloud.getService());
assertNotEquals(NewPipe.getService(YouTube.getServiceInfo().getName()), SoundCloud);
}
@Test
public void getServiceWithUrl() throws Exception {
assertEquals(getServiceByUrl("https://www.youtube.com/watch?v=_r6CgaFNAGg"), YouTube.getService());
assertEquals(getServiceByUrl("https://www.youtube.com/channel/UCi2bIyFtz-JdI-ou8kaqsqg"), YouTube.getService());
assertEquals(getServiceByUrl("https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH"), YouTube.getService());
assertEquals(getServiceByUrl("https://soundcloud.com/shupemoosic/pegboard-nerds-try-this"), SoundCloud.getService());
assertEquals(getServiceByUrl("https://soundcloud.com/deluxe314/sets/pegboard-nerds"), SoundCloud.getService());
assertEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), SoundCloud.getService());
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);
assertEquals(getServiceByUrl("https://soundcloud.com/shupemoosic/pegboard-nerds-try-this"), SoundCloud);
assertEquals(getServiceByUrl("https://soundcloud.com/deluxe314/sets/pegboard-nerds"), SoundCloud);
assertEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), SoundCloud);
assertNotEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), YouTube.getService());
assertNotEquals(getServiceByUrl("https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH"), SoundCloud.getService());
assertNotEquals(getServiceByUrl("https://soundcloud.com/pegboardnerds"), YouTube);
assertNotEquals(getServiceByUrl("https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH"), SoundCloud);
}
@Test
public void getIdWithServiceName() throws Exception {
assertEquals(NewPipe.getIdOfService(YouTube.getServiceInfo().name), YouTube.getId());
assertEquals(NewPipe.getIdOfService(SoundCloud.getServiceInfo().name), SoundCloud.getId());
assertEquals(NewPipe.getIdOfService(YouTube.getServiceInfo().getName()), YouTube.getServiceId());
assertEquals(NewPipe.getIdOfService(SoundCloud.getServiceInfo().getName()), SoundCloud.getServiceId());
assertNotEquals(NewPipe.getIdOfService(SoundCloud.getServiceInfo().name), YouTube.getId());
assertNotEquals(NewPipe.getIdOfService(SoundCloud.getServiceInfo().getName()), YouTube.getServiceId());
}
@Test
public void getServiceNameWithId() throws Exception {
assertEquals(NewPipe.getNameOfService(YouTube.getId()), YouTube.getServiceInfo().name);
assertEquals(NewPipe.getNameOfService(SoundCloud.getId()), SoundCloud.getServiceInfo().name);
assertEquals(NewPipe.getNameOfService(YouTube.getServiceId()), YouTube.getServiceInfo().getName());
assertEquals(NewPipe.getNameOfService(SoundCloud.getServiceId()), SoundCloud.getServiceInfo().getName());
assertNotEquals(NewPipe.getNameOfService(YouTube.getId()), SoundCloud.getServiceInfo().name);
assertNotEquals(NewPipe.getNameOfService(YouTube.getServiceId()), SoundCloud.getServiceInfo().getName());
}
}

View File

@ -22,7 +22,7 @@ public class SoundcloudChannelExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = SoundCloud.getService()
extractor = SoundCloud
.getChannelExtractor("https://soundcloud.com/liluzivert");
extractor.fetchPage();
}

View File

@ -1,11 +1,5 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@ -14,6 +8,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/**
* Test for {@link SoundcloudChartsUrlIdHandler}
*/
@ -24,7 +21,7 @@ public class SoundcloudChartsExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = SoundCloud.getService()
extractor = SoundCloud
.getKioskList()
.getExtractorById("Top 50", null);
extractor.fetchPage();

View File

@ -21,7 +21,7 @@ public class SoundcloudPlaylistExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = SoundCloud.getService()
extractor = SoundCloud
.getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r");
extractor.fetchPage();
}

View File

@ -7,7 +7,6 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
@ -19,7 +18,7 @@ public class SoundcloudSearchEngineAllTest extends BaseSoundcloudSearchTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = SoundCloud.getService().getSearchEngine();
SearchEngine engine = SoundCloud.getSearchEngine();
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert"
// keep in mind that the suggestions can NOT change by country (the parameter "de")

View File

@ -7,9 +7,9 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/**
@ -20,7 +20,7 @@ public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = SoundCloud.getService().getSearchEngine();
SearchEngine engine = SoundCloud.getSearchEngine();
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert"
// keep in mind that the suggestions can NOT change by country (the parameter "de")

View File

@ -7,9 +7,9 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
@ -41,7 +41,7 @@ public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = SoundCloud.getService().getSearchEngine();
SearchEngine engine = SoundCloud.getSearchEngine();
// Search by country not yet implemented
result = engine.search("parkmemme", 0, "", SearchEngine.Filter.PLAYLIST)

View File

@ -7,9 +7,9 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/**
@ -20,7 +20,7 @@ public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = SoundCloud.getService().getSearchEngine();
SearchEngine engine = SoundCloud.getSearchEngine();
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert",
// keep in mind that the suggestions can NOT change by country (the parameter "de")

View File

@ -9,7 +9,6 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.stream.SubtitlesFormat;
import java.io.IOException;
@ -26,7 +25,7 @@ public class SoundcloudStreamExtractorDefaultTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (SoundcloudStreamExtractor) SoundCloud.getService().getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
extractor = (SoundcloudStreamExtractor) SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
extractor.fetchPage();
}
@ -38,7 +37,7 @@ public class SoundcloudStreamExtractorDefaultTest {
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
StreamExtractor extractor = SoundCloud.getService().getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69");
StreamExtractor extractor = SoundCloud.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69");
assertEquals(extractor.getTimeStamp() + "", "69");
}

View File

@ -21,7 +21,7 @@ public class SoundcloudSuggestionExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
suggestionExtractor = SoundCloud.getService().getSuggestionExtractor();
suggestionExtractor = SoundCloud.getSuggestionExtractor();
}
@Test

View File

@ -7,7 +7,6 @@ import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@ -42,7 +41,7 @@ public class YoutubeChannelExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeChannelExtractor) YouTube.getService()
extractor = (YoutubeChannelExtractor) YouTube
.getChannelExtractor("https://www.youtube.com/user/Gronkh");
extractor.fetchPage();
}

View File

@ -28,7 +28,7 @@ public class YoutubePlaylistExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubePlaylistExtractor) YouTube.getService()
extractor = (YoutubePlaylistExtractor) YouTube
.getPlaylistExtractor("https://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj");
extractor.fetchPage();
}
@ -85,7 +85,7 @@ public class YoutubePlaylistExtractorTest {
assertTrue(streams.size() > 60);
assertFalse(streams.contains(null));
for(StreamInfoItem item: streams) {
assertEquals("Service id doesn't match", YouTube.getId(), item.getServiceId());
assertEquals("Service id doesn't match", YouTube.getServiceId(), item.getServiceId());
assertNotNull("Stream type not set: " + item, item.getStreamType());
//assertNotEmpty("Upload date not set: " + item, item.getUploadDate());
assertNotEmpty("Uploader name not set: " + item, item.getUploaderName());

View File

@ -8,14 +8,9 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/*
* Created by Christian Schabesberger on 29.12.15.

View File

@ -7,10 +7,9 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@ -42,7 +41,7 @@ public class YoutubeSearchEngineChannelTest extends BaseYoutubeSearchTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = YouTube.getService().getSearchEngine();
SearchEngine engine = YouTube.getSearchEngine();
// Youtube will suggest "gronkh" instead of "grrunkh"
// keep in mind that the suggestions can change by country (the parameter "de")

View File

@ -8,10 +8,9 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@ -43,7 +42,7 @@ public class YoutubeSearchEnginePlaylistTest extends BaseYoutubeSearchTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = YouTube.getService().getSearchEngine();
SearchEngine engine = YouTube.getSearchEngine();
// Youtube will suggest "gronkh" instead of "grrunkh"
// keep in mind that the suggestions can change by country (the parameter "de")

View File

@ -7,10 +7,9 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchResult;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@ -42,7 +41,7 @@ public class YoutubeSearchEngineStreamTest extends BaseYoutubeSearchTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
SearchEngine engine = YouTube.getService().getSearchEngine();
SearchEngine engine = YouTube.getSearchEngine();
// Youtube will suggest "results" instead of "rsults",
// keep in mind that the suggestions can change by country (the parameter "de")

View File

@ -41,7 +41,7 @@ public class YoutubeServiceTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
service = YouTube.getService();
service = YouTube;
kioskList = service.getKioskList();
}

View File

@ -44,7 +44,7 @@ public class YoutubeStreamExtractorDefaultTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeStreamExtractor) YouTube.getService()
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=rYEDA3JcQqw");
extractor.fetchPage();
}
@ -57,7 +57,7 @@ public class YoutubeStreamExtractorDefaultTest {
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
StreamExtractor extractor = YouTube.getService().getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
assertEquals(extractor.getTimeStamp() + "", "174");
}

View File

@ -43,7 +43,7 @@ public class YoutubeStreamExtractorGemaTest {
public void testGemaError() throws IOException, ExtractionException {
try {
NewPipe.init(Downloader.getInstance());
YouTube.getService().getStreamExtractor("https://www.youtube.com/watch?v=3O1_3zBUKM8");
YouTube.getStreamExtractor("https://www.youtube.com/watch?v=3O1_3zBUKM8");
fail("GemaException should be thrown");
} catch (YoutubeStreamExtractor.GemaException ignored) {

View File

@ -29,7 +29,7 @@ public class YoutubeStreamExtractorRestrictedTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeStreamExtractor) YouTube.getService()
extractor = (YoutubeStreamExtractor) YouTube
.getStreamExtractor("https://www.youtube.com/watch?v=i6JTvzrpBy0");
extractor.fetchPage();
}
@ -41,7 +41,7 @@ public class YoutubeStreamExtractorRestrictedTest {
@Test
public void testGetValidTimeStamp() throws IOException, ExtractionException {
StreamExtractor extractor = YouTube.getService().getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
StreamExtractor extractor = YouTube.getStreamExtractor("https://youtu.be/FmG385_uUys?t=174");
assertEquals(extractor.getTimeStamp() + "", "174");
}

View File

@ -41,7 +41,7 @@ public class YoutubeSuggestionExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
suggestionExtractor = YouTube.getService().getSuggestionExtractor();
suggestionExtractor = YouTube.getSuggestionExtractor();
}
@Test

View File

@ -28,9 +28,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import org.schabi.newpipe.extractor.utils.Utils;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@ -45,7 +43,7 @@ public class YoutubeTrendingExtractorTest {
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance());
extractor = (YoutubeTrendingExtractor) YouTube.getService()
extractor = (YoutubeTrendingExtractor) YouTube
.getKioskList()
.getExtractorById("Trending", null);
extractor.fetchPage();

View File

@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor.services.youtube;
* Created by Christian Schabesberger on 12.08.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* YoutubeTreindingKioskInfoTest.java is part of NewPipe.
* YoutubeTrendingKioskInfoTest.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,7 +28,6 @@ import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@ -36,17 +35,17 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/**
* Test for {@link KioskInfo}
*/
public class YoutubeTreindingKioskInfoTest {
public class YoutubeTrendingKioskInfoTest {
static KioskInfo kioskInfo;
@BeforeClass
public static void setUp()
throws Exception {
NewPipe.init(Downloader.getInstance());
StreamingService service = YouTube.getService();
StreamingService service = YouTube;
UrlIdHandler urlIdHandler = service.getKioskList().getUrlIdHandlerByType("Trending");
kioskInfo = KioskInfo.getInfo(YouTube.getService(), urlIdHandler.getUrl("Trending"), null);
kioskInfo = KioskInfo.getInfo(YouTube, urlIdHandler.getUrl("Trending"), null);
}
@Test

View File

@ -26,11 +26,10 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.UrlIdHandler;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/**
* Test for {@link YoutubeTrendingUrlIdHandler}
@ -40,7 +39,7 @@ public class YoutubeTrendingUrlIdHandlerTest {
@BeforeClass
public static void setUp() throws Exception {
urlIdHandler = YouTube.getService().getKioskList().getUrlIdHandlerByType("Trending");
urlIdHandler = YouTube.getKioskList().getUrlIdHandlerByType("Trending");
NewPipe.init(Downloader.getInstance());
}