From d0e66cc600ad43a48e17c65e29e897f4b549a3d0 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 17 Mar 2020 15:13:28 +0100 Subject: [PATCH] [SoundCloud] Improve thumbnail url extraction in playlists Prevent NullPointerExceptions and remove duplicate code --- .../soundcloud/SoundcloudPlaylistExtractor.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java index 363a223a2..f503ac0fe 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractor.java @@ -66,6 +66,7 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { return playlist.getString("title"); } + @Nullable @Override public String getThumbnailUrl() { String artworkUrl = playlist.getString("artwork_url"); @@ -75,21 +76,20 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { // if it also fails, return null try { final InfoItemsPage infoItems = getInitialPage(); - if (infoItems.getItems().isEmpty()) return null; for (StreamInfoItem item : infoItems.getItems()) { - final String thumbnailUrl = item.getThumbnailUrl(); - if (thumbnailUrl == null || thumbnailUrl.isEmpty()) continue; - - String thumbnailUrlBetterResolution = thumbnailUrl.replace("large.jpg", "crop.jpg"); - return thumbnailUrlBetterResolution; + artworkUrl = item.getThumbnailUrl(); + if (artworkUrl != null && !artworkUrl.isEmpty()) break; } } catch (Exception ignored) { } + + if (artworkUrl == null) { + return null; + } } - String artworkUrlBetterResolution = artworkUrl.replace("large.jpg", "crop.jpg"); - return artworkUrlBetterResolution; + return artworkUrl.replace("large.jpg", "crop.jpg"); } @Override