2019-12-16 08:35:44 +01:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
|
|
|
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
2020-10-18 05:48:14 +02:00
|
|
|
import java.time.OffsetDateTime;
|
|
|
|
import java.time.format.DateTimeParseException;
|
2019-12-16 08:35:44 +01:00
|
|
|
|
|
|
|
public class YoutubeFeedInfoItemExtractor implements StreamInfoItemExtractor {
|
|
|
|
private final Element entryElement;
|
|
|
|
|
2022-03-18 15:09:06 +01:00
|
|
|
public YoutubeFeedInfoItemExtractor(final Element entryElement) {
|
2019-12-16 08:35:44 +01:00
|
|
|
this.entryElement = entryElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamType getStreamType() {
|
|
|
|
// It is not possible to determine the stream type using the feed endpoint.
|
|
|
|
// All entries are considered a video stream.
|
|
|
|
return StreamType.VIDEO_STREAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isAd() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getDuration() {
|
|
|
|
// Not available when fetching through the feed endpoint.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getViewCount() {
|
2022-03-18 15:09:06 +01:00
|
|
|
return Long.parseLong(entryElement.getElementsByTag("media:statistics").first()
|
|
|
|
.attr("views"));
|
2019-12-16 08:35:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUploaderName() {
|
|
|
|
return entryElement.select("author > name").first().text();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUploaderUrl() {
|
|
|
|
return entryElement.select("author > uri").first().text();
|
|
|
|
}
|
|
|
|
|
2021-09-01 20:40:00 +02:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public String getUploaderAvatarUrl() throws ParsingException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-22 01:44:58 +01:00
|
|
|
@Override
|
|
|
|
public boolean isUploaderVerified() throws ParsingException {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-16 08:35:44 +01:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public String getTextualUploadDate() {
|
|
|
|
return entryElement.getElementsByTag("published").first().text();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public DateWrapper getUploadDate() throws ParsingException {
|
|
|
|
try {
|
2020-11-02 04:44:52 +01:00
|
|
|
return new DateWrapper(OffsetDateTime.parse(getTextualUploadDate()));
|
2022-03-18 15:09:06 +01:00
|
|
|
} catch (final DateTimeParseException e) {
|
|
|
|
throw new ParsingException("Could not parse date (\"" + getTextualUploadDate() + "\")",
|
|
|
|
e);
|
2019-12-16 08:35:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return entryElement.getElementsByTag("title").first().text();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUrl() {
|
|
|
|
return entryElement.getElementsByTag("link").first().attr("href");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getThumbnailUrl() {
|
|
|
|
return entryElement.getElementsByTag("media:thumbnail").first().attr("url");
|
|
|
|
}
|
|
|
|
}
|