1 | |
2 | type Shutterstock = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Search for videos |
7 | * This endpoint searches for videos. If you specify more than one search parameter, the API uses an AND condition. Array parameters can be specified multiple times; in this case, the API uses an AND or an OR condition with those values, depending on the parameter. 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 | added_date: string | undefined, |
12 | added_date_start: string | undefined, |
13 | added_date_end: string | undefined, |
14 | aspect_ratio: "4_3" | "16_9" | "nonstandard" | undefined, |
15 | category: string | undefined, |
16 | contributor: string | undefined, |
17 | contributor_country: string | undefined, |
18 | duration: string | undefined, |
19 | duration_from: string | undefined, |
20 | duration_to: string | undefined, |
21 | fps: string | undefined, |
22 | fps_from: string | undefined, |
23 | fps_to: string | undefined, |
24 | keyword_safe_search: string | undefined, |
25 | language: |
26 | | "ar" |
27 | | "bg" |
28 | | "bn" |
29 | | "cs" |
30 | | "da" |
31 | | "de" |
32 | | "el" |
33 | | "en" |
34 | | "es" |
35 | | "fi" |
36 | | "fr" |
37 | | "gu" |
38 | | "he" |
39 | | "hi" |
40 | | "hr" |
41 | | "hu" |
42 | | "id" |
43 | | "it" |
44 | | "ja" |
45 | | "kn" |
46 | | "ko" |
47 | | "ml" |
48 | | "mr" |
49 | | "nb" |
50 | | "nl" |
51 | | "or" |
52 | | "pl" |
53 | | "pt" |
54 | | "ro" |
55 | | "ru" |
56 | | "sk" |
57 | | "sl" |
58 | | "sv" |
59 | | "ta" |
60 | | "te" |
61 | | "th" |
62 | | "tr" |
63 | | "uk" |
64 | | "ur" |
65 | | "vi" |
66 | | "zh" |
67 | | "zh-Hant" |
68 | | undefined, |
69 | license: string | undefined, |
70 | model: string | undefined, |
71 | orientation: "vertical" | "horizontal" | undefined, |
72 | page: string | undefined, |
73 | per_page: string | undefined, |
74 | people_age: |
75 | | "infants" |
76 | | "children" |
77 | | "teenagers" |
78 | | "20s" |
79 | | "30s" |
80 | | "40s" |
81 | | "50s" |
82 | | "60s" |
83 | | "older" |
84 | | undefined, |
85 | people_ethnicity: string | undefined, |
86 | people_gender: "male" | "female" | "both" | undefined, |
87 | people_number: string | undefined, |
88 | people_model_released: string | undefined, |
89 | query: string | undefined, |
90 | resolution: "4k" | "standard_definition" | "high_definition" | undefined, |
91 | safe: string | undefined, |
92 | sort: "newest" | "popular" | "relevance" | "random" | undefined, |
93 | view: "minimal" | "full" | undefined, |
94 | ) { |
95 | const url = new URL(`https://api.shutterstock.com/v2/videos/search`); |
96 | for (const [k, v] of [ |
97 | ["added_date", added_date], |
98 | ["added_date_start", added_date_start], |
99 | ["added_date_end", added_date_end], |
100 | ["aspect_ratio", aspect_ratio], |
101 | ["category", category], |
102 | ["contributor", contributor], |
103 | ["contributor_country", contributor_country], |
104 | ["duration", duration], |
105 | ["duration_from", duration_from], |
106 | ["duration_to", duration_to], |
107 | ["fps", fps], |
108 | ["fps_from", fps_from], |
109 | ["fps_to", fps_to], |
110 | ["keyword_safe_search", keyword_safe_search], |
111 | ["language", language], |
112 | ["license", license], |
113 | ["model", model], |
114 | ["orientation", orientation], |
115 | ["page", page], |
116 | ["per_page", per_page], |
117 | ["people_age", people_age], |
118 | ["people_ethnicity", people_ethnicity], |
119 | ["people_gender", people_gender], |
120 | ["people_number", people_number], |
121 | ["people_model_released", people_model_released], |
122 | ["query", query], |
123 | ["resolution", resolution], |
124 | ["safe", safe], |
125 | ["sort", sort], |
126 | ["view", view], |
127 | ]) { |
128 | if (v !== undefined && v !== "" && k !== undefined) { |
129 | url.searchParams.append(k, v); |
130 | } |
131 | } |
132 | const response = await fetch(url, { |
133 | method: "GET", |
134 | headers: { |
135 | Authorization: "Bearer " + auth.token, |
136 | }, |
137 | body: undefined, |
138 | }); |
139 | if (!response.ok) { |
140 | const text = await response.text(); |
141 | throw new Error(`${response.status} ${text}`); |
142 | } |
143 | return await response.json(); |
144 | } |
145 |
|