Class GPhotos


  • public class GPhotos
    extends java.lang.Object
    A class providing a set of useful Google Photos operations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CREATE_MEDIA_ITEMS_BATCH_LIMIT
      Creating new media items in a batch is limited, see https://developers.google.com/photos/library/guides/upload-media#creating-media-item
    • Constructor Summary

      Constructors 
      Constructor Description
      GPhotos()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @NotNull org.apache.commons.lang3.tuple.Triple<java.util.Collection<com.google.photos.types.proto.MediaItem>,​java.util.Collection<com.google.photos.types.proto.MediaItem>,​java.util.Collection<MediaFile>> classifyMediaItemsByFilesAndGetMissingFiles​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, com.google.photos.types.proto.Album album, @NotNull java.util.stream.Stream<MediaFile> files)
      Classify media items of a given album to those matching a given files, non-matching the files, and also provide a collection of files missing in the media items.
      static java.util.stream.Stream<com.google.photos.types.proto.MediaItem> createMediaItems​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, @NotNull com.google.photos.types.proto.Album album, @NotNull java.util.Collection<MediaFile> files)
      Create new media items in a given album by uploading given files and return a stream of resulting media items.
      static com.google.photos.types.proto.Album getAlbum​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, java.lang.String id)
      Get an album of a given identifier.
      static java.lang.Iterable<com.google.photos.types.proto.Album> getAlbums​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient)
      List all albums in the user's library to be able to iterate over all the albums in this list (pagination is handled automatically).
      static java.util.stream.Stream<com.google.photos.types.proto.Album> getAlbumsStreamByTitle​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, java.lang.String titleOrRegEx, boolean isRegularExpression)
      Get a stream of all albums of a given title or matching a given regular expression (the empty regex for all albums).
      static com.google.photos.types.proto.MediaItem getMediaItem​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, java.lang.String id)
      Get a media item of a given identifier.
      static java.lang.Iterable<com.google.photos.types.proto.MediaItem> getMediaItems​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, @NotNull com.google.photos.types.proto.Album album)
      List all media items in a given album to be able to iterate over all the items in this list (pagination is handled automatically).
      static com.google.photos.types.proto.Album getOrCreateAlbum​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, java.lang.String title)
      Get or create an album of a given title.
      static java.lang.Iterable<com.google.photos.types.proto.Album> getSharedAlbums​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient)
      List all albums in the user's sharing tab to be able to iterate over all the shared albums in this list (pagination is handled automatically).
      static java.util.stream.Stream<com.google.photos.types.proto.Album> getSharedAlbumsStreamByTitle​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, java.lang.String titleOrRegEx, boolean isRegularExpression)
      Get a stream of all shared albums of a given title or matching a given regular expression (the empty regex for all shared albums).
      static @NotNull java.lang.String uploadMedia​(@NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient, @NotNull java.io.File file)
      Upload a media content from a given file.
      • Methods inherited from class java.lang.Object

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

      • CREATE_MEDIA_ITEMS_BATCH_LIMIT

        public static final int CREATE_MEDIA_ITEMS_BATCH_LIMIT
        Creating new media items in a batch is limited, see https://developers.google.com/photos/library/guides/upload-media#creating-media-item
        See Also:
        Constant Field Values
    • Constructor Detail

      • GPhotos

        public GPhotos()
    • Method Detail

      • getAlbums

        public static java.lang.Iterable<com.google.photos.types.proto.Album> getAlbums​(@NotNull
                                                                                        @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient)
        List all albums in the user's library to be able to iterate over all the albums in this list (pagination is handled automatically).
        Parameters:
        photosLibraryClient - the photos library client
        Returns:
        the iterator over the list of all albums
      • getSharedAlbums

        public static java.lang.Iterable<com.google.photos.types.proto.Album> getSharedAlbums​(@NotNull
                                                                                              @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient)
        List all albums in the user's sharing tab to be able to iterate over all the shared albums in this list (pagination is handled automatically).
        Parameters:
        photosLibraryClient - the photos library client
        Returns:
        the iterator over the list of all shared albums
      • getAlbum

        public static com.google.photos.types.proto.Album getAlbum​(@NotNull
                                                                   @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                   java.lang.String id)
        Get an album of a given identifier.
        Parameters:
        photosLibraryClient - the photos library client
        id - the album identifier
        Returns:
        the album
      • getAlbumsStreamByTitle

        public static java.util.stream.Stream<com.google.photos.types.proto.Album> getAlbumsStreamByTitle​(@NotNull
                                                                                                          @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                                                          java.lang.String titleOrRegEx,
                                                                                                          boolean isRegularExpression)
        Get a stream of all albums of a given title or matching a given regular expression (the empty regex for all albums).
        Parameters:
        photosLibraryClient - the photos library client
        titleOrRegEx - the album title or its regular expression to search
        isRegularExpression - the provided title is a regular expression
        Returns:
        the stream of the albums
      • getSharedAlbumsStreamByTitle

        public static java.util.stream.Stream<com.google.photos.types.proto.Album> getSharedAlbumsStreamByTitle​(@NotNull
                                                                                                                @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                                                                java.lang.String titleOrRegEx,
                                                                                                                boolean isRegularExpression)
        Get a stream of all shared albums of a given title or matching a given regular expression (the empty regex for all shared albums).
        Parameters:
        photosLibraryClient - the photos library client
        titleOrRegEx - the album title or its regular expression to search
        isRegularExpression - the provided title is a regular expression
        Returns:
        the stream of the shared albums
      • getOrCreateAlbum

        public static com.google.photos.types.proto.Album getOrCreateAlbum​(@NotNull
                                                                           @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                           java.lang.String title)
        Get or create an album of a given title.
        Parameters:
        photosLibraryClient - the photos library client
        title - the album title
        Returns:
        the album
      • getMediaItems

        public static java.lang.Iterable<com.google.photos.types.proto.MediaItem> getMediaItems​(@NotNull
                                                                                                @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                                                @NotNull
                                                                                                @NotNull com.google.photos.types.proto.Album album)
        List all media items in a given album to be able to iterate over all the items in this list (pagination is handled automatically).
        Parameters:
        photosLibraryClient - the photos library client
        album - the album
        Returns:
        the iterator over the list of media items
      • getMediaItem

        public static com.google.photos.types.proto.MediaItem getMediaItem​(@NotNull
                                                                           @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                           java.lang.String id)
        Get a media item of a given identifier.
        Parameters:
        photosLibraryClient - the photos library client
        id - the media item identifier
        Returns:
        the media item
      • classifyMediaItemsByFilesAndGetMissingFiles

        @NotNull
        public static @NotNull org.apache.commons.lang3.tuple.Triple<java.util.Collection<com.google.photos.types.proto.MediaItem>,​java.util.Collection<com.google.photos.types.proto.MediaItem>,​java.util.Collection<MediaFile>> classifyMediaItemsByFilesAndGetMissingFiles​(@NotNull
                                                                                                                                                                                                                                                                                          @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                                                                                                                                                                                                                                          com.google.photos.types.proto.Album album,
                                                                                                                                                                                                                                                                                          @NotNull
                                                                                                                                                                                                                                                                                          @NotNull java.util.stream.Stream<MediaFile> files)
        Classify media items of a given album to those matching a given files, non-matching the files, and also provide a collection of files missing in the media items.
        Parameters:
        photosLibraryClient - the photos library client
        files - a stream of the media files
        album - the album
        Returns:
        a triplet of the collections of media items matching the files, non-matching the files, and the collection of files missing in the media items
      • createMediaItems

        public static java.util.stream.Stream<com.google.photos.types.proto.MediaItem> createMediaItems​(@NotNull
                                                                                                        @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                                                                        @NotNull
                                                                                                        @NotNull com.google.photos.types.proto.Album album,
                                                                                                        @NotNull
                                                                                                        @NotNull java.util.Collection<MediaFile> files)
        Create new media items in a given album by uploading given files and return a stream of resulting media items.
        Parameters:
        photosLibraryClient - the photos library client
        album - the album
        files - the files
        Returns:
        the stream of the successfully created media items
      • uploadMedia

        @NotNull
        public static @NotNull java.lang.String uploadMedia​(@NotNull
                                                            @NotNull com.google.photos.library.v1.PhotosLibraryClient photosLibraryClient,
                                                            @NotNull
                                                            @NotNull java.io.File file)
                                                     throws java.io.IOException
        Upload a media content from a given file.
        Parameters:
        photosLibraryClient - the photos library client
        file - the file to upload
        Returns:
        the resulting token of the uploaded content
        Throws:
        java.io.IOException - the file cannot be found or uploaded