Search in sources :

Example 1 with PhotoAlbum

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

the class GooglePhotosService method importItem.

@Override
public void importItem(PhotosModelWrapper wrapper) throws IOException {
    for (PhotoAlbum album : wrapper.getAlbums()) {
        if (true) {
            // Google doesn't support creating albums anymore
            continue;
        }
        AlbumEntry myAlbum = new AlbumEntry();
        myAlbum.setTitle(new PlainTextConstruct("copy of " + album.getName()));
        myAlbum.setDescription(new PlainTextConstruct(album.getDescription()));
        URL albumUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default");
        AlbumEntry insertedEntry;
        try {
            // https://developers.google.com/picasa-web/docs/2.0/developers_guide_java#AddAlbums
            insertedEntry = service.insert(albumUrl, myAlbum);
            jobDataCache.store(album.getId(), insertedEntry.getGphotoId());
        } catch (ServiceException e) {
            throw new IOException("Problem copying" + album.getName() + " request to: " + albumUrl, e);
        }
    }
    for (PhotoModel photo : wrapper.getPhotos()) {
        // String newAlbumId = jobDataCache.getData(photo.getAlbumId(), String.class);
        String newAlbumId = "default";
        URL photoPostUrl = new URL("https://picasaweb.google.com/data/feed/api/user/default/albumid/" + newAlbumId);
        PhotoEntry myPhoto = new PhotoEntry();
        myPhoto.setTitle(new PlainTextConstruct("copy of " + photo.getTitle()));
        myPhoto.setDescription(new PlainTextConstruct(photo.getDescription()));
        myPhoto.setClient(CLIENT_NAME);
        String mediaType = photo.getMediaType();
        if (mediaType == null) {
            mediaType = "image/jpeg";
        }
        MediaStreamSource streamSource = new MediaStreamSource(getImageAsStream(photo.getFetchableUrl()), mediaType);
        myPhoto.setMediaSource(streamSource);
        try {
            service.insert(photoPostUrl, myPhoto);
        } catch (ServiceException e) {
            throw new IOException("Problem adding " + photo.getTitle() + " to " + newAlbumId, e);
        }
    }
}
Also used : AlbumEntry(com.google.gdata.data.photos.AlbumEntry) ServiceException(com.google.gdata.util.ServiceException) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) IOException(java.io.IOException) MediaStreamSource(com.google.gdata.data.media.MediaStreamSource) PlainTextConstruct(com.google.gdata.data.PlainTextConstruct) URL(java.net.URL) PhotoEntry(com.google.gdata.data.photos.PhotoEntry)

Example 2 with PhotoAlbum

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

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

the class SmugMugPhotoService method importItem.

@Override
public void importItem(PhotosModelWrapper wrapper) throws IOException {
    String folder = null;
    if (!wrapper.getAlbums().isEmpty()) {
        SmugMugResponse<SmugMugUserResponse> userResponse = makeUserRequest(USER_URL);
        folder = userResponse.getResponse().getUser().getUris().get("Folder").getUri();
    }
    for (PhotoAlbum album : wrapper.getAlbums()) {
        createAlbum(folder, album);
    }
    for (PhotoModel photo : wrapper.getPhotos()) {
        uploadPhoto(photo);
    }
}
Also used : SmugMugUserResponse(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugUserResponse) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum)

Example 4 with PhotoAlbum

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

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

Aggregations

PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)8 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)4 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)4 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)4 Photoset (com.flickr4java.flickr.photosets.Photoset)3 FlickrException (com.flickr4java.flickr.FlickrException)2 Photosets (com.flickr4java.flickr.photosets.Photosets)2 ServiceException (com.google.gdata.util.ServiceException)2 URL (java.net.URL)2 Resource (org.dataportabilityproject.dataModels.Resource)2 SmugMugUserResponse (org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugUserResponse)2 ImmutableList (com.google.common.collect.ImmutableList)1 PlainTextConstruct (com.google.gdata.data.PlainTextConstruct)1 MediaStreamSource (com.google.gdata.data.media.MediaStreamSource)1 AlbumEntry (com.google.gdata.data.photos.AlbumEntry)1 GphotoEntry (com.google.gdata.data.photos.GphotoEntry)1 PhotoEntry (com.google.gdata.data.photos.PhotoEntry)1