Search in sources :

Example 1 with Video

use of com.restfb.types.Video 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 Video

use of com.restfb.types.Video in project data-transfer-project by google.

the class FacebookVideosExporterTest method setUp.

@Before
public void setUp() throws CopyExceptionWithFailureReason {
    FacebookVideosInterface videosInterface = mock(FacebookVideosInterface.class);
    // Set up example video
    Video video = new Video();
    video.setId(VIDEO_ID);
    video.setSource(VIDEO_SOURCE);
    video.setDescription(VIDEO_NAME);
    ArrayList<Video> videos = new ArrayList<>();
    videos.add(video);
    @SuppressWarnings("unchecked") Connection<Video> videoConnection = mock(Connection.class);
    when(videosInterface.getVideos(Optional.empty())).thenReturn(videoConnection);
    when(videoConnection.getData()).thenReturn(videos);
    facebookVideosExporter = new FacebookVideosExporter(new AppCredentials("key", "secret"), videosInterface, null);
}
Also used : AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) Video(com.restfb.types.Video) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Aggregations

Video (com.restfb.types.Video)2 ArrayList (java.util.ArrayList)2 FacebookGraphException (com.restfb.exception.FacebookGraphException)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)1 PaginationData (org.datatransferproject.types.common.PaginationData)1 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)1 VideoModel (org.datatransferproject.types.common.models.videos.VideoModel)1 VideosContainerResource (org.datatransferproject.types.common.models.videos.VideosContainerResource)1 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)1 Before (org.junit.Before)1