Find All Videos

Technology
Media API
Required
Media API token
Edition
Express 499, Pro, Enterprise

How do you find all videos in the Brightcove system?

It's a common use case, and yet not quite as straight forward as one would think.

If PHP is your language of choice, the PHP Media API Wrapper contains a findAll convenience method which does this for you.

If Java is your language of choice, I strongly recommend downloading the open source SDK:
http://bc-j-mapi-w.sourceforge.net/

And the code for the Java SDK:

        ReadApi readApi = new ReadApi();
        Long retryDelayMs = 2000;
        int maxRetries = 10;
        readApi.SetQueryRetry(new QueryRetry(maxRetries, retryDelayMs,Logger.getAnonymousLogger()));
        int pageSize = 100;
        long totalPages = 0;
        Set<VideoStateFilterEnum> states = VideoStateFilterEnum.CreateEmptySet();
        states.add(VideoStateFilterEnum.INACTIVE);
        states.add(VideoStateFilterEnum.PLAYABLE);
        states.add(VideoStateFilterEnum.UNSCHEDULED);
        List<Video> allVideos = new ArrayList<Video>();
        for (int i = 0; i <= totalPages; i++) {
            List<Video> videos = readApi.FindModifiedVideos(readToken, new Long(0), states, pageSize, i, SortByTypeEnum.MODIFIED_DATE, SortOrderTypeEnum.ASC, videoFields, customFields);
            long totalCount = readApi.getLastCallTotalCount();
            totalPages = totalCount / pageSize;
            allVideos.addAll(videos);
        }
        return allVideos;    

Notice first the QueryRetry class.  This is a feature of the Java SDK to help assist with the query timeout errors (code 103).      

        readApi.SetQueryRetry(new QueryRetry(maxRetries, retryDelayMs,Logger.getAnonymousLogger()));
    

Next, notice FindModifiedVideos. We use FindModifiedVideos, instead of the common FindAllVideos, because FindAllVideos will not return inactive or non-currently scheduled videos.  Our from_date for FindModifiedVideos is 0.

Also, you may wonder why we recalculate the totalPages per each API call.  This ensures we will retrieve any new videos that were added during the processing of the code.

And that's it!