|
22 | 22 | import java.time.OffsetDateTime; |
23 | 23 | import java.time.ZoneOffset; |
24 | 24 | import java.time.format.DateTimeParseException; |
| 25 | +import java.util.ArrayList; |
25 | 26 | import java.util.Collections; |
26 | 27 | import java.util.List; |
27 | 28 | import java.util.stream.Collectors; |
@@ -198,6 +199,47 @@ public static List<Image> getBannersFromAccountOrVideoChannelObject( |
198 | 199 | "banners", "banner"); |
199 | 200 | } |
200 | 201 |
|
| 202 | + /** |
| 203 | + * Get thumbnails from a playlist or a video item {@link JsonObject}. |
| 204 | + * |
| 205 | + * <p> |
| 206 | + * PeerTube provides two thumbnails in its API: a low one, represented by the value of the |
| 207 | + * {@code thumbnailPath} key, and a medium one, represented by the value of the |
| 208 | + * {@code previewPath} key. |
| 209 | + * </p> |
| 210 | + * |
| 211 | + * <p> |
| 212 | + * If a value is not null or empty, an {@link Image} will be added to the list returned with |
| 213 | + * the URL to the thumbnail ({@code baseUrl + value}), a height and a width unknown and the |
| 214 | + * corresponding resolution level (see above). |
| 215 | + * </p> |
| 216 | + * |
| 217 | + * @param baseUrl the base URL of the PeerTube instance |
| 218 | + * @param playlistOrVideoItemObject the playlist or the video item {@link JsonObject}, which |
| 219 | + * must not be null |
| 220 | + * @return an unmodifiable list of {@link Image}s, which is never null but can be empty |
| 221 | + */ |
| 222 | + @Nonnull |
| 223 | + public static List<Image> getThumbnailsFromPlaylistOrVideoItem( |
| 224 | + @Nonnull final String baseUrl, |
| 225 | + @Nonnull final JsonObject playlistOrVideoItemObject) { |
| 226 | + final List<Image> imageList = new ArrayList<>(2); |
| 227 | + |
| 228 | + final String thumbnailPath = playlistOrVideoItemObject.getString("thumbnailPath"); |
| 229 | + if (!isNullOrEmpty(thumbnailPath)) { |
| 230 | + imageList.add(new Image(baseUrl + thumbnailPath, HEIGHT_UNKNOWN, WIDTH_UNKNOWN, |
| 231 | + ResolutionLevel.LOW)); |
| 232 | + } |
| 233 | + |
| 234 | + final String previewPath = playlistOrVideoItemObject.getString("previewPath"); |
| 235 | + if (!isNullOrEmpty(previewPath)) { |
| 236 | + imageList.add(new Image(baseUrl + previewPath, HEIGHT_UNKNOWN, WIDTH_UNKNOWN, |
| 237 | + ResolutionLevel.MEDIUM)); |
| 238 | + } |
| 239 | + |
| 240 | + return Collections.unmodifiableList(imageList); |
| 241 | + } |
| 242 | + |
201 | 243 | /** |
202 | 244 | * Utility method to get avatars and banners from video channels and accounts from given name |
203 | 245 | * keys. |
|
0 commit comments