From b89f5a9b42d31c22809396dc460fcc9aaf4003b7 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 12 Aug 2017 21:10:21 +0200 Subject: [PATCH] add youtube trending extractor --- .../newpipe/extractor/StreamingService.java | 2 +- .../newpipe/extractor/kiosk/KioskList.java | 30 ++------- .../services/youtube/YoutubeService.java | 9 ++- .../youtube/YoutubeTrendingExtractor.java | 63 +++++++++++++++++++ .../youtube/YoutubeTrendingUrlIdHandler.java | 45 +++++++++++++ 5 files changed, 121 insertions(+), 28 deletions(-) create mode 100644 src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java create mode 100644 src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java diff --git a/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index d4e3468bb..53935ba98 100644 --- a/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -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); diff --git a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index 0cecbdcde..c467a0b05 100644 --- a/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java +++ b/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java @@ -1,25 +1,5 @@ package org.schabi.newpipe.extractor.kiosk; -/* - * Created by Christian Schabesberger on 12.08.17. - * - * Copyright (C) Christian Schabesberger 2017 - * 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 . - */ - 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 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 { diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java index b071ba5eb..18aedbe90 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeService.java @@ -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; } diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java new file mode 100644 index 000000000..4e38e85a2 --- /dev/null +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractor.java @@ -0,0 +1,63 @@ +package org.schabi.newpipe.extractor.services.youtube; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * 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 . + */ + +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; + } +} diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java new file mode 100644 index 000000000..d6083459f --- /dev/null +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java @@ -0,0 +1,45 @@ +package org.schabi.newpipe.extractor.services.youtube; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * 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 . + */ + +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"); + } +}