Class PeertubeParsingHelper


  • public final class PeertubeParsingHelper
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void collectItemsFrom​(InfoItemsCollector collector, com.grack.nanojson.JsonObject json, java.lang.String baseUrl)  
      static void collectItemsFrom​(InfoItemsCollector collector, com.grack.nanojson.JsonObject json, java.lang.String baseUrl, boolean sepia)
      Collect items from the given JSON object with the given collector.
      static java.util.List<Image> getAvatarsFromOwnerAccountOrVideoChannelObject​(java.lang.String baseUrl, com.grack.nanojson.JsonObject ownerAccountOrVideoChannelObject)
      Get avatars from a ownerAccount or a videoChannel JsonObject.
      static java.util.List<Image> getBannersFromAccountOrVideoChannelObject​(java.lang.String baseUrl, com.grack.nanojson.JsonObject ownerAccountOrVideoChannelObject)
      Get banners from a ownerAccount or a videoChannel JsonObject.
      static Page getNextPage​(java.lang.String prevPageUrl, long total)  
      static java.util.List<Image> getThumbnailsFromPlaylistOrVideoItem​(java.lang.String baseUrl, com.grack.nanojson.JsonObject playlistOrVideoItemObject)
      Get thumbnails from a playlist or a video item JsonObject.
      static java.time.OffsetDateTime parseDateFrom​(java.lang.String textualUploadDate)  
      static void validate​(com.grack.nanojson.JsonObject json)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getNextPage

        public static Page getNextPage​(java.lang.String prevPageUrl,
                                       long total)
      • collectItemsFrom

        public static void collectItemsFrom​(InfoItemsCollector collector,
                                            com.grack.nanojson.JsonObject json,
                                            java.lang.String baseUrl,
                                            boolean sepia)
                                     throws ParsingException
        Collect items from the given JSON object with the given collector.

        Supported info item types are streams with their Sepia variant, channels and playlists.

        Parameters:
        collector - the collector used to collect information
        json - the JSOn response to retrieve data from
        baseUrl - the base URL of the instance
        sepia - if we should use PeertubeSepiaStreamInfoItemExtractor to extract streams or PeertubeStreamInfoItemExtractor otherwise
        Throws:
        ParsingException
      • getAvatarsFromOwnerAccountOrVideoChannelObject

        @Nonnull
        public static java.util.List<Image> getAvatarsFromOwnerAccountOrVideoChannelObject​(@Nonnull
                                                                                           java.lang.String baseUrl,
                                                                                           @Nonnull
                                                                                           com.grack.nanojson.JsonObject ownerAccountOrVideoChannelObject)
        Get avatars from a ownerAccount or a videoChannel JsonObject.

        If the avatars JsonArray is present and non null or empty, avatars will be extracted from this array using getImagesFromAvatarOrBannerArray(String, JsonArray).

        If that's not the case, an avatar will extracted using the avatar JsonObject.

        Note that only images for which paths are not null and not empty will be added to the unmodifiable Image list returned.

        Parameters:
        baseUrl - the base URL of the PeerTube instance
        ownerAccountOrVideoChannelObject - the ownerAccount or videoChannel JsonObject
        Returns:
        an unmodifiable list of Images, which may be empty but never null
      • getBannersFromAccountOrVideoChannelObject

        @Nonnull
        public static java.util.List<Image> getBannersFromAccountOrVideoChannelObject​(@Nonnull
                                                                                      java.lang.String baseUrl,
                                                                                      @Nonnull
                                                                                      com.grack.nanojson.JsonObject ownerAccountOrVideoChannelObject)
        Get banners from a ownerAccount or a videoChannel JsonObject.

        If the banners JsonArray is present and non null or empty, banners will be extracted from this array using getImagesFromAvatarOrBannerArray(String, JsonArray).

        If that's not the case, a banner will extracted using the banner JsonObject.

        Note that only images for which paths are not null and not empty will be added to the unmodifiable Image list returned.

        Parameters:
        baseUrl - the base URL of the PeerTube instance
        ownerAccountOrVideoChannelObject - the ownerAccount or videoChannel JsonObject
        Returns:
        an unmodifiable list of Images, which may be empty but never null
      • getThumbnailsFromPlaylistOrVideoItem

        @Nonnull
        public static java.util.List<Image> getThumbnailsFromPlaylistOrVideoItem​(@Nonnull
                                                                                 java.lang.String baseUrl,
                                                                                 @Nonnull
                                                                                 com.grack.nanojson.JsonObject playlistOrVideoItemObject)
        Get thumbnails from a playlist or a video item JsonObject.

        PeerTube provides two thumbnails in its API: a low one, represented by the value of the thumbnailPath key, and a medium one, represented by the value of the previewPath key.

        If a value is not null or empty, an Image will be added to the list returned with the URL to the thumbnail (baseUrl + value), a height and a width unknown and the corresponding resolution level (see above).

        Parameters:
        baseUrl - the base URL of the PeerTube instance
        playlistOrVideoItemObject - the playlist or the video item JsonObject, which must not be null
        Returns:
        an unmodifiable list of Images, which is never null but can be empty