Add getInfoFromFeed to ChannelInfo and FeedUrlIdHandler to services
This commit is contained in:
parent
58a3ffd1b9
commit
4edecd17c2
|
@ -1,6 +1,7 @@
|
|||
package org.schabi.newpipe.extractor;
|
||||
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.channel.FeedExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
|
@ -10,6 +11,7 @@ import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
|||
import java.io.IOException;
|
||||
|
||||
public abstract class StreamingService {
|
||||
|
||||
public class ServiceInfo {
|
||||
public final String name;
|
||||
|
||||
|
@ -22,7 +24,8 @@ public abstract class StreamingService {
|
|||
NONE,
|
||||
STREAM,
|
||||
CHANNEL,
|
||||
PLAYLIST
|
||||
PLAYLIST,
|
||||
CHANNEL_FEED
|
||||
}
|
||||
|
||||
private final int serviceId;
|
||||
|
@ -44,13 +47,19 @@ public abstract class StreamingService {
|
|||
public abstract UrlIdHandler getStreamUrlIdHandler();
|
||||
public abstract UrlIdHandler getChannelUrlIdHandler();
|
||||
public abstract UrlIdHandler getPlaylistUrlIdHandler();
|
||||
public abstract UrlIdHandler getFeedUrlIdHandler();
|
||||
public abstract SearchEngine getSearchEngine();
|
||||
public abstract SuggestionExtractor getSuggestionExtractor();
|
||||
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
|
||||
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
|
||||
public abstract FeedExtractor getFeedExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
|
||||
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
|
||||
public abstract KioskList getKioskList() throws ExtractionException;
|
||||
|
||||
public FeedExtractor getFeedExtractor(String url) throws IOException, ExtractionException {
|
||||
return getFeedExtractor(url, null);
|
||||
}
|
||||
|
||||
public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
|
||||
return getChannelExtractor(url, null);
|
||||
}
|
||||
|
@ -66,6 +75,7 @@ public abstract class StreamingService {
|
|||
UrlIdHandler sH = getStreamUrlIdHandler();
|
||||
UrlIdHandler cH = getChannelUrlIdHandler();
|
||||
UrlIdHandler pH = getPlaylistUrlIdHandler();
|
||||
UrlIdHandler fH = getFeedUrlIdHandler();
|
||||
|
||||
if (sH.acceptUrl(url)) {
|
||||
return LinkType.STREAM;
|
||||
|
@ -73,6 +83,8 @@ public abstract class StreamingService {
|
|||
return LinkType.CHANNEL;
|
||||
} else if (pH.acceptUrl(url)) {
|
||||
return LinkType.PLAYLIST;
|
||||
} else if (fH.acceptUrl(url)) {
|
||||
return LinkType.CHANNEL_FEED;
|
||||
} else {
|
||||
return LinkType.NONE;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ public class ChannelInfo 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);
|
||||
}
|
||||
|
@ -46,6 +45,66 @@ public class ChannelInfo extends ListInfo {
|
|||
return service.getChannelExtractor(url, nextStreamsUrl).getNextStreams();
|
||||
}
|
||||
|
||||
public static ChannelInfo getInfoFromFeed(String url) throws IOException, ExtractionException {
|
||||
return getInfoFromFeed(NewPipe.getServiceByUrl(url), url);
|
||||
}
|
||||
|
||||
public static ChannelInfo getInfoFromFeed(ServiceList serviceItem, String url) throws IOException, ExtractionException {
|
||||
return getInfoFromFeed(serviceItem.getService(), url);
|
||||
}
|
||||
|
||||
public static ChannelInfo getInfoFromFeed(StreamingService service, String url) throws IOException, ExtractionException {
|
||||
ChannelExtractor extractor = service.getFeedExtractor(url);
|
||||
extractor.fetchPage();
|
||||
return getInfoFromFeed(service.getFeedExtractor(url));
|
||||
}
|
||||
|
||||
public static ChannelInfo getInfoFromFeed(FeedExtractor extractor) throws ParsingException {
|
||||
|
||||
// important data
|
||||
int serviceId = extractor.getServiceId();
|
||||
String url = extractor.getCleanUrl();
|
||||
String id = extractor.getId();
|
||||
String name = extractor.getName();
|
||||
|
||||
ChannelInfo info = new ChannelInfo(serviceId, url, id, name);
|
||||
|
||||
|
||||
try {
|
||||
info.setAvatarUrl(extractor.getAvatarUrl());
|
||||
} catch (Exception e) {
|
||||
info.addError(e);
|
||||
}
|
||||
try {
|
||||
info.setBannerUrl(extractor.getBannerUrl());
|
||||
} catch (Exception e) {
|
||||
info.addError(e);
|
||||
}
|
||||
try {
|
||||
info.setFeedUrl(extractor.getFeedUrl());
|
||||
} catch (Exception e) {
|
||||
info.addError(e);
|
||||
}
|
||||
|
||||
info.setRelatedStreams(ExtractorHelper.getStreamsOrLogError(info, extractor));
|
||||
|
||||
try {
|
||||
info.setSubscriberCount(extractor.getSubscriberCount());
|
||||
} catch (Exception e) {
|
||||
info.addError(e);
|
||||
}
|
||||
try {
|
||||
info.setDescription(extractor.getDescription());
|
||||
} catch (Exception e) {
|
||||
info.addError(e);
|
||||
}
|
||||
|
||||
info.setHasMoreStreams(extractor.hasMoreStreams());
|
||||
info.setNextStreamsUrl(extractor.getNextStreamsUrl());
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
|
||||
return getInfo(NewPipe.getServiceByUrl(url), url);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.schabi.newpipe.extractor.StreamingService;
|
|||
import org.schabi.newpipe.extractor.SuggestionExtractor;
|
||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.channel.FeedExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
|
@ -39,6 +40,10 @@ public class SoundcloudService extends StreamingService {
|
|||
return SoundcloudPlaylistUrlIdHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UrlIdHandler getFeedUrlIdHandler() {
|
||||
return SoundcloudFeedUrlIdHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException {
|
||||
|
@ -50,6 +55,12 @@ public class SoundcloudService extends StreamingService {
|
|||
return new SoundcloudChannelExtractor(this, url, nextStreamsUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedExtractor getFeedExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException {
|
||||
return new SoundcloudFeedExtractor(this, url, nextStreamsUrl);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException {
|
||||
return new SoundcloudPlaylistExtractor(this, url, nextStreamsUrl);
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.schabi.newpipe.extractor.StreamingService;
|
|||
import org.schabi.newpipe.extractor.SuggestionExtractor;
|
||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.channel.FeedExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
|
@ -60,6 +61,11 @@ public class YoutubeService extends StreamingService {
|
|||
return YoutubePlaylistUrlIdHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UrlIdHandler getFeedUrlIdHandler() {
|
||||
return YoutubeFeedUrlIdHandler.getInstance();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException {
|
||||
|
@ -71,6 +77,11 @@ public class YoutubeService extends StreamingService {
|
|||
return new YoutubeChannelExtractor(this, url, nextStreamsUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeedExtractor getFeedExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException {
|
||||
return new YoutubeFeedExtractor(this, url, nextStreamsUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException {
|
||||
return new YoutubePlaylistExtractor(this, url, nextStreamsUrl);
|
||||
|
|
Loading…
Reference in New Issue