Skip to content

Commit 466d87c

Browse files
committed
remove type from kiosk and make getName() crawl the translated kiosk name
1 parent 7beb90b commit 466d87c

11 files changed

Lines changed: 79 additions & 74 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/kiosk/KioskExtractor.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929

3030
public abstract class KioskExtractor extends ListExtractor {
3131
private String contentCountry = null;
32-
private String type = null;
32+
private String id = null;
3333

3434
public KioskExtractor(StreamingService streamingService,
3535
String url,
3636
String nextStreamsUrl,
37-
String type)
37+
String kioskId)
3838
throws IOException, ExtractionException {
3939
super(streamingService, url, nextStreamsUrl);
40-
this.contentCountry = contentCountry;
41-
this.type = type;
40+
this.id = kioskId;
4241
}
4342

4443
/**
@@ -51,24 +50,23 @@ public void setContentCountry(String contentCountry) {
5150
this.contentCountry = contentCountry;
5251
}
5352

54-
/**
55-
* Returns the type of the kiosk.
56-
* eg. Trending, Top & Hot, Top last 24 hours
57-
* @return type of kiosk
58-
*/
59-
public String getType() throws ParsingException {
60-
return type;
61-
}
6253

6354
@Override
6455
public String getId() throws ParsingException {
65-
return getType();
56+
return id;
6657
}
6758

59+
/**
60+
* Id should be the name of the kiosk, tho Id is used for identifing it in the programm,
61+
* so id should be kept in english.
62+
* In order to get the name of the kiosk in the desired language we have to
63+
* crawl if from the website.
64+
* @return the tranlsated version of id
65+
* @throws ParsingException
66+
*/
6867
@Override
69-
public String getName() throws ParsingException {
70-
return getType();
71-
}
68+
public abstract String getName() throws ParsingException;
69+
7270

7371
public String getContentCountry() {
7472
return contentCountry;

src/main/java/org/schabi/newpipe/extractor/kiosk/KioskInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.io.IOException;
2828

2929
public class KioskInfo extends ListInfo {
30-
public String type;
3130

3231
public static ListExtractor.NextItemsResult getMoreItems(ServiceList serviceItem,
3332
String url,
@@ -67,9 +66,9 @@ public static KioskInfo getInfo(KioskExtractor extractor,
6766
KioskInfo info = new KioskInfo();
6867
extractor.setContentCountry(contentCountry);
6968
extractor.fetchPage();
70-
info.type = extractor.getType();
7169
info.name = extractor.getName();
7270
info.id = extractor.getId();
71+
info.url = extractor.getCleanUrl();
7372

7473
try {
7574
StreamInfoItemCollector c = extractor.getStreams();

src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface KioskExtractorFactory {
1818
KioskExtractor createNewKiosk(final StreamingService streamingService,
1919
final String url,
2020
final String nextStreamUrl,
21-
final String type)
21+
final String kioskId)
2222
throws ExtractionException, IOException;
2323
}
2424

@@ -39,12 +39,12 @@ public KioskList(int service_id) {
3939
this.service_id = service_id;
4040
}
4141

42-
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String type)
42+
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String id)
4343
throws Exception {
44-
if(kioskList.get(type) != null) {
45-
throw new Exception("Kiosk with type " + type + " already exists.");
44+
if(kioskList.get(id) != null) {
45+
throw new Exception("Kiosk with type " + id + " already exists.");
4646
}
47-
kioskList.put(type, new KioskEntry(extractorFactory, handler));
47+
kioskList.put(id, new KioskEntry(extractorFactory, handler));
4848
}
4949

5050
public void setDefaultKiosk(String kioskType) {
@@ -54,35 +54,35 @@ public void setDefaultKiosk(String kioskType) {
5454
public KioskExtractor getDefaultKioskExtractor(String nextStreamUrl)
5555
throws ExtractionException, IOException {
5656
if(defaultKiosk != null && !defaultKiosk.equals("")) {
57-
return getExtractorByType(defaultKiosk, nextStreamUrl);
57+
return getExtractorById(defaultKiosk, nextStreamUrl);
5858
} else {
5959
if(!kioskList.isEmpty()) {
6060
// if not set get any entry
6161
Object[] keySet = kioskList.keySet().toArray();
62-
return getExtractorByType(keySet[0].toString(), nextStreamUrl);
62+
return getExtractorById(keySet[0].toString(), nextStreamUrl);
6363
} else {
6464
return null;
6565
}
6666
}
6767
}
6868

69-
public String getDefaultKioskType() {
69+
public String getDefaultKioskId() {
7070
return defaultKiosk;
7171
}
7272

73-
public KioskExtractor getExtractorByType(String kioskType, String nextStreamsUrl)
73+
public KioskExtractor getExtractorById(String kioskId, String nextStreamsUrl)
7474
throws ExtractionException, IOException {
75-
KioskEntry ke = kioskList.get(kioskType);
75+
KioskEntry ke = kioskList.get(kioskId);
7676
if(ke == null) {
77-
throw new ExtractionException("No kiosk found with the type: " + kioskType);
77+
throw new ExtractionException("No kiosk found with the type: " + kioskId);
7878
} else {
7979
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
80-
ke.handler.getUrl(kioskType),
81-
nextStreamsUrl, kioskType);
80+
ke.handler.getUrl(kioskId),
81+
nextStreamsUrl, kioskId);
8282
}
8383
}
8484

85-
public Set<String> getAvailableKisokTypes() {
85+
public Set<String> getAvailableKisoks() {
8686
return kioskList.keySet();
8787
}
8888

@@ -91,7 +91,7 @@ public KioskExtractor getExtractorByUrl(String url, String nextStreamsUrl)
9191
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
9292
KioskEntry ke = e.getValue();
9393
if(ke.handler.acceptUrl(url)) {
94-
return getExtractorByType(e.getKey(), nextStreamsUrl);
94+
return getExtractorById(e.getKey(), nextStreamsUrl);
9595
}
9696
}
9797
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
public class SoundcloudChartsExtractor extends KioskExtractor {
1515
private String url;
1616

17-
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
17+
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl, String kioskId)
1818
throws IOException, ExtractionException {
19-
super(service, url, nextStreamsUrl, type);
19+
super(service, url, nextStreamsUrl, kioskId);
2020
this.url = url;
2121
}
2222

@@ -25,8 +25,8 @@ public void fetchPage() {
2525
}
2626

2727
@Override
28-
public String getType() throws ParsingException {
29-
return getUrlIdHandler().getId(url);
28+
public String getName() throws ParsingException {
29+
return "< Implement me (♥_♥) >";
3030
}
3131

3232
@Override
@@ -54,7 +54,7 @@ public StreamInfoItemCollector getStreams() throws IOException, ExtractionExcept
5454
"?genre=soundcloud:genres:all-music" +
5555
"&client_id=" + SoundcloudParsingHelper.clientId();
5656

57-
if (getType().equals("Top 50")) {
57+
if (getId().equals("Top 50")) {
5858
apiUrl += "&kind=top";
5959
} else {
6060
apiUrl += "&kind=new";

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

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,27 @@ public SuggestionExtractor getSuggestionExtractor() {
6262

6363
@Override
6464
public KioskList getKioskList() throws ExtractionException {
65+
KioskList.KioskExtractorFactory chartsFactory = new KioskList.KioskExtractorFactory() {
66+
@Override
67+
public KioskExtractor createNewKiosk(StreamingService streamingService,
68+
String url,
69+
String nextStreamUrl,
70+
String id)
71+
throws ExtractionException, IOException {
72+
return new SoundcloudChartsExtractor(SoundcloudService.this,
73+
url,
74+
nextStreamUrl,
75+
id);
76+
}
77+
};
78+
6579
KioskList list = new KioskList(getServiceId());
6680

6781
// add kiosks here e.g.:
6882
final SoundcloudChartsUrlIdHandler h = new SoundcloudChartsUrlIdHandler();
6983
try {
70-
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
71-
@Override
72-
public KioskExtractor createNewKiosk(StreamingService streamingService,
73-
String url,
74-
String nextStreamUrl,
75-
String type)
76-
throws ExtractionException, IOException {
77-
return new SoundcloudChartsExtractor(SoundcloudService.this,
78-
h.getUrl(type),
79-
nextStreamUrl,
80-
type);
81-
}
82-
}, h, "Top 50");
83-
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
84-
@Override
85-
public KioskExtractor createNewKiosk(StreamingService streamingService,
86-
String url,
87-
String nextStreamUrl,
88-
String type)
89-
throws ExtractionException, IOException {
90-
return new SoundcloudChartsExtractor(SoundcloudService.this,
91-
h.getUrl(type),
92-
nextStreamUrl,
93-
type);
94-
}
95-
}, h, "New & hot");
84+
list.addKioskEntry(chartsFactory, h, "Top 50");
85+
list.addKioskEntry(chartsFactory, h, "New & hot");
9686
} catch (Exception e) {
9787
throw new ExtractionException(e);
9888
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public KioskList getKioskList()
9090
try {
9191
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
9292
@Override
93-
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl, String type)
93+
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl, String id)
9494
throws ExtractionException, IOException {
95-
return new YoutubeTrendingExtractor(YoutubeService.this, url, nextStreamUrl, type);
95+
return new YoutubeTrendingExtractor(YoutubeService.this, url, nextStreamUrl, id);
9696
}
9797
}, new YoutubeTrendingUrlIdHandler(), "Trending");
9898
list.setDefaultKiosk("Trending");

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
3535

3636
private Document doc;
3737

38-
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
38+
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl, String kioskId)
3939
throws IOException, ExtractionException {
40-
super(service, url, nextStreamsUrl, type);
40+
super(service, url, nextStreamsUrl, kioskId);
4141
}
4242

4343
@Override
@@ -64,6 +64,18 @@ public ListExtractor.NextItemsResult getNextStreams() {
6464
return null;
6565
}
6666

67+
@Override
68+
public String getName() throws ParsingException {
69+
try {
70+
Element a = doc.select("a[href*=\"/feed/trending\"]").first();
71+
Element span = a.select("span[class*=\"display-name\"]").first();
72+
Element nameSpan = span.select("span").first();
73+
return nameSpan.text();
74+
} catch (Exception e) {
75+
throw new ParsingException("Could not get Trending name", e);
76+
}
77+
}
78+
6779
@Override
6880
public StreamInfoItemCollector getStreams() throws ParsingException {
6981
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());

src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void setUp() throws Exception {
2525
NewPipe.init(Downloader.getInstance());
2626
extractor = SoundCloud.getService()
2727
.getKioskList()
28-
.getExtractorByType("Top 50", null);
28+
.getExtractorById("Top 50", null);
2929
extractor.fetchPage();
3030
}
3131

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void setUp() throws Exception {
4848

4949
@Test
5050
public void testGetKioskAvailableKiosks() throws Exception {
51-
assertFalse("No kiosk got returned", kioskList.getAvailableKisokTypes().isEmpty());
51+
assertFalse("No kiosk got returned", kioskList.getAvailableKisoks().isEmpty());
5252
}
5353

5454
@Test

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTreindingKioskInfoTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public void getStreams() {
5454
}
5555

5656
@Test
57-
public void getType() {
58-
assertEquals(kioskInfo.type, "Trending");
57+
public void getId() {
58+
assertEquals(kioskInfo.id, "Trending");
59+
}
60+
61+
@Test
62+
public void getName() {
63+
assertFalse(kioskInfo.name.isEmpty());
5964
}
6065
}

0 commit comments

Comments
 (0)