messing kiosk up in order to make it work
This commit is contained in:
parent
b37b24511f
commit
7fffef5d4f
|
@ -29,13 +29,16 @@ import java.io.IOException;
|
|||
|
||||
public abstract class KioskExtractor extends ListExtractor {
|
||||
private String contentCountry = null;
|
||||
private String type = null;
|
||||
|
||||
public KioskExtractor(StreamingService streamingService,
|
||||
String url,
|
||||
String nextStreamsUrl)
|
||||
String nextStreamsUrl,
|
||||
String type)
|
||||
throws IOException, ExtractionException {
|
||||
super(streamingService, url, nextStreamsUrl);
|
||||
this.contentCountry = contentCountry;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +56,9 @@ public abstract class KioskExtractor extends ListExtractor {
|
|||
* eg. Trending, Top & Hot, Top last 24 hours
|
||||
* @return type of kiosk
|
||||
*/
|
||||
public abstract String getType() throws ParsingException;
|
||||
public String getType() throws ParsingException {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() throws ParsingException {
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.schabi.newpipe.extractor.kiosk;
|
|||
|
||||
import org.schabi.newpipe.extractor.*;
|
||||
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;
|
||||
|
@ -40,7 +39,7 @@ public class KioskInfo extends ListInfo {
|
|||
String url,
|
||||
String nextStreamsUrl) throws IOException, ExtractionException {
|
||||
KioskList kl = service.getKioskList();
|
||||
KioskExtractor extractor = kl.getExtryctorByUrl(url, nextStreamsUrl);
|
||||
KioskExtractor extractor = kl.getExtractorByUrl(url, nextStreamsUrl);
|
||||
return extractor.getNextStreams();
|
||||
}
|
||||
|
||||
|
@ -59,7 +58,7 @@ public class KioskInfo extends ListInfo {
|
|||
String url,
|
||||
String contentCountry) throws IOException, ExtractionException {
|
||||
KioskList kl = service.getKioskList();
|
||||
KioskExtractor extractor = kl.getExtryctorByUrl(url, null);
|
||||
KioskExtractor extractor = kl.getExtractorByUrl(url, null);
|
||||
return getInfo(extractor, contentCountry);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ public class KioskList {
|
|||
public interface KioskExtractorFactory {
|
||||
KioskExtractor createNewKiosk(final StreamingService streamingService,
|
||||
final String url,
|
||||
final String nextStreamUrl)
|
||||
final String nextStreamUrl,
|
||||
final String type)
|
||||
throws ExtractionException, IOException;
|
||||
}
|
||||
|
||||
|
@ -38,14 +39,12 @@ public class KioskList {
|
|||
this.service_id = service_id;
|
||||
}
|
||||
|
||||
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler)
|
||||
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String type)
|
||||
throws Exception {
|
||||
KioskExtractor extractor =
|
||||
extractorFactory.createNewKiosk(NewPipe.getService(service_id), "", "");
|
||||
if(kioskList.get(extractor.getType()) != null) {
|
||||
throw new Exception("Kiosk with type " + extractor.getType() + " already exists.");
|
||||
if(kioskList.get(type) != null) {
|
||||
throw new Exception("Kiosk with type " + type + " already exists.");
|
||||
}
|
||||
kioskList.put(extractor.getType(), new KioskEntry(extractorFactory, handler));
|
||||
kioskList.put(type, new KioskEntry(extractorFactory, handler));
|
||||
}
|
||||
|
||||
public void setDefaultKiosk(String kioskType) {
|
||||
|
@ -78,8 +77,8 @@ public class KioskList {
|
|||
throw new ExtractionException("No kiosk found with the type: " + kioskType);
|
||||
} else {
|
||||
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
|
||||
ke.handler.getUrl(""),
|
||||
nextStreamsUrl);
|
||||
ke.handler.getUrl(kioskType),
|
||||
nextStreamsUrl, kioskType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +86,7 @@ public class KioskList {
|
|||
return kioskList.keySet();
|
||||
}
|
||||
|
||||
public KioskExtractor getExtryctorByUrl(String url, String nextStreamsUrl)
|
||||
public KioskExtractor getExtractorByUrl(String url, String nextStreamsUrl)
|
||||
throws ExtractionException, IOException {
|
||||
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
|
||||
KioskEntry ke = e.getValue();
|
||||
|
@ -97,4 +96,8 @@ public class KioskList {
|
|||
}
|
||||
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
|
||||
}
|
||||
|
||||
public UrlIdHandler getUrlIdHandlerByType(String type) {
|
||||
return kioskList.get(type).handler;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
|||
public class SoundcloudChartsExtractor extends KioskExtractor {
|
||||
private String url;
|
||||
|
||||
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
|
||||
super(service, url, nextStreamsUrl);
|
||||
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
|
||||
throws IOException, ExtractionException {
|
||||
super(service, url, nextStreamsUrl, type);
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,16 +69,30 @@ public class SoundcloudService extends StreamingService {
|
|||
try {
|
||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl) throws ExtractionException, IOException {
|
||||
return new SoundcloudChartsExtractor(SoundcloudService.this, h.getUrl("Top 50"), nextStreamUrl);
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService,
|
||||
String url,
|
||||
String nextStreamUrl,
|
||||
String type)
|
||||
throws ExtractionException, IOException {
|
||||
return new SoundcloudChartsExtractor(SoundcloudService.this,
|
||||
h.getUrl(type),
|
||||
nextStreamUrl,
|
||||
type);
|
||||
}
|
||||
}, h);
|
||||
}, h, "Top 50");
|
||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl) throws ExtractionException, IOException {
|
||||
return new SoundcloudChartsExtractor(SoundcloudService.this, h.getUrl("New & hot"), nextStreamUrl);
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService,
|
||||
String url,
|
||||
String nextStreamUrl,
|
||||
String type)
|
||||
throws ExtractionException, IOException {
|
||||
return new SoundcloudChartsExtractor(SoundcloudService.this,
|
||||
h.getUrl(type),
|
||||
nextStreamUrl,
|
||||
type);
|
||||
}
|
||||
}, h);
|
||||
}, h, "New & hot");
|
||||
} catch (Exception e) {
|
||||
throw new ExtractionException(e);
|
||||
}
|
||||
|
|
|
@ -90,11 +90,11 @@ public class YoutubeService extends StreamingService {
|
|||
try {
|
||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl)
|
||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl, String type)
|
||||
throws ExtractionException, IOException {
|
||||
return new YoutubeTrendingExtractor(YoutubeService.this, url, nextStreamUrl);
|
||||
return new YoutubeTrendingExtractor(YoutubeService.this, url, nextStreamUrl, type);
|
||||
}
|
||||
}, new YoutubeTrendingUrlIdHandler());
|
||||
}, new YoutubeTrendingUrlIdHandler(), "Trending");
|
||||
list.setDefaultKiosk("Trending");
|
||||
} catch (Exception e) {
|
||||
throw new ExtractionException(e);
|
||||
|
|
|
@ -35,9 +35,9 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
|
|||
|
||||
private Document doc;
|
||||
|
||||
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl)
|
||||
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
|
||||
throws IOException, ExtractionException {
|
||||
super(service, url, nextStreamsUrl);
|
||||
super(service, url, nextStreamsUrl, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,11 +54,6 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
|
|||
doc = Jsoup.parse(pageContent, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "Trending";
|
||||
}
|
||||
|
||||
@Override
|
||||
public UrlIdHandler getUrlIdHandler() {
|
||||
return new YoutubeTrendingUrlIdHandler();
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube;
|
||||
|
||||
/*
|
||||
* Created by Christian Schabesberger on 12.08.17.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
||||
* YoutubeTreindingKioskInfoTest.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.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskInfo;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
/**
|
||||
* Test for {@link KioskInfo}
|
||||
*/
|
||||
public class YoutubeTreindingKioskInfoTest {
|
||||
KioskInfo kioskInfo;
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
StreamingService service = YouTube.getService();
|
||||
UrlIdHandler urlIdHandler = service.getKioskList().getUrlIdHandlerByType("Trending");
|
||||
|
||||
kioskInfo = KioskInfo.getInfo(YouTube.getService(), urlIdHandler.getUrl("Trending"), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStreams() {
|
||||
assertFalse(kioskInfo.related_streams.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getType() {
|
||||
assertEquals(kioskInfo.type, "Trending");
|
||||
}
|
||||
}
|
|
@ -47,7 +47,6 @@ public class YoutubeTrendingExtractorTest {
|
|||
extractor = YouTube.getService()
|
||||
.getKioskList()
|
||||
.getExtractorByType("Trending", null);
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,6 +24,9 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.UrlIdHandler;
|
||||
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -33,21 +36,23 @@ import static org.junit.Assert.assertTrue;
|
|||
* Test for {@link YoutubeTrendingUrlIdHandler}
|
||||
*/
|
||||
public class YoutubeTrendingUrlIdHandlerTest {
|
||||
private YoutubeTrendingUrlIdHandler urlIdHandler;
|
||||
private UrlIdHandler urlIdHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
urlIdHandler = new YoutubeTrendingUrlIdHandler();
|
||||
urlIdHandler = YouTube.getService().getKioskList().getUrlIdHandlerByType("Trending");
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() {
|
||||
public void getUrl()
|
||||
throws Exception {
|
||||
assertEquals(urlIdHandler.getUrl(""), "https://www.youtube.com/feed/trending");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getId() {
|
||||
public void getId()
|
||||
throws Exception {
|
||||
assertEquals(urlIdHandler.getId(""), "Trending");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue