Search in sources :

Example 1 with PhotosModelWrapper

use of org.dataportabilityproject.dataModels.photos.PhotosModelWrapper 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 2 with PhotosModelWrapper

use of org.dataportabilityproject.dataModels.photos.PhotosModelWrapper in project data-transfer-project by google.

the class SmugMugPhotoService method getAlbums.

private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
    String albumUri;
    if (paginationInformation.isPresent()) {
        albumUri = ((StringPaginationToken) paginationInformation.get()).getId();
    } else {
        SmugMugResponse<SmugMugUserResponse> userResponse = makeUserRequest(USER_URL);
        albumUri = userResponse.getResponse().getUser().getUris().get("UserAlbums").getUri();
    }
    List<PhotoAlbum> albums = new ArrayList<>();
    List<Resource> resources = new ArrayList<>();
    SmugMugResponse<SmugmugAlbumsResponse> albumResponse = makeAlbumRequest(albumUri);
    for (SmugMugAlbum album : albumResponse.getResponse().getAlbums()) {
        albums.add(new PhotoAlbum(album.getAlbumKey(), album.getTitle(), album.getDescription()));
        resources.add(new IdOnlyResource(album.getAlbumKey()));
    }
    StringPaginationToken pageToken = null;
    if (albumResponse.getResponse().getPageInfo() != null && albumResponse.getResponse().getPageInfo().getNextPage() != null) {
        pageToken = new StringPaginationToken(albumResponse.getResponse().getPageInfo().getNextPage());
    }
    return new PhotosModelWrapper(albums, null, new ContinuationInformation(resources, pageToken));
}
Also used : SmugMugUserResponse(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugUserResponse) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) SmugmugAlbumsResponse(org.dataportabilityproject.serviceProviders.smugmug.model.SmugmugAlbumsResponse) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) SmugMugAlbum(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbum) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 3 with PhotosModelWrapper

use of org.dataportabilityproject.dataModels.photos.PhotosModelWrapper 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)

Example 4 with PhotosModelWrapper

use of org.dataportabilityproject.dataModels.photos.PhotosModelWrapper in project data-transfer-project by google.

the class InstagramPhotoService method export.

@Override
public PhotosModelWrapper export(ExportInformation exportInformation) throws IOException {
    MediaResponse response = makeRequest("https://api.instagram.com/v1/users/self/media/recent", MediaResponse.class);
    List<PhotoModel> photos = new ArrayList<>();
    // TODO: check out paging.
    for (MediaFeedData photo : response.getData()) {
        // TODO json mapping is broken.
        String photoId = photo.getId();
        String url = photo.getImages().getStandardResolution().getUrl();
        String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null;
        photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, FAKE_ALBUM_ID));
    }
    List<PhotoAlbum> albums = new ArrayList<>();
    if (!photos.isEmpty() && !exportInformation.getPaginationInformation().isPresent()) {
        albums.add(new PhotoAlbum(FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram"));
    }
    return new PhotosModelWrapper(albums, photos, null);
}
Also used : MediaResponse(org.dataportabilityproject.serviceProviders.instagram.model.MediaResponse) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) MediaFeedData(org.dataportabilityproject.serviceProviders.instagram.model.MediaFeedData) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum)

Example 5 with PhotosModelWrapper

use of org.dataportabilityproject.dataModels.photos.PhotosModelWrapper in project data-transfer-project by google.

the class FlickrPhotoService method getAlbums.

private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
    try {
        ImmutableList.Builder<PhotoAlbum> results = ImmutableList.builder();
        List<IdOnlyResource> subResources = new ArrayList<>();
        int page = getPage(paginationInformation);
        Photosets photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
        for (Photoset photoset : photoSetList.getPhotosets()) {
            // Saving data to the album allows the target service
            // to recreate the album structure.
            results.add(new PhotoAlbum(photoset.getId(), photoset.getTitle(), photoset.getDescription()));
            // Adding sub-resources tells the framework to re-call
            // export to get all the photos.
            subResources.add(new IdOnlyResource(photoset.getId()));
        }
        FlickrPaginationInformation newPage = null;
        boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
        if (hasMore) {
            newPage = new FlickrPaginationInformation(page + 1);
        }
        return new PhotosModelWrapper(results.build(), null, new ContinuationInformation(subResources, newPage));
    } catch (FlickrException e) {
        throw new IOException("Couldn't fetch albums", e);
    }
}
Also used : FlickrException(com.flickr4java.flickr.FlickrException) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IOException(java.io.IOException) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum)

Aggregations

PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)10 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)8 ArrayList (java.util.ArrayList)7 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)6 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)6 IOException (java.io.IOException)5 Photoset (com.flickr4java.flickr.photosets.Photoset)4 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)4 Photosets (com.flickr4java.flickr.photosets.Photosets)3 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)3 Resource (org.dataportabilityproject.dataModels.Resource)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 FlickrException (com.flickr4java.flickr.FlickrException)2 Photo (com.flickr4java.flickr.photos.Photo)2 PhotoList (com.flickr4java.flickr.photos.PhotoList)2 UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)2 ImmutableList (com.google.common.collect.ImmutableList)2 GphotoEntry (com.google.gdata.data.photos.GphotoEntry)2 ServiceException (com.google.gdata.util.ServiceException)2