Skip to content

Commit 316b479

Browse files
committed
add basic setup for kiosk
1 parent 82824cd commit 316b479

7 files changed

Lines changed: 200 additions & 1 deletion

File tree

src/main/java/org/schabi/newpipe/extractor/InfoItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.schabi.newpipe.extractor;
22

33
/*
4-
* Created by the-scrabi on 11.02.17.
4+
* Created by Christian Schabesberger on 11.02.17.
55
*
66
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
77
* InfoItem.java is part of NewPipe.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
44
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
5+
import org.schabi.newpipe.extractor.kiosk.KioskList;
56
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
67
import org.schabi.newpipe.extractor.search.SearchEngine;
78
import org.schabi.newpipe.extractor.stream.StreamExtractor;
@@ -48,6 +49,7 @@ public ServiceInfo getServiceInfo() {
4849
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
4950
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
5051
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
52+
public abstract KioskList getKioskList();
5153

5254
public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
5355
return getChannelExtractor(url, null);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.schabi.newpipe.extractor.kiosk;
2+
3+
/*
4+
* Created by Christian Schabesberger on 12.08.17.
5+
*
6+
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
7+
* KioskExtractor.java is part of NewPipe.
8+
*
9+
* NewPipe is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* NewPipe is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
import org.schabi.newpipe.extractor.ListExtractor;
24+
import org.schabi.newpipe.extractor.StreamingService;
25+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
26+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
27+
28+
import java.io.IOException;
29+
30+
public abstract class KioskExtractor extends ListExtractor {
31+
public KioskExtractor(StreamingService streamingService, String url, String nextStreamsUrl)
32+
throws IOException, ExtractionException {
33+
super(streamingService, url, nextStreamsUrl);
34+
}
35+
36+
/**
37+
* Returns the type of the kiosk.
38+
* eg. Trending, Top & Hot, Top last 24 hours
39+
* @return type of kiosk
40+
*/
41+
public abstract String getType() throws ParsingException;
42+
43+
@Override
44+
public String getId() throws ParsingException {
45+
return getType();
46+
}
47+
48+
@Override
49+
public String getName() throws ParsingException {
50+
return getType();
51+
}
52+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.schabi.newpipe.extractor.kiosk;
2+
3+
/*
4+
* Created by Christian Schabesberger on 12.08.17.
5+
*
6+
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
7+
* KioskInfo.java is part of NewPipe.
8+
*
9+
* NewPipe is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* NewPipe is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
import org.schabi.newpipe.extractor.ListInfo;
24+
import org.schabi.newpipe.extractor.NewPipe;
25+
import org.schabi.newpipe.extractor.ServiceList;
26+
import org.schabi.newpipe.extractor.StreamingService;
27+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
28+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
29+
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
30+
31+
import java.io.IOException;
32+
33+
public class KioskInfo extends ListInfo {
34+
public String type;
35+
36+
public static KioskInfo getInfo(String url) throws IOException, ExtractionException {
37+
return getInfo(NewPipe.getServiceByUrl(url), url);
38+
}
39+
40+
public static KioskInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException {
41+
return getInfo(serviceItem.getService(), url);
42+
}
43+
44+
public static KioskInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
45+
KioskList kl = service.getKioskList();
46+
KioskExtractor extractor = kl.getExtryctorByUrl(url);
47+
return getInfo(extractor);
48+
}
49+
50+
public static KioskInfo getInfo(KioskExtractor extractor) throws ParsingException {
51+
KioskInfo info = new KioskInfo();
52+
info.type = extractor.getType();
53+
54+
try {
55+
StreamInfoItemCollector c = extractor.getStreams();
56+
info.related_streams = c.getItemList();
57+
info.errors.addAll(c.getErrors());
58+
} catch (Exception e) {
59+
info.errors.add(e);
60+
}
61+
62+
return info;
63+
}
64+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.schabi.newpipe.extractor.kiosk;
2+
3+
import org.schabi.newpipe.extractor.UrlIdHandler;
4+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
import java.util.Set;
9+
10+
public class KioskList {
11+
private int service_id;
12+
private HashMap<String, KioskEntry> kioskList = new HashMap<>();
13+
14+
private class KioskEntry {
15+
public KioskEntry(KioskExtractor e, UrlIdHandler h) {
16+
extractor = e;
17+
handler = h;
18+
}
19+
KioskExtractor extractor;
20+
UrlIdHandler handler;
21+
}
22+
23+
public KioskList(int service_id) {
24+
this.service_id = service_id;
25+
}
26+
27+
public void addKioskEntry(String kioskType, KioskExtractor extractor, UrlIdHandler handler)
28+
throws Exception {
29+
if(kioskList.get(kioskType) != null) {
30+
throw new Exception("Kiosk with type " + kioskType + " already exists.");
31+
}
32+
kioskList.put(kioskType, new KioskEntry(extractor, handler));
33+
}
34+
35+
public KioskExtractor getExtractorByType(String kioskType) throws ExtractionException {
36+
KioskEntry ke = kioskList.get(kioskType);
37+
if(ke == null) {
38+
throw new ExtractionException("No kiosk found with the type: " + kioskType);
39+
} else {
40+
return ke.extractor;
41+
}
42+
}
43+
44+
public Set<String> getAvailableKisokTypes() {
45+
return kioskList.keySet();
46+
}
47+
48+
public KioskExtractor getExtryctorByUrl(String url) throws ExtractionException {
49+
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
50+
KioskEntry ke = e.getValue();
51+
if(ke.handler.acceptUrl(url)) {
52+
return getExtractorByType(e.getKey());
53+
}
54+
}
55+
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
56+
}
57+
}

src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.schabi.newpipe.extractor.UrlIdHandler;
66
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
77
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
8+
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
9+
import org.schabi.newpipe.extractor.kiosk.KioskList;
810
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
911
import org.schabi.newpipe.extractor.search.SearchEngine;
1012
import org.schabi.newpipe.extractor.stream.StreamExtractor;
@@ -57,4 +59,15 @@ public PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl)
5759
public SuggestionExtractor getSuggestionExtractor() {
5860
return new SoundcloudSuggestionExtractor(getServiceId());
5961
}
62+
63+
@Override
64+
public KioskList getKioskList() {
65+
KioskList list = new KioskList(getServiceId());
66+
67+
// add kiosks here e.g.:
68+
//list.addKioskEntry("trinding", new TrendingKiosk(), new TrendingUrlIdHandler());
69+
70+
71+
return list;
72+
}
6073
}

src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.schabi.newpipe.extractor.UrlIdHandler;
66
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
77
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
8+
import org.schabi.newpipe.extractor.kiosk.KioskList;
89
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
910
import org.schabi.newpipe.extractor.search.SearchEngine;
1011
import org.schabi.newpipe.extractor.stream.StreamExtractor;
@@ -78,4 +79,14 @@ public PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl)
7879
public SuggestionExtractor getSuggestionExtractor() {
7980
return new YoutubeSuggestionExtractor(getServiceId());
8081
}
82+
83+
@Override
84+
public KioskList getKioskList() {
85+
KioskList list = new KioskList(getServiceId());
86+
87+
// add kiosks here e.g.:
88+
//list.addKioskEntry("trinding", new TrendingKiosk(), new TrendingUrlIdHandler());
89+
90+
return list;
91+
}
8192
}

0 commit comments

Comments
 (0)