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

94 lines
3.5 KiB
Java
Raw Normal View History

2018-05-08 21:19:03 +02:00
package org.schabi.newpipe.extractor.services.youtube.extractors;
2017-03-01 18:47:52 +01:00
import com.grack.nanojson.JsonObject;
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.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
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 {
private JsonObject channelInfoItem;
2017-03-01 18:47:52 +01:00
public YoutubeChannelInfoItemExtractor(JsonObject channelInfoItem) {
this.channelInfoItem = channelInfoItem;
2017-03-01 18:47:52 +01:00
}
@Override
2017-03-01 18:47:52 +01:00
public String getThumbnailUrl() throws ParsingException {
try {
return channelInfoItem.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
} catch (Exception e) {
throw new ParsingException("Could not get thumbnail url", e);
2017-03-01 18:47:52 +01:00
}
}
@Override
2017-08-11 20:21:49 +02:00
public String getName() throws ParsingException {
try {
return channelInfoItem.getObject("title").getString("simpleText");
} catch (Exception e) {
throw new ParsingException("Could not get name", e);
}
2017-03-01 18:47:52 +01:00
}
@Override
2017-08-11 20:21:49 +02:00
public String getUrl() throws ParsingException {
try {
String id = "channel/" + channelInfoItem.getString("channelId"); // Does prepending 'channel/' always work?
return YoutubeChannelLinkHandlerFactory.getInstance().getUrl(id);
} catch (Exception e) {
throw new ParsingException("Could not get url", e);
}
2017-03-01 18:47:52 +01:00
}
@Override
public long getSubscriberCount() throws ParsingException {
try {
String subscribers = channelInfoItem.getObject("subscriberCountText").getString("simpleText").split(" ")[0];
return Utils.mixedNumberWordToLong(subscribers);
} catch (Exception e) {
throw new ParsingException("Could not get subscriber count", e);
}
2017-03-01 18:47:52 +01:00
}
@Override
2017-08-06 22:20:15 +02:00
public long getStreamCount() throws ParsingException {
try {
return Long.parseLong(Utils.removeNonDigitCharacters(channelInfoItem.getObject("videoCountText")
.getArray("runs").getObject(0).getString("text")));
} catch (Exception e) {
throw new ParsingException("Could not get stream count", e);
2017-03-01 18:47:52 +01:00
}
}
@Override
2017-03-01 18:47:52 +01:00
public String getDescription() throws ParsingException {
try {
return channelInfoItem.getObject("descriptionSnippet").getArray("runs").getObject(0).getString("text");
} catch (Exception e) {
throw new ParsingException("Could not get description", e);
2017-03-01 18:47:52 +01:00
}
}
}