use of org.dataportabilityproject.dataModels.photos.PhotoModel 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);
}
}
}
use of org.dataportabilityproject.dataModels.photos.PhotoModel 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));
}
use of org.dataportabilityproject.dataModels.photos.PhotoModel in project data-transfer-project by google.
the class FlickrPhotoServiceTest method toCommonPhoto.
@Test
public void toCommonPhoto() {
Photo photo = initializePhoto(PHOTO_TITLE, FETCHABLE_URL, PHOTO_DESCRIPTION);
PhotoModel photoModel = FlickrPhotoService.toCommonPhoto(photo, ALBUM_ID);
assertThat(photoModel.getAlbumId()).isEqualTo(ALBUM_ID);
assertThat(photoModel.getFetchableUrl()).isEqualTo(FETCHABLE_URL);
assertThat(photoModel.getTitle()).isEqualTo(PHOTO_TITLE);
assertThat(photoModel.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
assertThat(photoModel.getMediaType()).isEqualTo("image/jpeg");
}
use of org.dataportabilityproject.dataModels.photos.PhotoModel 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);
}
}
use of org.dataportabilityproject.dataModels.photos.PhotoModel 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);
}
Aggregations