NewPipeExtractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java

79 lines
2.5 KiB
Java
Raw Normal View History

2017-03-01 18:47:52 +01:00
package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
2017-03-01 18:47:52 +01:00
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
2017-08-07 18:12:51 +02:00
import org.schabi.newpipe.extractor.user.UserExtractor;
2017-03-01 18:47:52 +01:00
import java.io.IOException;
public abstract class StreamingService {
public class ServiceInfo {
2017-08-06 22:20:15 +02:00
public final String name;
public ServiceInfo(String name) {
this.name = name;
}
2017-03-01 18:47:52 +01:00
}
public enum LinkType {
NONE,
STREAM,
2017-08-07 18:12:51 +02:00
USER,
2017-03-01 18:47:52 +01:00
PLAYLIST
}
2017-08-06 22:20:15 +02:00
private final int serviceId;
private final ServiceInfo serviceInfo;
2017-03-01 18:47:52 +01:00
2017-08-06 22:20:15 +02:00
public StreamingService(int id, String name) {
this.serviceId = id;
this.serviceInfo = new ServiceInfo(name);
}
public final int getServiceId() {
return serviceId;
2017-03-01 18:47:52 +01:00
}
2017-08-06 22:20:15 +02:00
public ServiceInfo getServiceInfo() {
return serviceInfo;
}
2017-08-06 22:20:15 +02:00
public abstract UrlIdHandler getStreamUrlIdHandler();
2017-08-07 18:12:51 +02:00
public abstract UrlIdHandler getUserUrlIdHandler();
2017-08-06 22:20:15 +02:00
public abstract UrlIdHandler getPlaylistUrlIdHandler();
public abstract SearchEngine getSearchEngine();
public abstract SuggestionExtractor getSuggestionExtractor();
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
2017-08-07 18:12:51 +02:00
public abstract UserExtractor getUserExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
2017-08-06 22:20:15 +02:00
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
2017-03-01 18:47:52 +01:00
2017-08-07 18:12:51 +02:00
public UserExtractor getUserExtractor(String url) throws IOException, ExtractionException {
return getUserExtractor(url, null);
2017-08-06 22:20:15 +02:00
}
2017-08-06 22:20:15 +02:00
public PlaylistExtractor getPlaylistExtractor(String url) throws IOException, ExtractionException {
return getPlaylistExtractor(url, null);
2017-03-01 18:47:52 +01:00
}
/**
2017-08-07 18:12:51 +02:00
* figure out where the link is pointing to (a user, video, playlist, etc.)
2017-03-01 18:47:52 +01:00
*/
public final LinkType getLinkTypeByUrl(String url) {
2017-08-06 22:20:15 +02:00
UrlIdHandler sH = getStreamUrlIdHandler();
2017-08-07 18:12:51 +02:00
UrlIdHandler cH = getUserUrlIdHandler();
2017-08-06 22:20:15 +02:00
UrlIdHandler pH = getPlaylistUrlIdHandler();
2017-03-01 18:47:52 +01:00
if (sH.acceptUrl(url)) {
2017-03-01 18:47:52 +01:00
return LinkType.STREAM;
} else if (cH.acceptUrl(url)) {
2017-08-07 18:12:51 +02:00
return LinkType.USER;
} else if (pH.acceptUrl(url)) {
return LinkType.PLAYLIST;
2017-03-01 18:47:52 +01:00
} else {
return LinkType.NONE;
}
}
}