Search in sources :

Example 1 with VideoModel

use of org.datatransferproject.types.common.models.videos.VideoModel in project data-transfer-project by google.

the class FacebookVideosExporter method exportVideos.

private ExportResult<VideosContainerResource> exportVideos(TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) throws CopyExceptionWithFailureReason {
    Optional<String> paginationToken = paginationData.map(StringPaginationToken::getToken);
    try {
        Connection<Video> videoConnection = getOrCreateVideosInterface(authData).getVideos(paginationToken);
        List<Video> videos = videoConnection.getData();
        if (videos.isEmpty()) {
            return new ExportResult<>(ExportResult.ResultType.END, null);
        }
        ArrayList<VideoModel> exportVideos = new ArrayList<>();
        for (Video video : videos) {
            final String url = video.getSource();
            final String fbid = video.getId();
            if (null == url || url.isEmpty()) {
                monitor.severe(() -> String.format("Source was missing or empty for video %s", fbid));
                continue;
            }
            exportVideos.add(new VideoModel(String.format("%s.mp4", fbid), url, video.getDescription(), "video/mp4", fbid, null, false));
        }
        String token = videoConnection.getAfterCursor();
        if (Strings.isNullOrEmpty(token)) {
            return new ExportResult<>(ExportResult.ResultType.END, new VideosContainerResource(null, exportVideos));
        } else {
            PaginationData nextPageData = new StringPaginationToken(token);
            ContinuationData continuationData = new ContinuationData(nextPageData);
            return new ExportResult<>(ExportResult.ResultType.CONTINUE, new VideosContainerResource(null, exportVideos), continuationData);
        }
    } catch (FacebookGraphException e) {
        String message = e.getMessage();
        // In such case, we should skip this object and continue with the rest of the transfer.
        if (message != null && message.contains("code 100, subcode 33")) {
            monitor.info(() -> "Cannot find videos to export, skipping to the next bunch", e);
            return new ExportResult<>(ExportResult.ResultType.END, null);
        }
        throw e;
    }
}
Also used : PaginationData(org.datatransferproject.types.common.PaginationData) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Video(com.restfb.types.Video) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) FacebookGraphException(com.restfb.exception.FacebookGraphException) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 2 with VideoModel

use of org.datatransferproject.types.common.models.videos.VideoModel in project data-transfer-project by google.

the class GoogleVideosImporterTest method descriptionOver1kCharactersShouldNotFail.

@Test
public void descriptionOver1kCharactersShouldNotFail() {
    // Mock creation response
    String videoDescriptionOver1k = "z0pyiaeQ03C7Pfs7qdoWfpR2E4BjqqLvsEL1OdBaQu8PeoI5uca83NJQKOfF4gnAhzvpgtbAPGBUade" + "FH5i4vas067Q67aDg1JA9qnnMEy5TTS7Qrp0MImGAI4aHFINwDrTOlFnyGoOwtQC6LLbWWlM8m224G1C08oEyjxuWicMXIdsJfsQvbE" + "dropW0jOMmO2DTCDCPRKwONGHPpo48pmi8HbtNolrbnU189mhyi4zSK3xmMAgmxQWOMmuNryXWB0Zok8hDxnxIes85Oe853U3jUxdu6" + "wNwkbZcpb97dj3puh6UYO9YFFsU40F2ULzpvPTvAPvDeBeOENpUjuh9YhPQiMbwLqne2AxLgMDgxz473Ho2DosixcWjSmX6JfSxInXh" + "lmXxN6xLJRi2abHeEpbOdvl28xEYpBF73DuZZ7NKPKyKhEcWi7aJVoWp9niBl0Cp4PCOO51ABROXOzE8dcoxf6dU1fhqkcQcuxV1qeK" + "XfYewxh8uZeShaMoey1rwzuux7lnKoHDGVQe1nJwSuTUNE5BgLa3uOSwQ9wG0tuakZF2M2YIMhEF6DUu7mZfN41fwPFleuwzO76C6eD" + "inP3xlNJzhsQjQtL0ITCf2oL6LgqLNxzHIRpY41d1Puxzyx2wWJ7DJy3UnMlylyEwhNkd8EuuyXYCs6GIzUXkvHRQZjN99ED6gkmnHS" + "SIW0QHBWOb4jHSYpK52OVMIsLkwRll8zNWci7rRXxFeMw0s0sFcIZthajvP7PMA361bNUDQe4vVhsxF1AQufm0D2SYGpA4zH8LOsacl" + "QPP2vKFFED90jUvbqkhesYYGvrvSq0t12LoMTFqkckRbxj7tODIUco9FFf9U5MQV40q6jgrKup19BSR9NUI58Y0GpI5ZqPgSaNhoJ5V" + "vsPhjrywUo6s9oOnolihQYq6lXZzwhESS8diG34oFLEwq9msSsrRtUSjgH50mNGogOlgEtbaFlMgXstzOWtUk2CwFEHZ9Y2qv123456" + "7890";
    final VideoModel videoModel = new VideoModel(VIDEO_TITLE, VIDEO_URI, videoDescriptionOver1k, MP4_MEDIA_TYPE, VIDEO_ID, null, false);
    String uploadToken = "token";
    NewMediaItem newMediaItemResult = googleVideosImporter.buildMediaItem(videoModel, uploadToken);
    assertFalse("Expected the length of the description to be truncated to 1000 chars.", (newMediaItemResult.getDescription().length() > 1000));
    assertTrue("Expected a truncated description to terminate with \"...\"", newMediaItemResult.getDescription().endsWith("..."));
}
Also used : NewMediaItem(com.google.photos.library.v1.proto.NewMediaItem) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Example 3 with VideoModel

use of org.datatransferproject.types.common.models.videos.VideoModel in project data-transfer-project by google.

the class GoogleVideosImporterTest method importTwoVideos.

@Test
public void importTwoVideos() throws Exception {
    PhotosLibraryClient photosLibraryClient = mock(PhotosLibraryClient.class);
    // Mock uploads
    when(photosLibraryClient.uploadMediaItem(any())).thenReturn(UploadMediaItemResponse.newBuilder().setUploadToken("token1").build(), UploadMediaItemResponse.newBuilder().setUploadToken("token2").build());
    // Mock creation response
    final NewMediaItemResult newMediaItemResult = NewMediaItemResult.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build()).setMediaItem(MediaItem.newBuilder().setId("RESULT_ID_1").build()).setUploadToken("token1").build();
    final NewMediaItemResult newMediaItemResult2 = NewMediaItemResult.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build()).setMediaItem(MediaItem.newBuilder().setId("RESULT_ID_2").build()).setUploadToken("token2").build();
    BatchCreateMediaItemsResponse response = BatchCreateMediaItemsResponse.newBuilder().addNewMediaItemResults(newMediaItemResult).addNewMediaItemResults(newMediaItemResult2).build();
    when(photosLibraryClient.batchCreateMediaItems(ArgumentMatchers.anyList())).thenReturn(response);
    InMemoryIdempotentImportExecutor executor = new InMemoryIdempotentImportExecutor(mock(Monitor.class));
    long length = googleVideosImporter.importVideoBatch(Lists.newArrayList(new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, VIDEO_ID, null, false), new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, "myId2", null, false)), photosLibraryClient, executor);
    assertEquals("Expected the number of bytes to be the two files of 32L.", 64L, length);
    assertEquals("Expected executor to have no errors.", 0, executor.getErrors().size());
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) NewMediaItemResult(com.google.photos.library.v1.proto.NewMediaItemResult) BatchCreateMediaItemsResponse(com.google.photos.library.v1.proto.BatchCreateMediaItemsResponse) InMemoryIdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor) PhotosLibraryClient(com.google.photos.library.v1.PhotosLibraryClient) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Example 4 with VideoModel

use of org.datatransferproject.types.common.models.videos.VideoModel in project data-transfer-project by google.

the class GoogleVideosImporterTest method skipNotFoundVideo.

@Test
public void skipNotFoundVideo() throws Exception {
    PhotosLibraryClient photosLibraryClient = mock(PhotosLibraryClient.class);
    HttpURLConnection httpURLConnection = mock(HttpURLConnection.class);
    when(httpURLConnection.getInputStream()).thenThrow(new FileNotFoundException());
    when(streamProvider.getConnection(any())).thenReturn(httpURLConnection);
    InMemoryIdempotentImportExecutor executor = new InMemoryIdempotentImportExecutor(mock(Monitor.class));
    long length = googleVideosImporter.importVideoBatch(Lists.newArrayList(new VideoModel(VIDEO_TITLE, VIDEO_URI, VIDEO_DESCRIPTION, MP4_MEDIA_TYPE, VIDEO_ID, null, false)), photosLibraryClient, executor);
    assertEquals("Expected the number of bytes to be 0L.", 0L, length);
    assertEquals("Expected executor to have no errors.", 0, executor.getErrors().size());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Monitor(org.datatransferproject.api.launcher.Monitor) FileNotFoundException(java.io.FileNotFoundException) InMemoryIdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor) PhotosLibraryClient(com.google.photos.library.v1.PhotosLibraryClient) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Example 5 with VideoModel

use of org.datatransferproject.types.common.models.videos.VideoModel in project data-transfer-project by google.

the class FacebookVideosImporterTest method testImportSingleVideo.

@Test
public void testImportSingleVideo() {
    importer.importSingleVideo(client, new VideoModel("title", VIDEO_URL, VIDEO_DESCRIPTION, "video/mp4", "videoId", null, false));
    Parameter[] params = { Parameter.with("file_url", VIDEO_URL), Parameter.with("description", VIDEO_DESCRIPTION) };
    verify(client).publish("me/videos", GraphResponse.class, params);
}
Also used : Parameter(com.restfb.Parameter) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Aggregations

VideoModel (org.datatransferproject.types.common.models.videos.VideoModel)21 Test (org.junit.Test)12 VideosContainerResource (org.datatransferproject.types.common.models.videos.VideosContainerResource)11 UUID (java.util.UUID)6 VideoAlbum (org.datatransferproject.types.common.models.videos.VideoAlbum)6 ArrayList (java.util.ArrayList)5 PhotosLibraryClient (com.google.photos.library.v1.PhotosLibraryClient)4 BatchCreateMediaItemsResponse (com.google.photos.library.v1.proto.BatchCreateMediaItemsResponse)4 NewMediaItemResult (com.google.photos.library.v1.proto.NewMediaItemResult)4 Monitor (org.datatransferproject.api.launcher.Monitor)4 NewMediaItem (com.google.photos.library.v1.proto.NewMediaItem)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)3 InOrder (org.mockito.InOrder)3 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Status (com.google.rpc.Status)2 HttpURLConnection (java.net.HttpURLConnection)2