Search in sources :

Example 1 with GphotoEntry

use of com.google.gdata.data.photos.GphotoEntry in project data-transfer-project by google.

the class GooglePhotosExporter method exportPhotos.

private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, String albumId, Optional<PaginationData> paginationData) {
    try {
        int startItem = 1;
        if (paginationData.isPresent()) {
            String token = ((StringPaginationToken) paginationData.get()).getToken();
            Preconditions.checkArgument(token.startsWith(PHOTO_TOKEN_PREFIX), "Invalid pagination token " + token);
            startItem = Integer.parseInt(token.substring(PHOTO_TOKEN_PREFIX.length()));
        }
        URL photosUrl = new URL(String.format(URL_PHOTO_FEED_FORMAT, albumId, startItem, MAX_RESULTS));
        AlbumFeed photoFeed = getOrCreatePhotosService(authData).getFeed(photosUrl, AlbumFeed.class);
        PaginationData nextPageData = null;
        if (photoFeed.getEntries().size() == MAX_RESULTS) {
            int nextPageStart = startItem + MAX_RESULTS;
            nextPageData = new StringPaginationToken(PHOTO_TOKEN_PREFIX + nextPageStart);
        }
        ContinuationData continuationData = new ContinuationData(nextPageData);
        List<PhotoModel> photos = new ArrayList<>(photoFeed.getEntries().size());
        for (GphotoEntry photo : photoFeed.getEntries()) {
            MediaContent mediaContent = (MediaContent) photo.getContent();
            photos.add(new PhotoModel(photo.getTitle().getPlainText(), mediaContent.getUri(), photo.getDescription().getPlainText(), mediaContent.getMimeType().getMediaType(), albumId));
        }
        PhotosContainerResource containerResource = new PhotosContainerResource(null, photos);
        ResultType resultType = ResultType.CONTINUE;
        if (nextPageData == null) {
            resultType = ResultType.END;
        }
        return new ExportResult<>(resultType, containerResource, continuationData);
    } catch (ServiceException | IOException e) {
        return new ExportResult<>(ResultType.ERROR, e.getMessage());
    }
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) AlbumFeed(com.google.gdata.data.photos.AlbumFeed) PhotoModel(org.dataportabilityproject.types.transfer.models.photos.PhotoModel) ArrayList(java.util.ArrayList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) IOException(java.io.IOException) URL(java.net.URL) PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) ServiceException(com.google.gdata.util.ServiceException) MediaContent(com.google.gdata.data.MediaContent) GphotoEntry(com.google.gdata.data.photos.GphotoEntry) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Example 2 with GphotoEntry

use of com.google.gdata.data.photos.GphotoEntry in project data-transfer-project by google.

the class GooglePhotosService method exportPhotos.

private PhotosModelWrapper exportPhotos(String albumId, Optional<PaginationInformation> pageInfo) throws IOException {
    // imgmax=d gets the original immage as per:
    // https://developers.google.com/picasa-web/docs/2.0/reference
    URL photosUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default/albumid/" + albumId + "?imgmax=d");
    AlbumFeed photoFeed;
    try {
        photoFeed = service.getFeed(photosUrl, AlbumFeed.class);
    } catch (ServiceException e) {
        throw new IOException("Problem making request to: " + photosUrl, e);
    }
    List<PhotoModel> photos = new ArrayList<>(photoFeed.getEntries().size());
    for (GphotoEntry photo : photoFeed.getEntries()) {
        MediaContent mediaContent = (MediaContent) photo.getContent();
        photos.add(new PhotoModel(photo.getTitle().getPlainText(), mediaContent.getUri(), photo.getDescription().getPlainText(), mediaContent.getMimeType().getMediaType(), albumId));
    }
    return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, null));
}
Also used : ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) ServiceException(com.google.gdata.util.ServiceException) AlbumFeed(com.google.gdata.data.photos.AlbumFeed) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) MediaContent(com.google.gdata.data.MediaContent) IOException(java.io.IOException) GphotoEntry(com.google.gdata.data.photos.GphotoEntry) URL(java.net.URL)

Example 3 with GphotoEntry

use of com.google.gdata.data.photos.GphotoEntry in project data-transfer-project by google.

the class GooglePhotosExporter method exportAlbums.

private ExportResult<PhotosContainerResource> exportAlbums(TokensAndUrlAuthData authData, Optional<PaginationData> paginationData) {
    try {
        int startItem = 1;
        if (paginationData.isPresent()) {
            String token = ((StringPaginationToken) paginationData.get()).getToken();
            Preconditions.checkArgument(token.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + token);
            startItem = Integer.parseInt(token.substring(ALBUM_TOKEN_PREFIX.length()));
        }
        URL albumUrl = new URL(String.format(URL_ALBUM_FEED_FORMAT, startItem, MAX_RESULTS));
        UserFeed albumFeed = getOrCreatePhotosService(authData).getFeed(albumUrl, UserFeed.class);
        PaginationData nextPageData = null;
        if (albumFeed.getAlbumEntries().size() == MAX_RESULTS) {
            int nextPageStart = startItem + MAX_RESULTS;
            nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + nextPageStart);
        }
        ContinuationData continuationData = new ContinuationData(nextPageData);
        List<PhotoAlbum> albums = new ArrayList<>(albumFeed.getAlbumEntries().size());
        for (GphotoEntry googleAlbum : albumFeed.getAlbumEntries()) {
            // Add album info to list so album can be recreated later
            albums.add(new PhotoAlbum(googleAlbum.getGphotoId(), googleAlbum.getTitle().getPlainText(), googleAlbum.getDescription().getPlainText()));
            // Add album id to continuation data
            continuationData.addContainerResource(new IdOnlyContainerResource(googleAlbum.getGphotoId()));
        }
        ResultType resultType = ResultType.CONTINUE;
        if (nextPageData == null || continuationData.getContainerResources().isEmpty()) {
            resultType = ResultType.END;
        }
        PhotosContainerResource containerResource = new PhotosContainerResource(albums, null);
        return new ExportResult<>(resultType, containerResource, continuationData);
    } catch (ServiceException | IOException e) {
        return new ExportResult<>(ResultType.ERROR, e.getMessage());
    }
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) ArrayList(java.util.ArrayList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) IOException(java.io.IOException) URL(java.net.URL) PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) ServiceException(com.google.gdata.util.ServiceException) UserFeed(com.google.gdata.data.photos.UserFeed) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) PhotoAlbum(org.dataportabilityproject.types.transfer.models.photos.PhotoAlbum) GphotoEntry(com.google.gdata.data.photos.GphotoEntry) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Example 4 with GphotoEntry

use of com.google.gdata.data.photos.GphotoEntry in project data-transfer-project by google.

the class GooglePhotosService method exportAlbums.

private PhotosModelWrapper exportAlbums(Optional<PaginationInformation> pageInfo) throws IOException {
    URL albumUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default?kind=album");
    UserFeed albumFeed;
    try {
        albumFeed = service.getFeed(albumUrl, UserFeed.class);
    } catch (ServiceException e) {
        throw new IOException("Problem making request to: " + albumUrl, e);
    }
    List<PhotoAlbum> albums = new ArrayList<>(albumFeed.getEntries().size());
    List<Resource> resources = new ArrayList<>(albumFeed.getEntries().size());
    for (GphotoEntry myAlbum : albumFeed.getEntries()) {
        // Adding sub-resources tells the framework to re-call
        // export to get all the photos.
        resources.add(new IdOnlyResource(myAlbum.getGphotoId()));
        // Saving data to the album allows the target service
        // to recreate the album structure.
        albums.add(new PhotoAlbum(myAlbum.getGphotoId(), myAlbum.getTitle().getPlainText(), myAlbum.getDescription().getPlainText()));
    }
    return new PhotosModelWrapper(albums, null, new ContinuationInformation(resources, null));
}
Also used : ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) URL(java.net.URL) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) ServiceException(com.google.gdata.util.ServiceException) UserFeed(com.google.gdata.data.photos.UserFeed) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) GphotoEntry(com.google.gdata.data.photos.GphotoEntry)

Aggregations

GphotoEntry (com.google.gdata.data.photos.GphotoEntry)4 ServiceException (com.google.gdata.util.ServiceException)4 IOException (java.io.IOException)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 MediaContent (com.google.gdata.data.MediaContent)2 AlbumFeed (com.google.gdata.data.photos.AlbumFeed)2 UserFeed (com.google.gdata.data.photos.UserFeed)2 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)2 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)2 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)2 ResultType (org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType)2 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)2 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)2 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)2 PhotosContainerResource (org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource)2 Resource (org.dataportabilityproject.dataModels.Resource)1 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)1 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)1 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)1