Locating specific media assets can be challenging when your library contains many audio, video, and image files. ApsaraVideo VOD (VOD) provides a powerful media search feature that lets you search, filter, and sort assets across multiple dimensions. You can use the console or an API or SDK to efficiently and accurately retrieve the media assets you need from large datasets.
Scenario 1: Search using the console
To search for audio or video information, follow these steps:
Log on to the ApsaraVideo VOD console.
In the left navigation pane, choose Media Files > Audio/Video to go to the Audio/Video management page.
Use the filter and search features at the top of the page to locate media assets.

Search: Supports fuzzy search for Video Title and exact match for Media ID and Tag Name.
Filter: Supports filtering audio and video files by Address, Type, Category, Status, Source, and Storage Class. You can also sort the results by Created At in ascending or descending order.
Scenario 2: Search for media assets using an API or SDK
Use a server-side software development kit (SDK) to call the API to search for media asset information. For more information, see VOD SDKs.
Use the SearchMedia operation to integrate search capabilities into your business systems and automate media asset retrieval. You can filter media assets by fields such as VideoId, CateId, StorageLocation, Title, and Tags. For more information, see Protocol for media asset search. The following code provides examples:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.SearchMediaRequest;
import com.aliyuncs.vod.model.v20170321.SearchMediaResponse;
public class SearchMediaExample {
public static void main(String[] args) {
// Initialize the client.
DefaultProfile profile = DefaultProfile.getProfile(
"cn-shanghai", // The region ID.
"YOUR_ACCESS_KEY_ID", // The AccessKey ID.
"YOUR_ACCESS_KEY_SECRET"// The AccessKey secret.
);
IAcsClient client = new DefaultAcsClient(profile);
// Build the request.
SearchMediaRequest request = new SearchMediaRequest();
request.setMatch("Title='VOD' AND Status='Normal'");
request.setFields("Title,CoverURL,Duration,Size");
request.setSortBy("CreationTime:Desc");
request.setPageSize(20);
request.setPageNo(1);
try {
SearchMediaResponse response = client.getAcsResponse(request);
System.out.println("Total Records: " + response.getTotal());
for (SearchMediaResponse.Media media : response.getMediaList()) {
System.out.println("VideoId: " + media.getMediaId() + ", Title: " + media.getVideo().getTitle());
}
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
e.printStackTrace();
}
}
}from aliyunsdkcore.client import AcsClient
from aliyunsdkvod.request.v20170321 import SearchMediaRequest
import json
# Initialize the client.
client = AcsClient(
'YOUR_ACCESS_KEY_ID',
'YOUR_ACCESS_KEY_SECRET',
'cn-shanghai'
)
# Build the request.
request = SearchMediaRequest.SearchMediaRequest()
request.set_Match("Title='VOD' AND Status='Normal'")
request.set_Fields("Title,CoverURL,Duration,Size")
request.set_SortBy("CreationTime:Desc")
request.set_PageSize(20)
request.set_PageNo(1)
try:
response_str = client.do_action_with_exception(request)
response_data = json.loads(response_str)
print(f"Total Records: {response_data.get('Total')}")
for media in response_data.get('MediaList', {}).get('Media', []):
print(f"VideoId: {media.get('MediaId')}, Title: {media.get('Video', {}).get('Title')}")
except Exception as e:
print(f"An error occurred: {e}")Paging and data traversal
To ensure query performance, media search provides two paging modes.
Standard paging (for UI display)
Use the
PageNoandPageSizeparameters to retrieve data page by page. You can retrieve up to the first 5,000 records from the search results.Scroll-based traversal (for data exporting)
Use the
PageNoandPageSizeparameters and theScrollTokencursor for deep traversal. This method lets you retrieve all search results in segments. Each segment is limited to a maximum of 1,200 records. The following code provides an example:// Scroll-based traversal example String scrollToken = null; // The SessionId must remain the same throughout a complete traversal. String sessionId = java.util.UUID.randomUUID().toString(); List<SearchMediaResponse.Media> allMedia = new ArrayList<>(); do { SearchMediaRequest request = new SearchMediaRequest(); request.setPageSize(100); // Pull up to 100 records at a time. request.setSessionId(sessionId); if (scrollToken != null) { request.setScrollToken(scrollToken); } SearchMediaResponse response = client.getAcsResponse(request); if (response.getMediaList() != null) { allMedia.addAll(response.getMediaList()); } scrollToken = response.getScrollToken(); // An empty or null scrollToken indicates that all data has been traversed. } while (scrollToken != null && !scrollToken.isEmpty());
API call examples
The sample code in the following section describes the query statements used for querying video information.
Before you send a request, you must perform URL encoding on the request parameters.
The equal signs (=), double quotation marks ("), single quotation marks ('), and parentheses used in the statement must be single-byte characters.
classification | Description |
Return field | The media search operation returns basic media asset information by default. To obtain additional information, specify the Sample request: |
Exact match | Query information about the video whose Sample request: |
Fuzzy match | To search for a Alternatively, you can write it as Sample request: |
Multi-value query | Note: If the fields used for the query only support fuzzy match, the query results are also returned based on fuzzy match. Query for a Sample request: |
Range query | Use a closed or open interval to specify a range. The Sample request: If you specify only a start or end time, leave the other value empty. For example, to query for a Sample request: |
Sort field | Sort media asset information in reverse chronological order based on the creation time: Sample request: |