NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelInfoItemExtra...

90 lines
2.9 KiB
Java
Raw Normal View History

2017-03-01 18:47:52 +01:00
package org.schabi.newpipe.extractor.services.youtube;
import org.jsoup.nodes.Element;
2017-08-11 03:23:09 +02:00
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
2017-03-01 18:47:52 +01:00
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Utils;
2017-03-01 18:47:52 +01:00
/*
2017-03-01 18:47:52 +01:00
* Created by Christian Schabesberger on 12.02.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
2017-08-11 03:23:09 +02:00
* YoutubeChannelInfoItemExtractor.java is part of NewPipe.
2017-03-01 18:47:52 +01:00
*
* 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/>.
*/
2017-08-11 03:23:09 +02:00
public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
2017-11-30 11:34:26 +01:00
private final Element el;
2017-03-01 18:47:52 +01:00
2017-08-11 03:23:09 +02:00
public YoutubeChannelInfoItemExtractor(Element el) {
2017-03-01 18:47:52 +01:00
this.el = el;
}
@Override
2017-03-01 18:47:52 +01:00
public String getThumbnailUrl() throws ParsingException {
Element img = el.select("span[class*=\"yt-thumb-simple\"]").first()
.select("img").first();
String url = img.attr("abs:src");
if (url.contains("gif")) {
2017-03-01 18:47:52 +01:00
url = img.attr("abs:data-thumb");
}
return url;
}
@Override
2017-08-11 20:21:49 +02:00
public String getName() throws ParsingException {
2017-03-01 18:47:52 +01:00
return el.select("a[class*=\"yt-uix-tile-link\"]").first()
.text();
}
@Override
2017-08-11 20:21:49 +02:00
public String getUrl() throws ParsingException {
2017-03-01 18:47:52 +01:00
return el.select("a[class*=\"yt-uix-tile-link\"]").first()
.attr("abs:href");
}
@Override
2017-03-01 18:47:52 +01:00
public long getSubscriberCount() throws ParsingException {
Element subsEl = el.select("span[class*=\"yt-subscriber-count\"]").first();
if (subsEl == null) {
2017-03-01 18:47:52 +01:00
return 0;
} else {
return Long.parseLong(Utils.removeNonDigitCharacters(subsEl.text()));
2017-03-01 18:47:52 +01:00
}
}
@Override
2017-08-06 22:20:15 +02:00
public long getStreamCount() throws ParsingException {
2017-03-01 18:47:52 +01:00
Element metaEl = el.select("ul[class*=\"yt-lockup-meta-info\"]").first();
if (metaEl == null) {
2017-03-01 18:47:52 +01:00
return 0;
} else {
return Long.parseLong(Utils.removeNonDigitCharacters(metaEl.text()));
2017-03-01 18:47:52 +01:00
}
}
@Override
2017-03-01 18:47:52 +01:00
public String getDescription() throws ParsingException {
Element desEl = el.select("div[class*=\"yt-lockup-description\"]").first();
if (desEl == null) {
2017-03-01 18:47:52 +01:00
return "";
} else {
return desEl.text();
}
}
}