Search in sources :

Example 1 with VideosContainerResource

use of org.datatransferproject.types.common.models.videos.VideosContainerResource 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 VideosContainerResource

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

the class BackblazeVideosImporterTest method testNullVideos.

@Test
public void testNullVideos() throws Exception {
    VideosContainerResource data = mock(VideosContainerResource.class);
    when(data.getVideos()).thenReturn(null);
    BackblazeVideosImporter sut = new BackblazeVideosImporter(monitor, dataStore, streamProvider, clientFactory);
    ImportResult result = sut.importItem(UUID.randomUUID(), executor, authData, data);
    assertEquals(ImportResult.OK, result);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) Test(org.junit.Test)

Example 3 with VideosContainerResource

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

the class KoofrVideosExporterTest method testExport.

@Test
public void testExport() throws Exception {
    when(client.getRootPath()).thenReturn("/Data transfer");
    when(client.listRecursive("/Data transfer")).thenReturn(Fixtures.listRecursiveItems);
    when(client.fileLink("/Data transfer/Album 2 :heart:/Video 1.mp4")).thenReturn("https://app-1.koofr.net/content/files/get/Video+1.mp4?base=TESTBASE");
    when(client.fileLink("/Data transfer/Videos/Video 2.mp4")).thenReturn("https://app-1.koofr.net/content/files/get/Video+2.mp4?base=TESTBASE");
    UUID jobId = UUID.randomUUID();
    ExportResult<VideosContainerResource> result = exporter.export(jobId, authData, Optional.empty());
    assertEquals(ExportResult.ResultType.END, result.getType());
    assertNull(result.getContinuationData());
    VideosContainerResource exportedData = result.getExportedData();
    List<VideoAlbum> expectedAlbums = ImmutableList.of(new VideoAlbum("/Album 2 :heart:", "Album 2 ❤️", "Album 2 description ❤️"), new VideoAlbum("/Videos", "Videos", null));
    assertEquals(expectedAlbums, exportedData.getAlbums());
    List<VideoModel> expectedVideos = ImmutableList.of(new VideoModel("Video 1.mp4", "https://app-1.koofr.net/content/files/get/Video+1.mp4?base=TESTBASE", null, "video/mp4", "/Album 2 :heart:/Video 1.mp4", "/Album 2 :heart:", false), new VideoModel("Video 2.mp4", "https://app-1.koofr.net/content/files/get/Video+2.mp4?base=TESTBASE", "Video 3 description", "video/mp4", "/Videos/Video 2.mp4", "/Videos", false));
    assertEquals(expectedVideos, exportedData.getVideos());
}
Also used : VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) UUID(java.util.UUID) VideoAlbum(org.datatransferproject.types.common.models.videos.VideoAlbum) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Example 4 with VideosContainerResource

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

the class GoogleVideosExporterTest method exportSingleVideo.

@Test
public void exportSingleVideo() throws IOException {
    when(albumListResponse.getNextPageToken()).thenReturn(null);
    GoogleMediaItem mediaItem = setUpSingleVideo(VIDEO_URI, VIDEO_ID);
    when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { mediaItem });
    when(mediaItemSearchResponse.getNextPageToken()).thenReturn(VIDEO_TOKEN);
    // Run test
    ExportResult<VideosContainerResource> result = googleVideosExporter.exportVideos(null, Optional.empty());
    // Verify correct methods were called
    verify(videosInterface).listVideoItems(Optional.empty());
    verify(mediaItemSearchResponse).getMediaItems();
    // Check pagination
    ContinuationData continuationData = result.getContinuationData();
    StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken.getToken()).isEqualTo(VIDEO_TOKEN);
    // Check videos field of container
    Collection<VideoModel> actualVideos = result.getExportedData().getVideos();
    URI video_uri_object = null;
    try {
        video_uri_object = new URI(VIDEO_URI + "=dv");
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    assertThat(actualVideos.stream().map(VideoModel::getContentUrl).collect(Collectors.toList())).containsExactly(video_uri_object);
    // Since albums are not supported atm, this should be null
    assertThat(actualVideos.stream().map(VideoModel::getAlbumId).collect(Collectors.toList())).containsExactly((Object) null);
}
Also used : VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) URISyntaxException(java.net.URISyntaxException) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) URI(java.net.URI) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 5 with VideosContainerResource

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

the class KoofrVideosImporterTest method testImportItemFromURLWithAlbum.

@Test
public void testImportItemFromURLWithAlbum() throws Exception {
    server.enqueue(new MockResponse().setResponseCode(200).setBody("123"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("4567"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("89"));
    when(client.ensureRootFolder()).thenReturn("/root");
    when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");
    when(executor.getCachedValue(eq("id2"))).thenReturn("/root/Album");
    when(client.fileExists("/root/Album 1/video1.mp4")).thenReturn(false);
    when(client.fileExists("/root/Album 1/video2.mp4")).thenReturn(true);
    when(client.fileExists("/root/Album/video3.mp4")).thenReturn(false);
    String description1000 = new String(new char[1000]).replace("\0", "a");
    String description1001 = new String(new char[1001]).replace("\0", "a");
    UUID jobId = UUID.randomUUID();
    Collection<VideoAlbum> albums = ImmutableList.of(new VideoAlbum("id1", "Album 1", "This is a fake album"), new VideoAlbum("id2", "", description1001));
    Collection<VideoModel> videos = ImmutableList.of(new VideoModel("video1.mp4", server.url("/1.mp4").toString(), "A video 1", "video/mp4", "video1", "id1", false), new VideoModel("video2.mp4", server.url("/2.mp4").toString(), "A video 2", "video/mp4", "video2", "id1", false), new VideoModel("video3.mp4", server.url("/3.mp4").toString(), description1001, "video/mp4", "video3", "id2", false));
    VideosContainerResource resource = spy(new VideosContainerResource(albums, videos));
    importer.importItem(jobId, executor, authData, resource);
    InOrder clientInOrder = Mockito.inOrder(client);
    clientInOrder.verify(client).ensureRootFolder();
    clientInOrder.verify(client).ensureFolder("/root", "Album 1");
    clientInOrder.verify(client).addDescription("/root/Album 1", "This is a fake album");
    clientInOrder.verify(client).ensureFolder("/root", "Album");
    clientInOrder.verify(client).addDescription("/root/Album", description1000);
    clientInOrder.verify(client).fileExists(eq("/root/Album 1/video1.mp4"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("video1.mp4"), any(), eq("video/mp4"), isNull(), eq("A video 1"));
    clientInOrder.verify(client).fileExists(eq("/root/Album 1/video2.mp4"));
    clientInOrder.verify(client).fileExists(eq("/root/Album/video3.mp4"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album"), eq("video3.mp4"), any(), eq("video/mp4"), isNull(), eq(description1000));
    clientInOrder.verifyNoMoreInteractions();
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) InOrder(org.mockito.InOrder) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) UUID(java.util.UUID) VideoAlbum(org.datatransferproject.types.common.models.videos.VideoAlbum) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) Test(org.junit.Test)

Aggregations

VideosContainerResource (org.datatransferproject.types.common.models.videos.VideosContainerResource)13 VideoModel (org.datatransferproject.types.common.models.videos.VideoModel)11 Test (org.junit.Test)9 UUID (java.util.UUID)6 VideoAlbum (org.datatransferproject.types.common.models.videos.VideoAlbum)5 ArrayList (java.util.ArrayList)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)3 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)3 InOrder (org.mockito.InOrder)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)2 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)2 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)2 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)1 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 AccessToken (com.google.auth.oauth2.AccessToken)1 UserCredentials (com.google.auth.oauth2.UserCredentials)1 Preconditions (com.google.common.base.Preconditions)1