Prevent NPE on live streams and cache correctly

pull/1320/head
litetex 2025-07-11 20:53:14 +02:00
rodzic ba2efde599
commit ef6a53ebb3
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 525B43E6039B3689
1 zmienionych plików z 11 dodań i 6 usunięć

Wyświetl plik

@ -42,7 +42,7 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
private final TimeAgoParser timeAgoParser; private final TimeAgoParser timeAgoParser;
private String cachedName; private String cachedName;
private String cachedTextualUploadDate; private Optional<String> cachedTextualUploadDate;
private JsonArray cachedMetadataRows; private JsonArray cachedMetadataRows;
@ -198,13 +198,13 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
@Override @Override
public String getTextualUploadDate() throws ParsingException { public String getTextualUploadDate() throws ParsingException {
if (cachedTextualUploadDate != null) { if (cachedTextualUploadDate != null) {
return cachedTextualUploadDate; return cachedTextualUploadDate.orElse(null);
} }
// This might be null e.g. for live streams
this.cachedTextualUploadDate = metadataPart(1, 1) this.cachedTextualUploadDate = metadataPart(1, 1)
.map(this::getTextContentFromMetadataPart) .map(this::getTextContentFromMetadataPart);
.orElse(null); return cachedTextualUploadDate.orElse(null);
return cachedTextualUploadDate;
} }
@Nullable @Nullable
@ -214,7 +214,12 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra
return null; return null;
} }
return timeAgoParser.parse(getTextualUploadDate()); final String textualUploadDate = getTextualUploadDate();
// Prevent NPE when e.g. a live stream is shown
if (textualUploadDate == null) {
return null;
}
return timeAgoParser.parse(textualUploadDate);
} }
@Override @Override