diff --git a/src/main/java/org/schabi/newpipe/extractor/InfoItem.java b/src/main/java/org/schabi/newpipe/extractor/InfoItem.java index 44f97153f..ab6e37cb6 100644 --- a/src/main/java/org/schabi/newpipe/extractor/InfoItem.java +++ b/src/main/java/org/schabi/newpipe/extractor/InfoItem.java @@ -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 * InfoItem.java is part of NewPipe. diff --git a/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index ae2241f30..d4e3468bb 100644 --- a/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -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); diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java new file mode 100644 index 000000000..6dad3acc7 --- /dev/null +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java @@ -0,0 +1,52 @@ +package org.schabi.newpipe.extractor.kiosk; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * 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 . + */ + +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(); + } +} diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java new file mode 100644 index 000000000..b196fecde --- /dev/null +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java @@ -0,0 +1,64 @@ +package org.schabi.newpipe.extractor.kiosk; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * 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 . + */ + +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; + } +} diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java new file mode 100644 index 000000000..26cb4a93d --- /dev/null +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java @@ -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 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 getAvailableKisokTypes() { + return kioskList.keySet(); + } + + public KioskExtractor getExtryctorByUrl(String url) throws ExtractionException { + for(Map.Entry 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); + } +} diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java index 80c565ac8..90e794f19 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java @@ -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; + } } diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index eb8926024..b071ba5eb 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -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; + } }