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

70 lines
2.5 KiB
Java
Raw Normal View History

2018-05-08 21:19:03 +02:00
package org.schabi.newpipe.extractor.services.youtube.extractors;
import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Utils;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
2020-02-27 17:39:23 +01:00
public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
2022-03-18 15:09:06 +01:00
private final JsonObject playlistInfoItem;
2022-03-18 15:09:06 +01:00
public YoutubePlaylistInfoItemExtractor(final JsonObject playlistInfoItem) {
this.playlistInfoItem = playlistInfoItem;
}
@Override
public String getThumbnailUrl() throws ParsingException {
try {
2022-03-18 15:09:06 +01:00
final String url = playlistInfoItem.getArray("thumbnails").getObject(0)
2020-02-27 19:08:46 +01:00
.getArray("thumbnails").getObject(0).getString("url");
return fixThumbnailUrl(url);
2022-03-18 15:09:06 +01:00
} catch (final Exception e) {
throw new ParsingException("Could not get thumbnail url", e);
}
}
@Override
public String getName() throws ParsingException {
try {
2020-02-27 17:39:23 +01:00
return getTextFromObject(playlistInfoItem.getObject("title"));
2022-03-18 15:09:06 +01:00
} catch (final Exception e) {
throw new ParsingException("Could not get name", e);
}
}
@Override
public String getUrl() throws ParsingException {
try {
2022-03-18 15:09:06 +01:00
final String id = playlistInfoItem.getString("playlistId");
return YoutubePlaylistLinkHandlerFactory.getInstance().getUrl(id);
2022-03-18 15:09:06 +01:00
} catch (final Exception e) {
throw new ParsingException("Could not get url", e);
}
}
@Override
public String getUploaderName() throws ParsingException {
try {
2020-02-27 17:39:23 +01:00
return getTextFromObject(playlistInfoItem.getObject("longBylineText"));
2022-03-18 15:09:06 +01:00
} catch (final Exception e) {
throw new ParsingException("Could not get uploader name", e);
}
}
@Override
public long getStreamCount() throws ParsingException {
try {
2022-03-18 15:09:06 +01:00
return Long.parseLong(Utils.removeNonDigitCharacters(
playlistInfoItem.getString("videoCount")));
} catch (final Exception e) {
throw new ParsingException("Could not get stream count", e);
}
}
}