Skip to content

Commit 7fffef5

Browse files
committed
messing kiosk up in order to make it work
1 parent b37b245 commit 7fffef5

10 files changed

Lines changed: 119 additions & 38 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929

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

3334
public KioskExtractor(StreamingService streamingService,
3435
String url,
35-
String nextStreamsUrl)
36+
String nextStreamsUrl,
37+
String type)
3638
throws IOException, ExtractionException {
3739
super(streamingService, url, nextStreamsUrl);
3840
this.contentCountry = contentCountry;
41+
this.type = type;
3942
}
4043

4144
/**
@@ -53,7 +56,9 @@ public void setContentCountry(String contentCountry) {
5356
* eg. Trending, Top & Hot, Top last 24 hours
5457
* @return type of kiosk
5558
*/
56-
public abstract String getType() throws ParsingException;
59+
public String getType() throws ParsingException {
60+
return type;
61+
}
5762

5863
@Override
5964
public String getId() throws ParsingException {

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

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

2323
import org.schabi.newpipe.extractor.*;
2424
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
25-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2625
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
2726

2827
import java.io.IOException;
@@ -40,7 +39,7 @@ public static ListExtractor.NextItemsResult getMoreItems(StreamingService servic
4039
String url,
4140
String nextStreamsUrl) throws IOException, ExtractionException {
4241
KioskList kl = service.getKioskList();
43-
KioskExtractor extractor = kl.getExtryctorByUrl(url, nextStreamsUrl);
42+
KioskExtractor extractor = kl.getExtractorByUrl(url, nextStreamsUrl);
4443
return extractor.getNextStreams();
4544
}
4645

@@ -59,7 +58,7 @@ public static KioskInfo getInfo(StreamingService service,
5958
String url,
6059
String contentCountry) throws IOException, ExtractionException {
6160
KioskList kl = service.getKioskList();
62-
KioskExtractor extractor = kl.getExtryctorByUrl(url, null);
61+
KioskExtractor extractor = kl.getExtractorByUrl(url, null);
6362
return getInfo(extractor, contentCountry);
6463
}
6564

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public class KioskList {
1717
public interface KioskExtractorFactory {
1818
KioskExtractor createNewKiosk(final StreamingService streamingService,
1919
final String url,
20-
final String nextStreamUrl)
20+
final String nextStreamUrl,
21+
final String type)
2122
throws ExtractionException, IOException;
2223
}
2324

@@ -38,14 +39,12 @@ public KioskList(int service_id) {
3839
this.service_id = service_id;
3940
}
4041

41-
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler)
42+
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String type)
4243
throws Exception {
43-
KioskExtractor extractor =
44-
extractorFactory.createNewKiosk(NewPipe.getService(service_id), "", "");
45-
if(kioskList.get(extractor.getType()) != null) {
46-
throw new Exception("Kiosk with type " + extractor.getType() + " already exists.");
44+
if(kioskList.get(type) != null) {
45+
throw new Exception("Kiosk with type " + type + " already exists.");
4746
}
48-
kioskList.put(extractor.getType(), new KioskEntry(extractorFactory, handler));
47+
kioskList.put(type, new KioskEntry(extractorFactory, handler));
4948
}
5049

5150
public void setDefaultKiosk(String kioskType) {
@@ -78,16 +77,16 @@ public KioskExtractor getExtractorByType(String kioskType, String nextStreamsUrl
7877
throw new ExtractionException("No kiosk found with the type: " + kioskType);
7978
} else {
8079
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
81-
ke.handler.getUrl(""),
82-
nextStreamsUrl);
80+
ke.handler.getUrl(kioskType),
81+
nextStreamsUrl, kioskType);
8382
}
8483
}
8584

8685
public Set<String> getAvailableKisokTypes() {
8786
return kioskList.keySet();
8887
}
8988

90-
public KioskExtractor getExtryctorByUrl(String url, String nextStreamsUrl)
89+
public KioskExtractor getExtractorByUrl(String url, String nextStreamsUrl)
9190
throws ExtractionException, IOException {
9291
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
9392
KioskEntry ke = e.getValue();
@@ -97,4 +96,8 @@ public KioskExtractor getExtryctorByUrl(String url, String nextStreamsUrl)
9796
}
9897
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
9998
}
99+
100+
public UrlIdHandler getUrlIdHandlerByType(String type) {
101+
return kioskList.get(type).handler;
102+
}
100103
}

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

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

17-
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
18-
super(service, url, nextStreamsUrl);
17+
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
18+
throws IOException, ExtractionException {
19+
super(service, url, nextStreamsUrl, type);
1920
this.url = url;
2021
}
2122

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,30 @@ public KioskList getKioskList() throws ExtractionException {
6969
try {
7070
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
7171
@Override
72-
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl) throws ExtractionException, IOException {
73-
return new SoundcloudChartsExtractor(SoundcloudService.this, h.getUrl("Top 50"), nextStreamUrl);
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);
7481
}
75-
}, h);
82+
}, h, "Top 50");
7683
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
7784
@Override
78-
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl) throws ExtractionException, IOException {
79-
return new SoundcloudChartsExtractor(SoundcloudService.this, h.getUrl("New & hot"), nextStreamUrl);
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);
8094
}
81-
}, h);
95+
}, h, "New & hot");
8296
} catch (Exception e) {
8397
throw new ExtractionException(e);
8498
}

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

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

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

Lines changed: 2 additions & 7 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)
38+
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
3939
throws IOException, ExtractionException {
40-
super(service, url, nextStreamsUrl);
40+
super(service, url, nextStreamsUrl, type);
4141
}
4242

4343
@Override
@@ -54,11 +54,6 @@ public void fetchPage() throws IOException, ExtractionException {
5454
doc = Jsoup.parse(pageContent, url);
5555
}
5656

57-
@Override
58-
public String getType() {
59-
return "Trending";
60-
}
61-
6257
@Override
6358
public UrlIdHandler getUrlIdHandler() {
6459
return new YoutubeTrendingUrlIdHandler();
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
/*
4+
* Created by Christian Schabesberger on 12.08.17.
5+
*
6+
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
7+
* YoutubeTreindingKioskInfoTest.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.junit.Before;
24+
import org.junit.Test;
25+
import org.schabi.newpipe.Downloader;
26+
import org.schabi.newpipe.extractor.NewPipe;
27+
import org.schabi.newpipe.extractor.StreamingService;
28+
import org.schabi.newpipe.extractor.UrlIdHandler;
29+
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
30+
31+
import static junit.framework.TestCase.assertEquals;
32+
import static org.junit.Assert.assertFalse;
33+
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
34+
35+
/**
36+
* Test for {@link KioskInfo}
37+
*/
38+
public class YoutubeTreindingKioskInfoTest {
39+
KioskInfo kioskInfo;
40+
41+
@Before
42+
public void setUp()
43+
throws Exception {
44+
NewPipe.init(Downloader.getInstance());
45+
StreamingService service = YouTube.getService();
46+
UrlIdHandler urlIdHandler = service.getKioskList().getUrlIdHandlerByType("Trending");
47+
48+
kioskInfo = KioskInfo.getInfo(YouTube.getService(), urlIdHandler.getUrl("Trending"), null);
49+
}
50+
51+
@Test
52+
public void getStreams() {
53+
assertFalse(kioskInfo.related_streams.isEmpty());
54+
}
55+
56+
@Test
57+
public void getType() {
58+
assertEquals(kioskInfo.type, "Trending");
59+
}
60+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public void setUp() throws Exception {
4747
extractor = YouTube.getService()
4848
.getKioskList()
4949
.getExtractorByType("Trending", null);
50-
extractor.fetchPage();
5150
}
5251

5352
@Test

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import org.junit.Test;
2525
import org.schabi.newpipe.Downloader;
2626
import org.schabi.newpipe.extractor.NewPipe;
27+
import org.schabi.newpipe.extractor.UrlIdHandler;
28+
29+
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2730

2831
import static junit.framework.TestCase.assertFalse;
2932
import static org.junit.Assert.assertEquals;
@@ -33,21 +36,23 @@
3336
* Test for {@link YoutubeTrendingUrlIdHandler}
3437
*/
3538
public class YoutubeTrendingUrlIdHandlerTest {
36-
private YoutubeTrendingUrlIdHandler urlIdHandler;
39+
private UrlIdHandler urlIdHandler;
3740

3841
@Before
3942
public void setUp() throws Exception {
40-
urlIdHandler = new YoutubeTrendingUrlIdHandler();
43+
urlIdHandler = YouTube.getService().getKioskList().getUrlIdHandlerByType("Trending");
4144
NewPipe.init(Downloader.getInstance());
4245
}
4346

4447
@Test
45-
public void getUrl() {
48+
public void getUrl()
49+
throws Exception {
4650
assertEquals(urlIdHandler.getUrl(""), "https://www.youtube.com/feed/trending");
4751
}
4852

4953
@Test
50-
public void getId() {
54+
public void getId()
55+
throws Exception {
5156
assertEquals(urlIdHandler.getId(""), "Trending");
5257
}
5358

0 commit comments

Comments
 (0)