Skip to content

Commit 0acaaeb

Browse files
committed
prop and source updates
1 parent 5e6dd68 commit 0acaaeb

File tree

14 files changed

+73
-149
lines changed

14 files changed

+73
-149
lines changed

components/youtube_data_api/common/consts.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,22 @@ export default {
115115
"replies",
116116
"snippet",
117117
],
118+
VIDEO_DURATIONS: [
119+
{
120+
label: "Do not filter video search results based on their duration. This is the default value.",
121+
value: "any",
122+
},
123+
{
124+
label: "Only include videos longer than 20 minutes",
125+
value: "long",
126+
},
127+
{
128+
label: "Only include videos that are between four and 20 minutes long (inclusive)",
129+
value: "medium",
130+
},
131+
{
132+
label: "Only include videos that are less than four minutes long",
133+
value: "short",
134+
},
135+
],
118136
};

components/youtube_data_api/sources/common/common.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export default {
7171
fn: this.youtubeDataApi.getVideos,
7272
params,
7373
});
74-
videos.forEach((video) => this.emitEvent(video));
74+
videos.forEach((video) => this.emitEvent({
75+
...video,
76+
url: `https://www.youtube.com/watch?v=${video.id.videoId}`,
77+
}));
7578
return videos[0].snippet.publishedAt;
7679
},
7780
async paginatePlaylistItems(params, publishedAfter = null) {
@@ -104,15 +107,15 @@ export default {
104107
count++;
105108
if (this.isRelevant(item, publishedAfter)) {
106109
results.push(item);
107-
if ((params.maxResults && results.length >= params.maxResults) || !nextPageToken) {
110+
if (params.maxResults && results.length >= params.maxResults) {
108111
done = true;
109112
break;
110113
}
111114
}
112115
}
113116
params.pageToken = nextPageToken;
114117
totalResults = pageInfo.totalResults;
115-
} while ((count < totalResults) && !done);
118+
} while ((count < totalResults) && params.pageToken && !done);
116119
return results;
117120
},
118121
},

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ export default {
1616
if (!this.handle) {
1717
return props;
1818
}
19-
const channelParams = {
20-
part: "id",
21-
forHandle: this.handle,
22-
};
23-
const channels = (await this.youtubeDataApi.getChannels(channelParams)).data;
19+
const channels = await this.getChannels();
2420
if (!channels.items) {
2521
props.alert = {
2622
type: "alert",
@@ -35,16 +31,11 @@ export default {
3531
...common.hooks,
3632
async deploy() {
3733
const channelIds = await this.getChannelIds();
38-
39-
const params = {
34+
const lastPublished = await this.loopThroughChannels(channelIds, {
4035
...this._getBaseParams(),
4136
maxResults: 10,
42-
};
43-
44-
const lastPublished = await this.loopThroughChannels(channelIds, params);
45-
46-
if (lastPublished) this._setPublishedAfter(lastPublished);
47-
else this._setPublishedAfter(new Date());
37+
});
38+
this._setPublishedAfter(lastPublished || new Date());
4839
},
4940
},
5041
methods: {
@@ -54,18 +45,19 @@ export default {
5445
channelId,
5546
};
5647
},
57-
async getChannelIds() {
58-
const channelParams = {
48+
async getChannels() {
49+
const { data } = await this.youtubeDataApi.getChannels({
5950
part: "id",
6051
forHandle: this.handle,
61-
};
62-
const channels = (await this.youtubeDataApi.getChannels(channelParams)).data;
52+
});
53+
return data;
54+
},
55+
async getChannelIds() {
56+
const channels = await this.getChannels();
6357
if (!channels.items) {
6458
throw new Error(`A channel for handle "${this.handle}" was not found`);
6559
}
66-
const channelIds = channels.items.map((channel) => {
67-
return channel.id;
68-
});
60+
const channelIds = channels.items.map(({ id }) => id);
6961
return channelIds;
7062
},
7163
async loopThroughChannels(channelIds, baseParams) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
key: "youtube_data_api-new-videos-by-handle",
88
name: "New Videos by Handle",
99
description: "Emit new event for each new Youtube video tied to a handle.",
10-
version: "0.0.1",
10+
version: "0.0.2",
1111
dedupe: "unique",
1212
props: {
1313
youtubeDataApi,

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

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import common from "../common/common.mjs";
2+
import consts from "../../common/consts.mjs";
23

34
export default {
45
...common,
@@ -8,18 +9,44 @@ export default {
89
type: "string",
910
label: "Search Query",
1011
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,
1138
},
1239
},
13-
hooks: {
14-
...common.hooks,
15-
deploy() {},
16-
},
40+
hooks: {},
1741
methods: {
1842
...common.methods,
1943
getParams() {
2044
return {
2145
q: this.q,
2246
maxResults: this.maxResults,
47+
channelId: this.channelId,
48+
location: this.location,
49+
locationRadius: this.locationRadius,
2350
};
2451
},
2552
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
type: "source",
77
key: "youtube_data_api-new-videos-by-search",
88
name: "New Videos by Search",
9-
description: "Emit new event for each new YouTube video matching a search query.",
10-
version: "0.0.9",
9+
description: "Emit new event for each new YouTube video matching the search criteria.",
10+
version: "0.0.10",
1111
dedupe: "unique",
1212
props: {
1313
youtubeDataApi,

components/youtube_data_api/sources/new-videos-in-channel/common.mjs

Lines changed: 0 additions & 21 deletions
This file was deleted.

components/youtube_data_api/sources/new-videos-in-channel/new-videos-in-channel.mjs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)