use of com.google.gdata.data.MediaContent 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());
}
}
use of com.google.gdata.data.MediaContent 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 com.google.gdata.data.MediaContent in project jbehave-core by jbehave.
the class LoadOdtFromGoogle method mediaContent.
MediaContent mediaContent(String url) {
MediaContent mc = new MediaContent();
mc.setUri(url);
return mc;
}
use of com.google.gdata.data.MediaContent in project jbehave-core by jbehave.
the class GoogleOdtLoaderBehaviour method shouldGetResourceFromDocsService.
@Test
public void shouldGetResourceFromDocsService() throws IOException, ServiceException {
DocsService service = mock(DocsService.class);
DocumentListFeed feed = mock(DocumentListFeed.class);
DocumentListEntry entry = mock(DocumentListEntry.class);
MediaSource mediaSource = mock(MediaSource.class);
InputStream inputStream = mock(InputStream.class);
final MediaContent content = mock(MediaContent.class);
final DocumentQuery query = mock(DocumentQuery.class);
when(service.getFeed(query, DocumentListFeed.class)).thenReturn(feed);
when(service.getMedia(content)).thenReturn(mediaSource);
when(feed.getEntries()).thenReturn(asList(entry));
when(entry.getContent()).thenReturn(content);
when(content.getUri()).thenReturn("http://docs.google.com");
when(mediaSource.getInputStream()).thenReturn(inputStream);
LoadOdtFromGoogle storyLoader = new LoadOdtFromGoogle("user", "password", "https://docs.google.com/feeds/default/private/full/", service) {
@Override
DocumentQuery documentQuery(String title) throws MalformedURLException {
return query;
}
@Override
protected MediaContent mediaContent(String url) {
return content;
}
};
InputStream resourceStream = storyLoader.resourceAsStream("a_story");
MatcherAssert.assertThat(resourceStream, Matchers.equalTo(inputStream));
}
Aggregations