Skip to content

Commit 7eddf9a

Browse files
committed
Prevent NPE on live streams and cache correctly
1 parent 370a3b6 commit 7eddf9a

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
4242
private final TimeAgoParser timeAgoParser;
4343

4444
private String cachedName;
45-
private String cachedTextualUploadDate;
45+
private Optional<String> cachedTextualUploadDate;
4646

4747
private JsonArray cachedMetadataRows;
4848

@@ -198,13 +198,13 @@ public boolean isUploaderVerified() throws ParsingException {
198198
@Override
199199
public String getTextualUploadDate() throws ParsingException {
200200
if (cachedTextualUploadDate != null) {
201-
return cachedTextualUploadDate;
201+
return cachedTextualUploadDate.orElse(null);
202202
}
203203

204+
// This might be null e.g. for live streams
204205
this.cachedTextualUploadDate = metadataPart(1, 1)
205-
.map(this::getTextContentFromMetadataPart)
206-
.orElse(null);
207-
return cachedTextualUploadDate;
206+
.map(this::getTextContentFromMetadataPart);
207+
return cachedTextualUploadDate.orElse(null);
208208
}
209209

210210
@Nullable
@@ -214,7 +214,12 @@ public DateWrapper getUploadDate() throws ParsingException {
214214
return null;
215215
}
216216

217-
return timeAgoParser.parse(getTextualUploadDate());
217+
final String textualUploadDate = getTextualUploadDate();
218+
// Prevent NPE when e.g. a live stream is shown
219+
if (textualUploadDate == null) {
220+
return null;
221+
}
222+
return timeAgoParser.parse(textualUploadDate);
218223
}
219224

220225
@Override

0 commit comments

Comments
 (0)