Skip to content

Commit f39603f

Browse files
committed
Implement getUploadDate() in YouTubeStreamInfoItemExtractor
1 parent 26ea3dc commit f39603f

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,9 @@ public String getFeedUrl() throws ParsingException {
164164

165165
@Override
166166
public long getSubscriberCount() throws ParsingException {
167-
168167
final JsonObject subscriberInfo = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText");
169168
if (subscriberInfo != null) {
170169
try {
171-
172170
return Utils.mixedNumberWordToLong(subscriberInfo.getArray("runs").getObject(0).getString("text"));
173171
} catch (NumberFormatException e) {
174172
throw new ParsingException("Could not get subscriber count", e);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ public StreamInfoItem getNextStream() throws ExtractionException {
512512
}
513513
}
514514

515-
516515
@Override
517516
public StreamInfoItemsCollector getRelatedStreams() throws ExtractionException {
518517
assertPageFetched();
@@ -678,7 +677,6 @@ private JsonObject getPlayerResponse() throws ParsingException {
678677
}
679678
}
680679

681-
682680
@Nonnull
683681
private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaException {
684682
try {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,26 @@ public String getUploaderUrl() throws ParsingException {
158158
@Override
159159
public String getTextualUploadDate() {
160160
// TODO: Get upload date in case of a videoRenderer (not available in case of a compactVideoRenderer)
161-
return null;
161+
try {
162+
String s =videoInfo.getObject("publishedTimeText").getString("simpleText");
163+
return s;
164+
} catch (Exception e) {
165+
// upload date is not always available, e.g. in playlists
166+
return null;
167+
}
162168
}
163169

164170
@Nullable
165171
@Override
166-
public DateWrapper getUploadDate() {
172+
public DateWrapper getUploadDate() throws ParsingException {
173+
String textualUploadDate = getTextualUploadDate();
174+
if (timeAgoParser != null && textualUploadDate != null && !textualUploadDate.isEmpty()) {
175+
try {
176+
return timeAgoParser.parse(textualUploadDate);
177+
} catch (ParsingException e) {
178+
throw new ParsingException("Could not get upload date", e);
179+
}
180+
}
167181
return null;
168182
}
169183

0 commit comments

Comments
 (0)