Search in sources :

Example 1 with MediaStreamSource

use of com.google.gdata.data.media.MediaStreamSource 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 MediaStreamSource

use of com.google.gdata.data.media.MediaStreamSource in project data-transfer-project by google.

the class GooglePhotosImporter method importSinglePhoto.

@VisibleForTesting
void importSinglePhoto(UUID jobId, TokensAndUrlAuthData authData, PhotoModel inputPhoto) throws IOException, ServiceException {
    // Set up photo
    PhotoEntry outputPhoto = new PhotoEntry();
    outputPhoto.setTitle(new PlainTextConstruct("copy of " + inputPhoto.getTitle()));
    outputPhoto.setDescription(new PlainTextConstruct(inputPhoto.getDescription()));
    outputPhoto.setClient(GoogleStaticObjects.APP_NAME);
    String mediaType = inputPhoto.getMediaType();
    if (mediaType == null) {
        mediaType = "image/jpeg";
    }
    MediaStreamSource streamSource = new MediaStreamSource(getImageAsStream(inputPhoto.getFetchableUrl()), mediaType);
    outputPhoto.setMediaSource(streamSource);
    // Find album to upload photo to
    String albumId = jobStore.findData(TempPhotosData.class, jobId).lookupNewAlbumId(inputPhoto.getAlbumId());
    URL uploadUrl = new URL(String.format(PHOTO_POST_URL_FORMATTER, albumId));
    // Upload photo
    getOrCreatePhotosService(authData).insert(uploadUrl, outputPhoto);
}
Also used : TempPhotosData(org.dataportabilityproject.spi.transfer.types.TempPhotosData) MediaStreamSource(com.google.gdata.data.media.MediaStreamSource) PlainTextConstruct(com.google.gdata.data.PlainTextConstruct) URL(java.net.URL) PhotoEntry(com.google.gdata.data.photos.PhotoEntry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

PlainTextConstruct (com.google.gdata.data.PlainTextConstruct)2 MediaStreamSource (com.google.gdata.data.media.MediaStreamSource)2 PhotoEntry (com.google.gdata.data.photos.PhotoEntry)2 URL (java.net.URL)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AlbumEntry (com.google.gdata.data.photos.AlbumEntry)1 ServiceException (com.google.gdata.util.ServiceException)1 IOException (java.io.IOException)1 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)1 PhotoModel (org.dataportabilityproject.dataModels.photos.PhotoModel)1 TempPhotosData (org.dataportabilityproject.spi.transfer.types.TempPhotosData)1