[media.ccc.de] Fix NPE in search results if they contain a future talk

This commit is contained in:
TobiGr 2020-12-30 18:34:24 +01:00
parent 3c8c8e7307
commit edf8dd0e92
4 changed files with 16 additions and 7 deletions

View File

@ -28,9 +28,9 @@ public final class MediaCCCParsingHelper {
}
}
public static boolean isLiveStreamId(final String url) {
public static boolean isLiveStreamId(final String id) {
final String pattern = "\\w+/\\w+";
return Pattern.matches(pattern, url); // {conference_slug}/{room_slug}
return Pattern.matches(pattern, id); // {conference_slug}/{room_slug}
}
public static JsonArray getLiveStreams(final Downloader downloader, final Localization localization) throws ExtractionException {

View File

@ -81,8 +81,13 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
|| getLinkHandler().getContentFilters().isEmpty()) {
JsonArray events = doc.getArray("events");
for (int i = 0; i < events.size(); i++) {
searchItems.commit(new MediaCCCStreamInfoItemExtractor(
events.getObject(i)));
// Ensure only uploaded talks are shown in the search results.
// If the release date is null, the talk has not been held or uploaded yet
// and no streams are going to be available anyway.
if (events.getObject(i).getString("release_date") != null) {
searchItems.commit(new MediaCCCStreamInfoItemExtractor(
events.getObject(i)));
}
}
}
return new InfoItemsPage<>(searchItems, null);
@ -105,7 +110,7 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
try {
doc = JsonParser.object().from(site);
} catch (JsonParserException jpe) {
throw new ExtractionException("Could not parse json.", jpe);
throw new ExtractionException("Could not parse JSON.", jpe);
}
}
if (getLinkHandler().getContentFilters().contains(CONFERENCES)

View File

@ -56,7 +56,11 @@ public class MediaCCCStreamInfoItemExtractor implements StreamInfoItemExtractor
@Nullable
@Override
public DateWrapper getUploadDate() throws ParsingException {
return new DateWrapper(MediaCCCParsingHelper.parseDateFrom(getTextualUploadDate()));
final String date = getTextualUploadDate();
if (date == null) {
return null; // event is in the future...
}
return new DateWrapper(MediaCCCParsingHelper.parseDateFrom(date));
}
@Override

View File

@ -33,7 +33,7 @@ public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory
return "https://media.ccc.de/public/events/search?q="
+ URLEncoder.encode(query, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new ParsingException("Could not create search string with querry: " + query, e);
throw new ParsingException("Could not create search string with query: " + query, e);
}
}
}