Implement getUploadDate() in YouTubeStreamInfoItemExtractor

This commit is contained in:
TobiGr 2020-02-25 10:38:54 +01:00
parent 26ea3dceb6
commit f39603f6ef
3 changed files with 16 additions and 6 deletions

View File

@ -164,11 +164,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
@Override @Override
public long getSubscriberCount() throws ParsingException { public long getSubscriberCount() throws ParsingException {
final JsonObject subscriberInfo = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText"); final JsonObject subscriberInfo = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText");
if (subscriberInfo != null) { if (subscriberInfo != null) {
try { try {
return Utils.mixedNumberWordToLong(subscriberInfo.getArray("runs").getObject(0).getString("text")); return Utils.mixedNumberWordToLong(subscriberInfo.getArray("runs").getObject(0).getString("text"));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new ParsingException("Could not get subscriber count", e); throw new ParsingException("Could not get subscriber count", e);

View File

@ -512,7 +512,6 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
} }
@Override @Override
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException { public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
assertPageFetched(); assertPageFetched();
@ -678,7 +677,6 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
} }
@Nonnull @Nonnull
private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaException { private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaException {
try { try {

View File

@ -158,12 +158,26 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
@Override @Override
public String getTextualUploadDate() { public String getTextualUploadDate() {
// TODO: Get upload date in case of a videoRenderer (not available in case of a compactVideoRenderer) // TODO: Get upload date in case of a videoRenderer (not available in case of a compactVideoRenderer)
return null; try {
String s =videoInfo.getObject("publishedTimeText").getString("simpleText");
return s;
} catch (Exception e) {
// upload date is not always available, e.g. in playlists
return null;
}
} }
@Nullable @Nullable
@Override @Override
public DateWrapper getUploadDate() { public DateWrapper getUploadDate() throws ParsingException {
String textualUploadDate = getTextualUploadDate();
if (timeAgoParser != null && textualUploadDate != null && !textualUploadDate.isEmpty()) {
try {
return timeAgoParser.parse(textualUploadDate);
} catch (ParsingException e) {
throw new ParsingException("Could not get upload date", e);
}
}
return null; return null;
} }