add youtube trending extractor

This commit is contained in:
Christian Schabesberger 2017-08-12 21:10:21 +02:00
parent a6c1728dac
commit b89f5a9b42
5 changed files with 121 additions and 28 deletions

View File

@ -49,7 +49,7 @@ public abstract class StreamingService {
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
public abstract KioskList getKioskList();
public abstract KioskList getKioskList() throws ExtractionException;
public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
return getChannelExtractor(url, null);

View File

@ -1,25 +1,5 @@
package org.schabi.newpipe.extractor.kiosk;
/*
* Created by Christian Schabesberger on 12.08.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* KioskList.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.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -27,7 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class KioskList {
public class KioskList {
private int service_id;
private HashMap<String, KioskEntry> kioskList = new HashMap<>();
@ -44,12 +24,12 @@ public class KioskList {
this.service_id = service_id;
}
public void addKioskEntry(String kioskType, KioskExtractor extractor, UrlIdHandler handler)
public void addKioskEntry(KioskExtractor extractor, UrlIdHandler handler)
throws Exception {
if(kioskList.get(kioskType) != null) {
throw new Exception("Kiosk with type " + kioskType + " already exists.");
if(kioskList.get(extractor.getType()) != null) {
throw new Exception("Kiosk with type " + extractor.getType() + " already exists.");
}
kioskList.put(kioskType, new KioskEntry(extractor, handler));
kioskList.put(extractor.getType(), new KioskEntry(extractor, handler));
}
public KioskExtractor getExtractorByType(String kioskType) throws ExtractionException {

View File

@ -81,11 +81,16 @@ public class YoutubeService extends StreamingService {
}
@Override
public KioskList getKioskList() {
public KioskList getKioskList() throws ExtractionException {
KioskList list = new KioskList(getServiceId());
// add kiosks here e.g.:
//list.addKioskEntry("trinding", new TrendingKiosk(), new TrendingUrlIdHandler());
YoutubeTrendingUrlIdHandler h = new YoutubeTrendingUrlIdHandler();
try {
list.addKioskEntry(new YoutubeTrendingExtractor(this, h.getUrl(""), h.getUrl("")), h);
} catch (Exception e) {
throw new ExtractionException(e);
}
return list;
}

View File

@ -0,0 +1,63 @@
package org.schabi.newpipe.extractor.services.youtube;
/*
* Created by Christian Schabesberger on 12.08.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* YoutubeTrendingExtractor.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.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import java.io.IOException;
public class YoutubeTrendingExtractor extends KioskExtractor {
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl)
throws IOException, ExtractionException {
super(service, url, nextStreamsUrl);
}
@Override
public void fetchPage()
throws IOException, ExtractionException {
}
@Override
public String getType() {
return "Treinding";
}
@Override
public UrlIdHandler getUrlIdHandler() {
return new YoutubeTrendingUrlIdHandler();
}
@Override
public ListExtractor.NextItemsResult getNextStreams() {
return null;
}
@Override
public StreamInfoItemCollector getStreams() {
return null;
}
}

View File

@ -0,0 +1,45 @@
package org.schabi.newpipe.extractor.services.youtube;
/*
* Created by Christian Schabesberger on 12.08.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* YoutubeTrendingUrlIdHandler.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.schabi.newpipe.extractor.UrlIdHandler;
public class YoutubeTrendingUrlIdHandler implements UrlIdHandler {
public String getUrl(String id) {
return "https://www.youtube.com/feed/trending";
}
@Override
public String getId(String url) {
return "Trending";
}
@Override
public String cleanUrl(String url) {
return getUrl("");
}
@Override
public boolean acceptUrl(String url) {
return url.contains("feed/treinding");
}
}