Search in sources :

Example 16 with VideoModel

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

the class GoogleVideosImporterTest method failOneVideo.

@Test
public void failOneVideo() 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.INVALID_ARGUMENT_VALUE).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 one files of 32L.", 32L, length);
    assertEquals("Expected executor to have one error.", 1, executor.getErrors().size());
    ErrorDetail errorDetail = executor.getErrors().iterator().next();
    assertEquals("myId2", errorDetail.id());
    assertThat(errorDetail.exception(), CoreMatchers.containsString("Video item could not be created."));
}
Also used : ErrorDetail(org.datatransferproject.types.transfer.errors.ErrorDetail) 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 17 with VideoModel

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

the class KoofrMediaExport method processVideo.

protected void processVideo(FilesFile file, String path, String albumId) {
    String videoId = path;
    String name = getFileName(file);
    String description = getFileDescription(file);
    String contentType = file.getContentType();
    String fullPath = rootPath + path;
    albumsWithVideos.add(albumId);
    VideoObjectContainer container = new VideoObjectContainer();
    container.videoModel = new VideoModel(name, "", description, contentType, videoId, albumId, false);
    container.fullPath = fullPath;
    videos.add(container);
}
Also used : VideoModel(org.datatransferproject.types.common.models.videos.VideoModel)

Example 18 with VideoModel

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

the class KoofrMediaExport method getVideos.

public List<VideoModel> getVideos() throws IOException, InvalidTokenException {
    ArrayList<VideoModel> exportVideos = new ArrayList<>();
    for (VideoObjectContainer container : videos) {
        VideoModel video = container.videoModel;
        String fetchableUrl = getFetchableUrl(container.fullPath);
        if (fetchableUrl == null) {
            continue;
        }
        exportVideos.add(new VideoModel(video.getName(), fetchableUrl, video.getDescription(), video.getEncodingFormat(), video.getDataId(), video.getAlbumId(), video.isInTempStore()));
    }
    return exportVideos;
}
Also used : ArrayList(java.util.ArrayList) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel)

Example 19 with VideoModel

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

the class KoofrVideosExporter method export.

@Override
public ExportResult<VideosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws CopyExceptionWithFailureReason {
    Preconditions.checkNotNull(authData);
    KoofrClient koofrClient = koofrClientFactory.create(authData);
    KoofrMediaExport export = new KoofrMediaExport(koofrClient, monitor);
    try {
        export.export();
        List<VideoAlbum> exportAlbums = export.getVideoAlbums();
        List<VideoModel> exportVideos = export.getVideos();
        VideosContainerResource containerResource = new VideosContainerResource(exportAlbums, exportVideos);
        return new ExportResult<>(ExportResult.ResultType.END, containerResource, null);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
}
Also used : VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) IOException(java.io.IOException) VideoAlbum(org.datatransferproject.types.common.models.videos.VideoAlbum) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) KoofrMediaExport(org.datatransferproject.transfer.koofr.common.KoofrMediaExport) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 20 with VideoModel

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

the class FacebookVideosExporterTest method testExportVideo.

@Test
public void testExportVideo() throws CopyExceptionWithFailureReason {
    ExportResult<VideosContainerResource> result = facebookVideosExporter.export(uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of(new ExportInformation(null, null)));
    assertEquals(ExportResult.ResultType.END, result.getType());
    VideosContainerResource exportedData = result.getExportedData();
    assertEquals(1, exportedData.getVideos().size());
    assertEquals(new VideoModel(VIDEO_ID + ".mp4", VIDEO_SOURCE, VIDEO_NAME, "video/mp4", VIDEO_ID, null, false), exportedData.getVideos().toArray()[0]);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) 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