2018-05-08 21:19:03 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2020-02-23 18:27:28 +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;
|
2020-02-23 18:27:28 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
|
2017-07-11 05:08:03 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2017-06-29 20:12:55 +02: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 {
|
2020-02-23 18:27:28 +01:00
|
|
|
private JsonObject channelInfoItem;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2020-02-23 18:27:28 +01:00
|
|
|
public YoutubeChannelInfoItemExtractor(JsonObject channelInfoItem) {
|
|
|
|
this.channelInfoItem = channelInfoItem;
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
@Override
|
2017-03-01 18:47:52 +01:00
|
|
|
public String getThumbnailUrl() throws ParsingException {
|
2020-02-23 18:27:28 +01:00
|
|
|
try {
|
2020-02-23 19:45:45 +01:00
|
|
|
return channelInfoItem.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
2020-02-23 18:27:28 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException("Could not get thumbnail url", e);
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
@Override
|
2017-08-11 20:21:49 +02:00
|
|
|
public String getName() throws ParsingException {
|
2020-02-23 18:27:28 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
@Override
|
2017-08-11 20:21:49 +02:00
|
|
|
public String getUrl() throws ParsingException {
|
2019-08-27 12:01:00 +02:00
|
|
|
try {
|
2020-02-23 18:27:28 +01:00
|
|
|
String id = "channel/" + channelInfoItem.getString("channelId"); // Does prepending 'channel/' always work?
|
|
|
|
return YoutubeChannelLinkHandlerFactory.getInstance().getUrl(id);
|
2019-08-27 13:16:08 +02:00
|
|
|
} catch (Exception e) {
|
2020-02-23 18:27:28 +01:00
|
|
|
throw new ParsingException("Could not get url", e);
|
2019-08-12 11:57:29 +02:00
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
@Override
|
2020-02-24 10:39:52 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
@Override
|
2017-08-06 22:20:15 +02:00
|
|
|
public long getStreamCount() throws ParsingException {
|
2020-02-23 18:27:28 +01:00
|
|
|
try {
|
|
|
|
return Long.parseLong(Utils.removeNonDigitCharacters(channelInfoItem.getObject("videoCountText")
|
|
|
|
.getArray("runs").getObject(0).getString("text")));
|
|
|
|
} catch (Exception e) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get stream count", e);
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
@Override
|
2017-03-01 18:47:52 +01:00
|
|
|
public String getDescription() throws ParsingException {
|
2020-02-23 18:27:28 +01:00
|
|
|
try {
|
|
|
|
return channelInfoItem.getObject("descriptionSnippet").getArray("runs").getObject(0).getString("text");
|
|
|
|
} catch (Exception e) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get description", e);
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|