Skip to content

Commit 39905ec

Browse files
committed
search-videos & update new-videos-by-search
1 parent 2a753ea commit 39905ec

File tree

5 files changed

+279
-35
lines changed

5 files changed

+279
-35
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import youtubeDataApi from "../../youtube_data_api.app.mjs";
2+
import consts from "../../common/consts.mjs";
3+
4+
export default {
5+
key: "youtube_data_api-search-videos",
6+
name: "Search Videos",
7+
description: "Returns a list of videos that match the search parameters. [See the documentation](https://developers.google.com/youtube/v3/docs/search/list) for more information",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
youtubeDataApi,
12+
q: {
13+
propDefinition: [
14+
youtubeDataApi,
15+
"q",
16+
],
17+
},
18+
channelId: {
19+
propDefinition: [
20+
youtubeDataApi,
21+
"channelId",
22+
],
23+
optional: true,
24+
},
25+
videoDuration: {
26+
propDefinition: [
27+
youtubeDataApi,
28+
"videoDuration",
29+
],
30+
},
31+
videoDefinition: {
32+
propDefinition: [
33+
youtubeDataApi,
34+
"videoDefinition",
35+
],
36+
},
37+
videoCaption: {
38+
propDefinition: [
39+
youtubeDataApi,
40+
"videoCaption",
41+
],
42+
},
43+
videoLicense: {
44+
propDefinition: [
45+
youtubeDataApi,
46+
"videoLicense",
47+
],
48+
},
49+
regionCode: {
50+
propDefinition: [
51+
youtubeDataApi,
52+
"regionCode",
53+
],
54+
},
55+
videoCategoryId: {
56+
propDefinition: [
57+
youtubeDataApi,
58+
"videoCategoryId",
59+
(c) => ({
60+
regionCode: c.regionCode,
61+
}),
62+
],
63+
optional: true,
64+
},
65+
location: {
66+
propDefinition: [
67+
youtubeDataApi,
68+
"location",
69+
],
70+
},
71+
locationRadius: {
72+
propDefinition: [
73+
youtubeDataApi,
74+
"locationRadius",
75+
],
76+
},
77+
sortOrder: {
78+
type: "string",
79+
label: "Sort Order",
80+
description: "The method that will be used to order resources in the API response. The default value is `relevance`",
81+
options: consts.VIDEO_SORT_ORDER,
82+
optional: true,
83+
},
84+
maxResults: {
85+
propDefinition: [
86+
youtubeDataApi,
87+
"maxResults",
88+
],
89+
},
90+
},
91+
async run({ $ }) {
92+
const results = this.youtubeDataApi.paginate(
93+
this.youtubeDataApi.getVideos,
94+
{
95+
part: "snippet",
96+
type: "video",
97+
q: this.q,
98+
channelId: this.channelId,
99+
location: this.location,
100+
locationRadius: this.locationRadius,
101+
videoDefinition: this.videoDefinition,
102+
videoDuration: this.videoDuration,
103+
videoCaption: this.videoCaption,
104+
videoLicense: this.videoLicense,
105+
order: this.sortOrder,
106+
regionCode: this.regionCode,
107+
videoCategoryId: this.videoCategoryId,
108+
},
109+
this.maxResults,
110+
);
111+
112+
const videos = [];
113+
for await (const video of results) {
114+
videos.push(video);
115+
}
116+
$.export("$summary", `Successfully fetched ${videos.length} video${videos.length === 1
117+
? ""
118+
: "s"}`);
119+
return videos;
120+
},
121+
};

components/youtube_data_api/common-app.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import youtube from "@googleapis/youtube";
22
import { toArray } from "./common/utils.mjs";
33
import { promisify } from "util";
44
const pause = promisify((delay, fn) => setTimeout(fn, delay));
5+
import consts from "./common/consts.mjs";
56

67
export default {
78
propDefinitions: {
@@ -259,6 +260,52 @@ export default {
259260
};
260261
},
261262
},
263+
q: {
264+
type: "string",
265+
label: "Search Query",
266+
description: "Search for new videos that match these keywords.",
267+
optional: true,
268+
},
269+
location: {
270+
type: "string",
271+
label: "Location",
272+
description: "The location parameter, in conjunction with the locationRadius parameter, defines a circular geographic area and also restricts a search to videos that specify, in their metadata, a geographic location that falls within that area. The parameter value is a string that specifies latitude/longitude coordinates e.g. `37.42307,-122.08427`.",
273+
optional: true,
274+
},
275+
locationRadius: {
276+
type: "string",
277+
label: "Location Radius",
278+
description: "The parameter value must be a floating point number followed by a measurement unit. Valid measurement units are m, km, ft, and mi. For example, valid parameter values include `1500m`, `5km`, `10000ft`, and `0.75mi`. The API does not support locationRadius parameter values larger than 1000 kilometers.",
279+
optional: true,
280+
},
281+
videoDuration: {
282+
type: "string",
283+
label: "Video Duration",
284+
description: "Filter the results based on video duration",
285+
options: consts.VIDEO_DURATIONS,
286+
optional: true,
287+
},
288+
videoCaption: {
289+
type: "string",
290+
label: "Video Caption",
291+
description: "Indicates whether the API should filter video search results based on whether they have captions",
292+
options: consts.VIDEO_CAPTION_OPTIONS,
293+
optional: true,
294+
},
295+
videoDefinition: {
296+
type: "string",
297+
label: "Video Definition",
298+
description: "Filter the results to only include either high definition (HD) or standard definition (SD) videos",
299+
options: consts.VIDEO_DEFINITION,
300+
optional: true,
301+
},
302+
videoLicense: {
303+
type: "string",
304+
label: "Video License",
305+
description: "Filter the results to only include videos with a particular license",
306+
options: consts.VIDEO_LICENSE,
307+
optional: true,
308+
},
262309
},
263310
methods: {
264311
/**

components/youtube_data_api/common/consts.mjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,44 @@ export default {
133133
value: "short",
134134
},
135135
],
136+
VIDEO_SORT_ORDER: [
137+
"date",
138+
"rating",
139+
"relevance",
140+
"title",
141+
"viewCount",
142+
],
143+
VIDEO_CAPTION_OPTIONS: [
144+
{
145+
label: "Do not filter results based on caption availability",
146+
value: "any",
147+
},
148+
{
149+
label: "Only include videos that have captions",
150+
value: "closedCaption",
151+
},
152+
{
153+
label: "Only include videos that do not have captions",
154+
value: "none",
155+
},
156+
],
157+
VIDEO_DEFINITION: [
158+
"any",
159+
"high",
160+
"standard",
161+
],
162+
VIDEO_LICENSE: [
163+
{
164+
label: "Return all videos",
165+
value: "any",
166+
},
167+
{
168+
label: "Only return videos that have a Creative Commons license. Users can reuse videos with this license in other videos that they create.",
169+
value: "creativeCommon",
170+
},
171+
{
172+
label: "Only return videos that have the standard YouTube license",
173+
value: "youtube",
174+
},
175+
],
136176
};

components/youtube_data_api/sources/new-videos-by-search/common.mjs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
11
import common from "../common/common.mjs";
2-
import consts from "../../common/consts.mjs";
32

43
export default {
54
...common,
6-
props: {
7-
...common.props,
8-
q: {
9-
type: "string",
10-
label: "Search Query",
11-
description: "Search for new videos that match these keywords.",
12-
optional: true,
13-
},
14-
channelId: {
15-
type: "string",
16-
label: "Channel ID",
17-
description: "The ID of the channel to search for new videos in. E.g. `UChkRx83xLq2nk55D8CRODVz`",
18-
optional: true,
19-
},
20-
location: {
21-
type: "string",
22-
label: "Location",
23-
description: "The location parameter, in conjunction with the locationRadius parameter, defines a circular geographic area and also restricts a search to videos that specify, in their metadata, a geographic location that falls within that area. The parameter value is a string that specifies latitude/longitude coordinates e.g. `37.42307,-122.08427`.",
24-
optional: true,
25-
},
26-
locationRadius: {
27-
type: "string",
28-
label: "Location Radius",
29-
description: "The parameter value must be a floating point number followed by a measurement unit. Valid measurement units are m, km, ft, and mi. For example, valid parameter values include `1500m`, `5km`, `10000ft`, and `0.75mi`. The API does not support locationRadius parameter values larger than 1000 kilometers.",
30-
optional: true,
31-
},
32-
videoDuration: {
33-
type: "string",
34-
label: "Video Duration",
35-
description: "Filter the results based on video duration",
36-
options: consts.VIDEO_DURATIONS,
37-
optional: true,
38-
},
39-
},
405
hooks: {},
416
methods: {
427
...common.methods,
@@ -47,6 +12,12 @@ export default {
4712
channelId: this.channelId,
4813
location: this.location,
4914
locationRadius: this.locationRadius,
15+
videoDuration: this.videoDuration,
16+
videoDefinition: this.videoDefinition,
17+
videoCaption: this.videoCaption,
18+
videoLicense: this.videoLicense,
19+
regionCode: this.regionCode,
20+
videoCategoryId: this.videoCategoryId,
5021
};
5122
},
5223
},

components/youtube_data_api/sources/new-videos-by-search/new-videos-by-search.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,71 @@ export default {
1111
dedupe: "unique",
1212
props: {
1313
youtubeDataApi,
14+
q: {
15+
propDefinition: [
16+
youtubeDataApi,
17+
"q",
18+
],
19+
},
20+
channelId: {
21+
propDefinition: [
22+
youtubeDataApi,
23+
"channelId",
24+
],
25+
optional: true,
26+
},
27+
videoDuration: {
28+
propDefinition: [
29+
youtubeDataApi,
30+
"videoDuration",
31+
],
32+
},
33+
videoDefinition: {
34+
propDefinition: [
35+
youtubeDataApi,
36+
"videoDefinition",
37+
],
38+
},
39+
videoCaption: {
40+
propDefinition: [
41+
youtubeDataApi,
42+
"videoCaption",
43+
],
44+
},
45+
videoLicense: {
46+
propDefinition: [
47+
youtubeDataApi,
48+
"videoLicense",
49+
],
50+
},
51+
regionCode: {
52+
propDefinition: [
53+
youtubeDataApi,
54+
"regionCode",
55+
],
56+
},
57+
videoCategoryId: {
58+
propDefinition: [
59+
youtubeDataApi,
60+
"videoCategoryId",
61+
(c) => ({
62+
regionCode: c.regionCode,
63+
}),
64+
],
65+
optional: true,
66+
},
67+
location: {
68+
propDefinition: [
69+
youtubeDataApi,
70+
"location",
71+
],
72+
},
73+
locationRadius: {
74+
propDefinition: [
75+
youtubeDataApi,
76+
"locationRadius",
77+
],
78+
},
1479
maxResults: {
1580
propDefinition: [
1681
youtubeDataApi,

0 commit comments

Comments
 (0)