2018-05-08 21:19:03 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
2017-08-16 02:11:38 +02:00
|
|
|
|
2020-02-23 19:45:45 +01:00
|
|
|
import com.grack.nanojson.JsonObject;
|
|
|
|
|
2017-08-16 02:11:38 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
2020-02-23 19:45:45 +01:00
|
|
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
|
2017-08-16 02:11:38 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
|
|
|
|
2020-04-10 10:51:05 +02:00
|
|
|
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
|
|
|
|
2017-08-16 02:11:38 +02:00
|
|
|
public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
2022-03-18 15:09:06 +01:00
|
|
|
private final JsonObject playlistInfoItem;
|
2017-08-16 02:11:38 +02:00
|
|
|
|
2022-03-18 15:09:06 +01:00
|
|
|
public YoutubePlaylistInfoItemExtractor(final JsonObject playlistInfoItem) {
|
2020-02-23 19:45:45 +01:00
|
|
|
this.playlistInfoItem = playlistInfoItem;
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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");
|
|
|
|
|
2020-02-28 09:36:33 +01:00
|
|
|
return fixThumbnailUrl(url);
|
2022-03-18 15:09:06 +01:00
|
|
|
} catch (final Exception e) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get thumbnail url", e);
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get name", e);
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUrl() throws ParsingException {
|
|
|
|
try {
|
2022-03-18 15:09:06 +01:00
|
|
|
final String id = playlistInfoItem.getString("playlistId");
|
2020-02-23 19:45:45 +01:00
|
|
|
return YoutubePlaylistLinkHandlerFactory.getInstance().getUrl(id);
|
2022-03-18 15:09:06 +01:00
|
|
|
} catch (final Exception e) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get url", e);
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get uploader name", e);
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2020-02-23 19:45:45 +01:00
|
|
|
throw new ParsingException("Could not get stream count", e);
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|