Skip to content

Commit b89f5a9

Browse files
committed
add youtube trending extractor
1 parent a6c1728 commit b89f5a9

5 files changed

Lines changed: 121 additions & 28 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/StreamingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ServiceInfo getServiceInfo() {
4949
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
5050
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
5151
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
52-
public abstract KioskList getKioskList();
52+
public abstract KioskList getKioskList() throws ExtractionException;
5353

5454
public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
5555
return getChannelExtractor(url, null);

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

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
package org.schabi.newpipe.extractor.kiosk;
22

3-
/*
4-
* Created by Christian Schabesberger on 12.08.17.
5-
*
6-
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
7-
* KioskList.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-
233
import org.schabi.newpipe.extractor.UrlIdHandler;
244
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
255

266
import java.util.HashMap;
277
import java.util.Map;
288
import java.util.Set;
299

30-
public class KioskList {
10+
public class KioskList {
3111
private int service_id;
3212
private HashMap<String, KioskEntry> kioskList = new HashMap<>();
3313

@@ -44,12 +24,12 @@ public KioskList(int service_id) {
4424
this.service_id = service_id;
4525
}
4626

47-
public void addKioskEntry(String kioskType, KioskExtractor extractor, UrlIdHandler handler)
27+
public void addKioskEntry(KioskExtractor extractor, UrlIdHandler handler)
4828
throws Exception {
49-
if(kioskList.get(kioskType) != null) {
50-
throw new Exception("Kiosk with type " + kioskType + " already exists.");
29+
if(kioskList.get(extractor.getType()) != null) {
30+
throw new Exception("Kiosk with type " + extractor.getType() + " already exists.");
5131
}
52-
kioskList.put(kioskType, new KioskEntry(extractor, handler));
32+
kioskList.put(extractor.getType(), new KioskEntry(extractor, handler));
5333
}
5434

5535
public KioskExtractor getExtractorByType(String kioskType) throws ExtractionException {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,16 @@ public SuggestionExtractor getSuggestionExtractor() {
8181
}
8282

8383
@Override
84-
public KioskList getKioskList() {
84+
public KioskList getKioskList() throws ExtractionException {
8585
KioskList list = new KioskList(getServiceId());
8686

8787
// add kiosks here e.g.:
88-
//list.addKioskEntry("trinding", new TrendingKiosk(), new TrendingUrlIdHandler());
88+
YoutubeTrendingUrlIdHandler h = new YoutubeTrendingUrlIdHandler();
89+
try {
90+
list.addKioskEntry(new YoutubeTrendingExtractor(this, h.getUrl(""), h.getUrl("")), h);
91+
} catch (Exception e) {
92+
throw new ExtractionException(e);
93+
}
8994

9095
return list;
9196
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
* YoutubeTrendingExtractor.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.schabi.newpipe.extractor.ListExtractor;
24+
import org.schabi.newpipe.extractor.StreamingService;
25+
import org.schabi.newpipe.extractor.UrlIdHandler;
26+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
27+
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
28+
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
29+
import java.io.IOException;
30+
31+
public class YoutubeTrendingExtractor extends KioskExtractor {
32+
33+
public YoutubeTrendingExtractor(StreamingService service, String url, String nextStreamsUrl)
34+
throws IOException, ExtractionException {
35+
super(service, url, nextStreamsUrl);
36+
}
37+
38+
@Override
39+
public void fetchPage()
40+
throws IOException, ExtractionException {
41+
42+
}
43+
44+
@Override
45+
public String getType() {
46+
return "Treinding";
47+
}
48+
49+
@Override
50+
public UrlIdHandler getUrlIdHandler() {
51+
return new YoutubeTrendingUrlIdHandler();
52+
}
53+
54+
@Override
55+
public ListExtractor.NextItemsResult getNextStreams() {
56+
return null;
57+
}
58+
59+
@Override
60+
public StreamInfoItemCollector getStreams() {
61+
return null;
62+
}
63+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
* YoutubeTrendingUrlIdHandler.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.schabi.newpipe.extractor.UrlIdHandler;
24+
25+
public class YoutubeTrendingUrlIdHandler implements UrlIdHandler {
26+
27+
public String getUrl(String id) {
28+
return "https://www.youtube.com/feed/trending";
29+
}
30+
31+
@Override
32+
public String getId(String url) {
33+
return "Trending";
34+
}
35+
36+
@Override
37+
public String cleanUrl(String url) {
38+
return getUrl("");
39+
}
40+
41+
@Override
42+
public boolean acceptUrl(String url) {
43+
return url.contains("feed/treinding");
44+
}
45+
}

0 commit comments

Comments
 (0)