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
public long getSubscriberCount() throws ParsingException {
final JsonObject subscriberInfo = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText");
if (subscriberInfo != null) {
try {
return Utils.mixedNumberWordToLong(subscriberInfo.getArray("runs").getObject(0).getString("text"));
} catch (NumberFormatException e) {
throw new ParsingException("Could not get subscriber count", e);

View File

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

View File

@ -158,12 +158,26 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
@Override
public String getTextualUploadDate() {
// 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
@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;
}