add basic setup for kiosk
This commit is contained in:
parent
82824cdd72
commit
316b479199
|
@ -1,7 +1,7 @@
|
|||
package org.schabi.newpipe.extractor;
|
||||
|
||||
/*
|
||||
* Created by the-scrabi on 11.02.17.
|
||||
* Created by Christian Schabesberger on 11.02.17.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
||||
* InfoItem.java is part of NewPipe.
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor;
|
|||
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
|
@ -48,6 +49,7 @@ public abstract class StreamingService {
|
|||
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
|
||||
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
|
||||
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
|
||||
public abstract KioskList getKioskList();
|
||||
|
||||
public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
|
||||
return getChannelExtractor(url, null);
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.schabi.newpipe.extractor.kiosk;
|
||||
|
||||
/*
|
||||
* Created by Christian Schabesberger on 12.08.17.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
||||
* KioskExtractor.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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NewPipe is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class KioskExtractor extends ListExtractor {
|
||||
public KioskExtractor(StreamingService streamingService, String url, String nextStreamsUrl)
|
||||
throws IOException, ExtractionException {
|
||||
super(streamingService, url, nextStreamsUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the kiosk.
|
||||
* eg. Trending, Top & Hot, Top last 24 hours
|
||||
* @return type of kiosk
|
||||
*/
|
||||
public abstract String getType() throws ParsingException;
|
||||
|
||||
@Override
|
||||
public String getId() throws ParsingException {
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() throws ParsingException {
|
||||
return getType();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package org.schabi.newpipe.extractor.kiosk;
|
||||
|
||||
/*
|
||||
* Created by Christian Schabesberger on 12.08.17.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
||||
* KioskInfo.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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* NewPipe is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class KioskInfo extends ListInfo {
|
||||
public String type;
|
||||
|
||||
public static KioskInfo getInfo(String url) throws IOException, ExtractionException {
|
||||
return getInfo(NewPipe.getServiceByUrl(url), url);
|
||||
}
|
||||
|
||||
public static KioskInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException {
|
||||
return getInfo(serviceItem.getService(), url);
|
||||
}
|
||||
|
||||
public static KioskInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
|
||||
KioskList kl = service.getKioskList();
|
||||
KioskExtractor extractor = kl.getExtryctorByUrl(url);
|
||||
return getInfo(extractor);
|
||||
}
|
||||
|
||||
public static KioskInfo getInfo(KioskExtractor extractor) throws ParsingException {
|
||||
KioskInfo info = new KioskInfo();
|
||||
info.type = extractor.getType();
|
||||
|
||||
try {
|
||||
StreamInfoItemCollector c = extractor.getStreams();
|
||||
info.related_streams = c.getItemList();
|
||||
info.errors.addAll(c.getErrors());
|
||||
} catch (Exception e) {
|
||||
info.errors.add(e);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package org.schabi.newpipe.extractor.kiosk;
|
||||
|
||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class KioskList {
|
||||
private int service_id;
|
||||
private HashMap<String, KioskEntry> kioskList = new HashMap<>();
|
||||
|
||||
private class KioskEntry {
|
||||
public KioskEntry(KioskExtractor e, UrlIdHandler h) {
|
||||
extractor = e;
|
||||
handler = h;
|
||||
}
|
||||
KioskExtractor extractor;
|
||||
UrlIdHandler handler;
|
||||
}
|
||||
|
||||
public KioskList(int service_id) {
|
||||
this.service_id = service_id;
|
||||
}
|
||||
|
||||
public void addKioskEntry(String kioskType, KioskExtractor extractor, UrlIdHandler handler)
|
||||
throws Exception {
|
||||
if(kioskList.get(kioskType) != null) {
|
||||
throw new Exception("Kiosk with type " + kioskType + " already exists.");
|
||||
}
|
||||
kioskList.put(kioskType, new KioskEntry(extractor, handler));
|
||||
}
|
||||
|
||||
public KioskExtractor getExtractorByType(String kioskType) throws ExtractionException {
|
||||
KioskEntry ke = kioskList.get(kioskType);
|
||||
if(ke == null) {
|
||||
throw new ExtractionException("No kiosk found with the type: " + kioskType);
|
||||
} else {
|
||||
return ke.extractor;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getAvailableKisokTypes() {
|
||||
return kioskList.keySet();
|
||||
}
|
||||
|
||||
public KioskExtractor getExtryctorByUrl(String url) throws ExtractionException {
|
||||
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
|
||||
KioskEntry ke = e.getValue();
|
||||
if(ke.handler.acceptUrl(url)) {
|
||||
return getExtractorByType(e.getKey());
|
||||
}
|
||||
}
|
||||
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.SuggestionExtractor;
|
|||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
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.playlist.PlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
|
@ -57,4 +59,15 @@ public class SoundcloudService extends StreamingService {
|
|||
public SuggestionExtractor getSuggestionExtractor() {
|
||||
return new SoundcloudSuggestionExtractor(getServiceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public KioskList getKioskList() {
|
||||
KioskList list = new KioskList(getServiceId());
|
||||
|
||||
// add kiosks here e.g.:
|
||||
//list.addKioskEntry("trinding", new TrendingKiosk(), new TrendingUrlIdHandler());
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.schabi.newpipe.extractor.SuggestionExtractor;
|
|||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||
|
@ -78,4 +79,14 @@ public class YoutubeService extends StreamingService {
|
|||
public SuggestionExtractor getSuggestionExtractor() {
|
||||
return new YoutubeSuggestionExtractor(getServiceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public KioskList getKioskList() {
|
||||
KioskList list = new KioskList(getServiceId());
|
||||
|
||||
// add kiosks here e.g.:
|
||||
//list.addKioskEntry("trinding", new TrendingKiosk(), new TrendingUrlIdHandler());
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue