Skip to content

Commit c79afc0

Browse files
Apply code review suggestions
1 parent e9dd84f commit c79afc0

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,20 @@ public String getName() throws ParsingException {
174174
@Nullable
175175
@Override
176176
public String getTextualUploadDate() throws ParsingException {
177-
final String dateStr = playerMicroFormatRenderer.getString("uploadDate",
178-
playerMicroFormatRenderer.getString("publishDate", ""));
179-
if (!dateStr.isEmpty()) {
180-
return dateStr;
177+
String timestamp = playerMicroFormatRenderer.getString("uploadDate", "");
178+
if (timestamp.isEmpty()) {
179+
timestamp = playerMicroFormatRenderer.getString("publishDate", "");
180+
}
181+
if (!timestamp.isEmpty()) {
182+
return timestamp;
181183
}
182184

183185
final var liveDetails = playerMicroFormatRenderer.getObject("liveBroadcastDetails");
184-
final String timestamp = liveDetails.getString("endTimestamp", // an ended live stream
185-
liveDetails.getString("startTimestamp", "")); // a running live stream
186-
186+
timestamp = liveDetails.getString("endTimestamp", ""); // an ended live stream
187+
if (timestamp.isEmpty()) {
188+
// a running live stream
189+
timestamp = liveDetails.getString("startTimestamp", "");
190+
}
187191
if (!timestamp.isEmpty()) {
188192
return timestamp;
189193
} else if (getStreamType() == StreamType.LIVE_STREAM) {
@@ -229,7 +233,8 @@ public DateWrapper getUploadDate() throws ParsingException {
229233
final var instant = date.atStartOfDay(ZoneId.systemDefault()).toInstant();
230234
return new DateWrapper(instant, true);
231235
})
232-
.orElseThrow(() -> new ParsingException("Could not parse upload date"));
236+
.orElseThrow(() -> new ParsingException("Could not parse upload date \""
237+
+ dateText + "\""));
233238
}
234239

235240
private Optional<LocalDate> parseOptionalDate(final String date, final String pattern) {

0 commit comments

Comments
 (0)