mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-28 16:00:33 +05:30
remove type from kiosk and make getName() crawl the translated kiosk name
This commit is contained in:
parent
7beb90bf8a
commit
466d87ceb4
@ -29,16 +29,15 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public abstract class KioskExtractor extends ListExtractor {
|
public abstract class KioskExtractor extends ListExtractor {
|
||||||
private String contentCountry = null;
|
private String contentCountry = null;
|
||||||
private String type = null;
|
private String id = null;
|
||||||
|
|
||||||
public KioskExtractor(StreamingService streamingService,
|
public KioskExtractor(StreamingService streamingService,
|
||||||
String url,
|
String url,
|
||||||
String nextStreamsUrl,
|
String nextStreamsUrl,
|
||||||
String type)
|
String kioskId)
|
||||||
throws IOException, ExtractionException {
|
throws IOException, ExtractionException {
|
||||||
super(streamingService, url, nextStreamsUrl);
|
super(streamingService, url, nextStreamsUrl);
|
||||||
this.contentCountry = contentCountry;
|
this.id = kioskId;
|
||||||
this.type = type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,24 +50,23 @@ public abstract class KioskExtractor extends ListExtractor {
|
|||||||
this.contentCountry = contentCountry;
|
this.contentCountry = contentCountry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the type of the kiosk.
|
|
||||||
* eg. Trending, Top & Hot, Top last 24 hours
|
|
||||||
* @return type of kiosk
|
|
||||||
*/
|
|
||||||
public String getType() throws ParsingException {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() throws ParsingException {
|
public String getId() throws ParsingException {
|
||||||
return getType();
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id should be the name of the kiosk, tho Id is used for identifing it in the programm,
|
||||||
|
* so id should be kept in english.
|
||||||
|
* In order to get the name of the kiosk in the desired language we have to
|
||||||
|
* crawl if from the website.
|
||||||
|
* @return the tranlsated version of id
|
||||||
|
* @throws ParsingException
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public abstract String getName() throws ParsingException;
|
||||||
return getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getContentCountry() {
|
public String getContentCountry() {
|
||||||
return contentCountry;
|
return contentCountry;
|
||||||
|
@ -27,7 +27,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class KioskInfo extends ListInfo {
|
public class KioskInfo extends ListInfo {
|
||||||
public String type;
|
|
||||||
|
|
||||||
public static ListExtractor.NextItemsResult getMoreItems(ServiceList serviceItem,
|
public static ListExtractor.NextItemsResult getMoreItems(ServiceList serviceItem,
|
||||||
String url,
|
String url,
|
||||||
@ -67,9 +66,9 @@ public class KioskInfo extends ListInfo {
|
|||||||
KioskInfo info = new KioskInfo();
|
KioskInfo info = new KioskInfo();
|
||||||
extractor.setContentCountry(contentCountry);
|
extractor.setContentCountry(contentCountry);
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
info.type = extractor.getType();
|
|
||||||
info.name = extractor.getName();
|
info.name = extractor.getName();
|
||||||
info.id = extractor.getId();
|
info.id = extractor.getId();
|
||||||
|
info.url = extractor.getCleanUrl();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StreamInfoItemCollector c = extractor.getStreams();
|
StreamInfoItemCollector c = extractor.getStreams();
|
||||||
|
@ -18,7 +18,7 @@ public class KioskList {
|
|||||||
KioskExtractor createNewKiosk(final StreamingService streamingService,
|
KioskExtractor createNewKiosk(final StreamingService streamingService,
|
||||||
final String url,
|
final String url,
|
||||||
final String nextStreamUrl,
|
final String nextStreamUrl,
|
||||||
final String type)
|
final String kioskId)
|
||||||
throws ExtractionException, IOException;
|
throws ExtractionException, IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,12 +39,12 @@ public class KioskList {
|
|||||||
this.service_id = service_id;
|
this.service_id = service_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String type)
|
public void addKioskEntry(KioskExtractorFactory extractorFactory, UrlIdHandler handler, String id)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
if(kioskList.get(type) != null) {
|
if(kioskList.get(id) != null) {
|
||||||
throw new Exception("Kiosk with type " + type + " already exists.");
|
throw new Exception("Kiosk with type " + id + " already exists.");
|
||||||
}
|
}
|
||||||
kioskList.put(type, new KioskEntry(extractorFactory, handler));
|
kioskList.put(id, new KioskEntry(extractorFactory, handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultKiosk(String kioskType) {
|
public void setDefaultKiosk(String kioskType) {
|
||||||
@ -54,35 +54,35 @@ public class KioskList {
|
|||||||
public KioskExtractor getDefaultKioskExtractor(String nextStreamUrl)
|
public KioskExtractor getDefaultKioskExtractor(String nextStreamUrl)
|
||||||
throws ExtractionException, IOException {
|
throws ExtractionException, IOException {
|
||||||
if(defaultKiosk != null && !defaultKiosk.equals("")) {
|
if(defaultKiosk != null && !defaultKiosk.equals("")) {
|
||||||
return getExtractorByType(defaultKiosk, nextStreamUrl);
|
return getExtractorById(defaultKiosk, nextStreamUrl);
|
||||||
} else {
|
} else {
|
||||||
if(!kioskList.isEmpty()) {
|
if(!kioskList.isEmpty()) {
|
||||||
// if not set get any entry
|
// if not set get any entry
|
||||||
Object[] keySet = kioskList.keySet().toArray();
|
Object[] keySet = kioskList.keySet().toArray();
|
||||||
return getExtractorByType(keySet[0].toString(), nextStreamUrl);
|
return getExtractorById(keySet[0].toString(), nextStreamUrl);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultKioskType() {
|
public String getDefaultKioskId() {
|
||||||
return defaultKiosk;
|
return defaultKiosk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KioskExtractor getExtractorByType(String kioskType, String nextStreamsUrl)
|
public KioskExtractor getExtractorById(String kioskId, String nextStreamsUrl)
|
||||||
throws ExtractionException, IOException {
|
throws ExtractionException, IOException {
|
||||||
KioskEntry ke = kioskList.get(kioskType);
|
KioskEntry ke = kioskList.get(kioskId);
|
||||||
if(ke == null) {
|
if(ke == null) {
|
||||||
throw new ExtractionException("No kiosk found with the type: " + kioskType);
|
throw new ExtractionException("No kiosk found with the type: " + kioskId);
|
||||||
} else {
|
} else {
|
||||||
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
|
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
|
||||||
ke.handler.getUrl(kioskType),
|
ke.handler.getUrl(kioskId),
|
||||||
nextStreamsUrl, kioskType);
|
nextStreamsUrl, kioskId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getAvailableKisokTypes() {
|
public Set<String> getAvailableKisoks() {
|
||||||
return kioskList.keySet();
|
return kioskList.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ public class KioskList {
|
|||||||
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
|
for(Map.Entry<String, KioskEntry> e : kioskList.entrySet()) {
|
||||||
KioskEntry ke = e.getValue();
|
KioskEntry ke = e.getValue();
|
||||||
if(ke.handler.acceptUrl(url)) {
|
if(ke.handler.acceptUrl(url)) {
|
||||||
return getExtractorByType(e.getKey(), nextStreamsUrl);
|
return getExtractorById(e.getKey(), nextStreamsUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
|
throw new ExtractionException("Could not find a kiosk that fits to the url: " + url);
|
||||||
|
@ -14,9 +14,9 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
|
|||||||
public class SoundcloudChartsExtractor extends KioskExtractor {
|
public class SoundcloudChartsExtractor extends KioskExtractor {
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
|
public SoundcloudChartsExtractor(StreamingService service, String url, String nextStreamsUrl, String kioskId)
|
||||||
throws IOException, ExtractionException {
|
throws IOException, ExtractionException {
|
||||||
super(service, url, nextStreamsUrl, type);
|
super(service, url, nextStreamsUrl, kioskId);
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ public class SoundcloudChartsExtractor extends KioskExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
return getUrlIdHandler().getId(url);
|
return "< Implement me (♥_♥) >";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,7 +54,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor {
|
|||||||
"?genre=soundcloud:genres:all-music" +
|
"?genre=soundcloud:genres:all-music" +
|
||||||
"&client_id=" + SoundcloudParsingHelper.clientId();
|
"&client_id=" + SoundcloudParsingHelper.clientId();
|
||||||
|
|
||||||
if (getType().equals("Top 50")) {
|
if (getId().equals("Top 50")) {
|
||||||
apiUrl += "&kind=top";
|
apiUrl += "&kind=top";
|
||||||
} else {
|
} else {
|
||||||
apiUrl += "&kind=new";
|
apiUrl += "&kind=new";
|
||||||
|
@ -62,37 +62,27 @@ public class SoundcloudService extends StreamingService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KioskList getKioskList() throws ExtractionException {
|
public KioskList getKioskList() throws ExtractionException {
|
||||||
|
KioskList.KioskExtractorFactory chartsFactory = new KioskList.KioskExtractorFactory() {
|
||||||
|
@Override
|
||||||
|
public KioskExtractor createNewKiosk(StreamingService streamingService,
|
||||||
|
String url,
|
||||||
|
String nextStreamUrl,
|
||||||
|
String id)
|
||||||
|
throws ExtractionException, IOException {
|
||||||
|
return new SoundcloudChartsExtractor(SoundcloudService.this,
|
||||||
|
url,
|
||||||
|
nextStreamUrl,
|
||||||
|
id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
KioskList list = new KioskList(getServiceId());
|
KioskList list = new KioskList(getServiceId());
|
||||||
|
|
||||||
// add kiosks here e.g.:
|
// add kiosks here e.g.:
|
||||||
final SoundcloudChartsUrlIdHandler h = new SoundcloudChartsUrlIdHandler();
|
final SoundcloudChartsUrlIdHandler h = new SoundcloudChartsUrlIdHandler();
|
||||||
try {
|
try {
|
||||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
list.addKioskEntry(chartsFactory, h, "Top 50");
|
||||||
@Override
|
list.addKioskEntry(chartsFactory, h, "New & hot");
|
||||||
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, "Top 50");
|
|
||||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
|
||||||
@Override
|
|
||||||
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, "New & hot");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ExtractionException(e);
|
throw new ExtractionException(e);
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,9 @@ public class YoutubeService extends StreamingService {
|
|||||||
try {
|
try {
|
||||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||||
@Override
|
@Override
|
||||||
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl, String type)
|
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String nextStreamUrl, String id)
|
||||||
throws ExtractionException, IOException {
|
throws ExtractionException, IOException {
|
||||||
return new YoutubeTrendingExtractor(YoutubeService.this, url, nextStreamUrl, type);
|
return new YoutubeTrendingExtractor(YoutubeService.this, url, nextStreamUrl, id);
|
||||||
}
|
}
|
||||||
}, new YoutubeTrendingUrlIdHandler(), "Trending");
|
}, new YoutubeTrendingUrlIdHandler(), "Trending");
|
||||||
list.setDefaultKiosk("Trending");
|
list.setDefaultKiosk("Trending");
|
||||||
|
@ -35,9 +35,9 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
|
|||||||
|
|
||||||
private Document doc;
|
private Document doc;
|
||||||
|
|
||||||
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl, String type)
|
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl, String kioskId)
|
||||||
throws IOException, ExtractionException {
|
throws IOException, ExtractionException {
|
||||||
super(service, url, nextStreamsUrl, type);
|
super(service, url, nextStreamsUrl, kioskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,6 +64,18 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() throws ParsingException {
|
||||||
|
try {
|
||||||
|
Element a = doc.select("a[href*=\"/feed/trending\"]").first();
|
||||||
|
Element span = a.select("span[class*=\"display-name\"]").first();
|
||||||
|
Element nameSpan = span.select("span").first();
|
||||||
|
return nameSpan.text();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new ParsingException("Could not get Trending name", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StreamInfoItemCollector getStreams() throws ParsingException {
|
public StreamInfoItemCollector getStreams() throws ParsingException {
|
||||||
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
|
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
|
||||||
|
@ -25,7 +25,7 @@ public class SoundcloudChartsExtractorTest {
|
|||||||
NewPipe.init(Downloader.getInstance());
|
NewPipe.init(Downloader.getInstance());
|
||||||
extractor = SoundCloud.getService()
|
extractor = SoundCloud.getService()
|
||||||
.getKioskList()
|
.getKioskList()
|
||||||
.getExtractorByType("Top 50", null);
|
.getExtractorById("Top 50", null);
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public class YoutubeServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetKioskAvailableKiosks() throws Exception {
|
public void testGetKioskAvailableKiosks() throws Exception {
|
||||||
assertFalse("No kiosk got returned", kioskList.getAvailableKisokTypes().isEmpty());
|
assertFalse("No kiosk got returned", kioskList.getAvailableKisoks().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -54,7 +54,12 @@ public class YoutubeTreindingKioskInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getType() {
|
public void getId() {
|
||||||
assertEquals(kioskInfo.type, "Trending");
|
assertEquals(kioskInfo.id, "Trending");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getName() {
|
||||||
|
assertFalse(kioskInfo.name.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class YoutubeTrendingExtractorTest {
|
|||||||
NewPipe.init(Downloader.getInstance());
|
NewPipe.init(Downloader.getInstance());
|
||||||
extractor = YouTube.getService()
|
extractor = YouTube.getService()
|
||||||
.getKioskList()
|
.getKioskList()
|
||||||
.getExtractorByType("Trending", null);
|
.getExtractorById("Trending", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -56,7 +56,8 @@ public class YoutubeTrendingExtractorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetName() throws Exception {
|
public void testGetName() throws Exception {
|
||||||
assertEquals(extractor.getName(), "Trending");
|
System.out.println(extractor.getName());
|
||||||
|
assertFalse(extractor.getName().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user