1 | |
2 | type Shutterstock = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Search editorial video content |
7 | * This endpoint searches for editorial videos. If you specify more than one search parameter, the API uses an AND condition. For example, if you set the `category` parameter to "Alone,Performing" and also specify a `query` parameter, the results include only videos that match the query and are in both the Alone and Performing categories. You can also filter search terms out in the `query` parameter by prefixing the term with NOT. |
8 | */ |
9 | export async function main( |
10 | auth: Shutterstock, |
11 | query: string | undefined, |
12 | sort: "relevant" | "newest" | "oldest" | undefined, |
13 | category: string | undefined, |
14 | country: string | undefined, |
15 | supplier_code: string | undefined, |
16 | date_start: string | undefined, |
17 | date_end: string | undefined, |
18 | resolution: "4k" | "high_definition" | "standard_definition" | undefined, |
19 | fps: string | undefined, |
20 | per_page: string | undefined, |
21 | cursor: string | undefined, |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.shutterstock.com/v2/editorial/videos/search`, |
25 | ); |
26 | for (const [k, v] of [ |
27 | ["query", query], |
28 | ["sort", sort], |
29 | ["category", category], |
30 | ["country", country], |
31 | ["supplier_code", supplier_code], |
32 | ["date_start", date_start], |
33 | ["date_end", date_end], |
34 | ["resolution", resolution], |
35 | ["fps", fps], |
36 | ["per_page", per_page], |
37 | ["cursor", cursor], |
38 | ]) { |
39 | if (v !== undefined && v !== "" && k !== undefined) { |
40 | url.searchParams.append(k, v); |
41 | } |
42 | } |
43 | const response = await fetch(url, { |
44 | method: "GET", |
45 | headers: { |
46 | Authorization: "Bearer " + auth.token, |
47 | }, |
48 | body: undefined, |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|