NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/PeertubeService.java

160 lines
6.3 KiB
Java
Raw Normal View History

2018-10-11 21:10:22 +02:00
package org.schabi.newpipe.extractor.services.peertube;
2019-03-07 22:39:05 +01:00
import static java.util.Arrays.asList;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
2018-10-11 21:10:22 +02:00
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;
import java.io.IOException;
import java.util.List;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelExtractor;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeCommentsExtractor;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSearchExtractor;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeStreamExtractor;
2018-10-12 09:34:51 +02:00
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeSuggestionExtractor;
2018-10-11 21:10:22 +02:00
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeCommentsLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeTrendingLinkHandlerFactory;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
2019-11-19 22:38:17 +01:00
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
2018-10-11 21:10:22 +02:00
public class PeertubeService extends StreamingService {
private PeertubeInstance instance;
public PeertubeService(int id) {
this(id, PeertubeInstance.defaultInstance);
}
public PeertubeService(int id, PeertubeInstance instance) {
2019-11-23 22:05:41 +01:00
super(id, "PeerTube", asList(VIDEO, COMMENTS));
2018-10-11 21:10:22 +02:00
this.instance = instance;
}
@Override
public LinkHandlerFactory getStreamLHFactory() {
return PeertubeStreamLinkHandlerFactory.getInstance();
}
@Override
public ListLinkHandlerFactory getChannelLHFactory() {
return PeertubeChannelLinkHandlerFactory.getInstance();
}
@Override
public ListLinkHandlerFactory getPlaylistLHFactory() {
// TODO Auto-generated method stub
return null;
}
@Override
public SearchQueryHandlerFactory getSearchQHFactory() {
return PeertubeSearchQueryHandlerFactory.getInstance();
}
@Override
public ListLinkHandlerFactory getCommentsLHFactory() {
return PeertubeCommentsLinkHandlerFactory.getInstance();
}
@Override
2019-11-19 22:38:17 +01:00
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) {
return new PeertubeSearchExtractor(this, queryHandler);
2018-10-11 21:10:22 +02:00
}
@Override
2019-11-19 22:38:17 +01:00
public SuggestionExtractor getSuggestionExtractor() {
return new PeertubeSuggestionExtractor(this);
2018-10-11 21:10:22 +02:00
}
@Override
public SubscriptionExtractor getSubscriptionExtractor() {
// TODO Auto-generated method stub
return null;
}
@Override
2019-11-19 22:38:17 +01:00
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler)
2018-10-11 21:10:22 +02:00
throws ExtractionException {
2019-11-19 22:38:17 +01:00
return new PeertubeChannelExtractor(this, linkHandler);
2018-10-11 21:10:22 +02:00
}
@Override
2019-11-19 22:38:17 +01:00
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler)
2018-10-11 21:10:22 +02:00
throws ExtractionException {
// TODO Auto-generated method stub
return null;
}
@Override
2019-11-19 22:38:17 +01:00
public StreamExtractor getStreamExtractor(LinkHandler linkHandler)
2018-10-11 21:10:22 +02:00
throws ExtractionException {
2019-11-19 22:38:17 +01:00
return new PeertubeStreamExtractor(this, linkHandler);
2018-10-11 21:10:22 +02:00
}
@Override
2019-11-19 22:38:17 +01:00
public CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
2018-10-11 21:10:22 +02:00
throws ExtractionException {
2019-11-19 22:38:17 +01:00
return new PeertubeCommentsExtractor(this, linkHandler);
2018-10-11 21:10:22 +02:00
}
@Override
public String getBaseUrl() {
return instance.getUrl();
}
2019-11-22 19:35:49 +01:00
public void setInstance(PeertubeInstance instance) {
2019-11-22 18:29:14 +01:00
this.instance = instance;
2018-10-11 21:10:22 +02:00
}
2018-12-29 17:28:43 +01:00
2018-12-25 14:42:22 +01:00
@Override
public KioskList getKioskList() throws ExtractionException {
KioskList.KioskExtractorFactory kioskFactory = new KioskList.KioskExtractorFactory() {
@Override
public KioskExtractor createNewKiosk(StreamingService streamingService,
String url,
2019-11-19 22:38:17 +01:00
String id)
2018-12-25 14:42:22 +01:00
throws ExtractionException {
return new PeertubeTrendingExtractor(PeertubeService.this,
2019-11-19 22:38:17 +01:00
new PeertubeTrendingLinkHandlerFactory().fromId(id), id);
2018-12-25 14:42:22 +01:00
}
};
2019-11-19 22:38:17 +01:00
KioskList list = new KioskList(this);
2018-12-25 14:42:22 +01:00
// add kiosks here e.g.:
final PeertubeTrendingLinkHandlerFactory h = new PeertubeTrendingLinkHandlerFactory();
try {
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_TRENDING);
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_RECENT);
list.addKioskEntry(kioskFactory, h, PeertubeTrendingLinkHandlerFactory.KIOSK_LOCAL);
list.setDefaultKiosk(PeertubeTrendingLinkHandlerFactory.KIOSK_TRENDING);
} catch (Exception e) {
throw new ExtractionException(e);
}
return list;
}
2018-10-11 21:10:22 +02:00
}