2022-01-03 13:42:42 -08:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
2020-07-01 19:54:51 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
2020-08-16 00:40:15 -07:00
|
|
|
INodeExecutionData,
|
2020-07-01 19:54:51 -07:00
|
|
|
INodePropertyOptions,
|
2020-08-16 00:40:15 -07:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeOperationError,
|
2020-07-01 19:54:51 -07:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { googleApiRequest, googleApiRequestAllItems } from './GenericFunctions';
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { channelFields, channelOperations } from './ChannelDescription';
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { playlistFields, playlistOperations } from './PlaylistDescription';
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { playlistItemFields, playlistItemOperations } from './PlaylistItemDescription';
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { videoFields, videoOperations } from './VideoDescription';
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { videoCategoryFields, videoCategoryOperations } from './VideoCategoryDescription';
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { countriesCodes } from './CountryCodes';
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2020-07-01 19:54:51 -07:00
|
|
|
export class YouTube implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
2020-08-16 00:40:15 -07:00
|
|
|
displayName: 'YouTube',
|
2020-07-01 19:54:51 -07:00
|
|
|
name: 'youTube',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-07-01 19:54:51 -07:00
|
|
|
icon: 'file:youTube.png',
|
|
|
|
group: ['input'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Consume YouTube API',
|
2020-07-01 19:54:51 -07:00
|
|
|
defaults: {
|
|
|
|
name: 'YouTube',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'youTubeOAuth2Api',
|
|
|
|
required: true,
|
2020-08-15 19:36:11 -07:00
|
|
|
},
|
2020-07-01 19:54:51 -07:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-07-01 19:54:51 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Channel',
|
|
|
|
value: 'channel',
|
|
|
|
},
|
2020-08-09 14:39:28 -07:00
|
|
|
{
|
|
|
|
name: 'Playlist',
|
|
|
|
value: 'playlist',
|
|
|
|
},
|
2020-08-15 19:36:11 -07:00
|
|
|
{
|
|
|
|
name: 'Playlist Item',
|
|
|
|
value: 'playlistItem',
|
|
|
|
},
|
2020-08-09 14:39:28 -07:00
|
|
|
{
|
|
|
|
name: 'Video',
|
|
|
|
value: 'video',
|
|
|
|
},
|
2020-08-11 13:07:23 -07:00
|
|
|
{
|
|
|
|
name: 'Video Category',
|
|
|
|
value: 'videoCategory',
|
|
|
|
},
|
2020-07-01 19:54:51 -07:00
|
|
|
],
|
|
|
|
default: 'channel',
|
|
|
|
},
|
|
|
|
...channelOperations,
|
|
|
|
...channelFields,
|
2020-08-09 14:39:28 -07:00
|
|
|
|
|
|
|
...playlistOperations,
|
|
|
|
...playlistFields,
|
|
|
|
|
2020-08-15 19:36:11 -07:00
|
|
|
...playlistItemOperations,
|
|
|
|
...playlistItemFields,
|
|
|
|
|
2020-08-09 14:39:28 -07:00
|
|
|
...videoOperations,
|
|
|
|
...videoFields,
|
2020-08-11 13:07:23 -07:00
|
|
|
|
|
|
|
...videoCategoryOperations,
|
|
|
|
...videoCategoryFields,
|
2020-07-01 19:54:51 -07:00
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
// Get all the languages to display them to user so that he can
|
|
|
|
// select them easily
|
2022-08-17 08:50:24 -07:00
|
|
|
async getLanguages(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-07-01 19:54:51 -07:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const languages = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
2020-10-22 09:00:28 -07:00
|
|
|
'/youtube/v3/i18nLanguages',
|
2020-07-01 19:54:51 -07:00
|
|
|
);
|
|
|
|
for (const language of languages) {
|
|
|
|
const languageName = language.id.toUpperCase();
|
|
|
|
const languageId = language.id;
|
|
|
|
returnData.push({
|
|
|
|
name: languageName,
|
2020-10-22 06:46:03 -07:00
|
|
|
value: languageId,
|
2020-07-01 19:54:51 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-08-09 14:39:28 -07:00
|
|
|
// Get all the countries codes to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getCountriesCodes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
for (const countryCode of countriesCodes) {
|
|
|
|
const countryCodeName = `${countryCode.name} - ${countryCode.alpha2}`;
|
|
|
|
const countryCodeId = countryCode.alpha2;
|
|
|
|
returnData.push({
|
|
|
|
name: countryCodeName,
|
|
|
|
value: countryCodeId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
// Get all the video categories to display them to user so that he can
|
|
|
|
// select them easily
|
2022-08-17 08:50:24 -07:00
|
|
|
async getVideoCategories(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-08-11 13:07:23 -07:00
|
|
|
const countryCode = this.getCurrentNodeParameter('regionCode') as string;
|
|
|
|
|
2020-08-09 14:39:28 -07:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const qs: IDataObject = {};
|
|
|
|
qs.regionCode = countryCode;
|
|
|
|
qs.part = 'snippet';
|
|
|
|
const categories = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
'/youtube/v3/videoCategories',
|
|
|
|
{},
|
2020-10-22 09:00:28 -07:00
|
|
|
qs,
|
2020-08-09 14:39:28 -07:00
|
|
|
);
|
|
|
|
for (const category of categories) {
|
|
|
|
const categoryName = category.snippet.title;
|
|
|
|
const categoryId = category.id;
|
|
|
|
returnData.push({
|
|
|
|
name: categoryName,
|
2020-10-22 06:46:03 -07:00
|
|
|
value: categoryId,
|
2020-08-09 14:39:28 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-08-15 19:36:11 -07:00
|
|
|
// Get all the playlists to display them to user so that he can
|
|
|
|
// select them easily
|
2022-08-17 08:50:24 -07:00
|
|
|
async getPlaylists(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2020-08-15 19:36:11 -07:00
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const qs: IDataObject = {};
|
|
|
|
qs.part = 'snippet';
|
|
|
|
qs.mine = true;
|
|
|
|
const playlists = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
|
|
|
'/youtube/v3/playlists',
|
|
|
|
{},
|
2020-10-22 09:00:28 -07:00
|
|
|
qs,
|
2020-08-15 19:36:11 -07:00
|
|
|
);
|
|
|
|
for (const playlist of playlists) {
|
|
|
|
const playlistName = playlist.snippet.title;
|
|
|
|
const playlistId = playlist.id;
|
|
|
|
returnData.push({
|
|
|
|
name: playlistName,
|
2020-10-22 06:46:03 -07:00
|
|
|
value: playlistId,
|
2020-08-15 19:36:11 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-07-01 19:54:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-07-01 19:54:51 -07:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-07-01 19:54:51 -07:00
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
if (resource === 'channel') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
//https://developers.google.com/youtube/v3/docs/channels/list
|
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
|
|
|
|
|
|
|
if (part.includes('*')) {
|
|
|
|
part = [
|
|
|
|
'brandingSettings',
|
|
|
|
'contentDetails',
|
|
|
|
'contentOwnerDetails',
|
|
|
|
'id',
|
|
|
|
'localizations',
|
|
|
|
'snippet',
|
|
|
|
'statistics',
|
|
|
|
'status',
|
|
|
|
'topicDetails',
|
|
|
|
];
|
|
|
|
}
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = part.join(',');
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.id = channelId;
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
responseData = await googleApiRequest.call(this, 'GET', '/youtube/v3/channels', {}, qs);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
2020-07-01 19:54:51 -07:00
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/channels/list
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
if (part.includes('*')) {
|
|
|
|
part = [
|
|
|
|
'brandingSettings',
|
|
|
|
'contentDetails',
|
|
|
|
'contentOwnerDetails',
|
|
|
|
'id',
|
|
|
|
'localizations',
|
|
|
|
'snippet',
|
|
|
|
'statistics',
|
|
|
|
'status',
|
|
|
|
'topicDetails',
|
|
|
|
];
|
2020-07-01 19:54:51 -07:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = part.join(',');
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, options, filters);
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.mine = true;
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (qs.categoryId || qs.forUsername || qs.id || qs.managedByMe) {
|
|
|
|
delete qs.mine;
|
|
|
|
}
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll) {
|
|
|
|
responseData = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/channels',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.maxResults = this.getNodeParameter('limit', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/channels',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2020-07-01 19:54:51 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/channels/update
|
|
|
|
if (operation === 'update') {
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
id: channelId,
|
|
|
|
brandingSettings: {
|
|
|
|
channel: {},
|
|
|
|
image: {},
|
|
|
|
},
|
|
|
|
};
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = 'brandingSettings';
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = updateFields.onBehalfOfContentOwner as string;
|
|
|
|
}
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.brandingSettingsUi) {
|
2022-08-17 08:50:24 -07:00
|
|
|
const channelSettingsValues = (updateFields.brandingSettingsUi as IDataObject)
|
|
|
|
.channelSettingsValues as IDataObject | undefined;
|
2021-07-19 23:58:54 -07:00
|
|
|
const channelSettings: IDataObject = {};
|
|
|
|
if (channelSettingsValues?.channel) {
|
|
|
|
const channelSettingsOptions = channelSettingsValues.channel as IDataObject;
|
|
|
|
if (channelSettingsOptions.country) {
|
|
|
|
channelSettings.country = channelSettingsOptions.country;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.description) {
|
|
|
|
channelSettings.description = channelSettingsOptions.description;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.defaultLanguage) {
|
|
|
|
channelSettings.defaultLanguage = channelSettingsOptions.defaultLanguage;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.defaultTab) {
|
|
|
|
channelSettings.defaultTab = channelSettingsOptions.defaultTab;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.featuredChannelsTitle) {
|
2022-08-17 08:50:24 -07:00
|
|
|
channelSettings.featuredChannelsTitle =
|
|
|
|
channelSettingsOptions.featuredChannelsTitle;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (channelSettingsOptions.featuredChannelsUrls) {
|
2022-08-17 08:50:24 -07:00
|
|
|
channelSettings.featuredChannelsUrls =
|
|
|
|
channelSettingsOptions.featuredChannelsUrls;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (channelSettingsOptions.keywords) {
|
|
|
|
channelSettings.keywords = channelSettingsOptions.keywords;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.moderateComments) {
|
2022-08-17 08:50:24 -07:00
|
|
|
channelSettings.moderateComments =
|
|
|
|
channelSettingsOptions.moderateComments as boolean;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (channelSettingsOptions.profileColor) {
|
|
|
|
channelSettings.profileColor = channelSettingsOptions.profileColor as string;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.profileColor) {
|
|
|
|
channelSettings.profileColor = channelSettingsOptions.profileColor as string;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.showRelatedChannels) {
|
2022-08-17 08:50:24 -07:00
|
|
|
channelSettings.showRelatedChannels =
|
|
|
|
channelSettingsOptions.showRelatedChannels as boolean;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (channelSettingsOptions.showBrowseView) {
|
|
|
|
channelSettings.showBrowseView = channelSettingsOptions.showBrowseView as boolean;
|
|
|
|
}
|
|
|
|
if (channelSettingsOptions.trackingAnalyticsAccountId) {
|
2022-08-17 08:50:24 -07:00
|
|
|
channelSettings.trackingAnalyticsAccountId =
|
|
|
|
channelSettingsOptions.trackingAnalyticsAccountId as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (channelSettingsOptions.unsubscribedTrailer) {
|
2022-08-17 08:50:24 -07:00
|
|
|
channelSettings.unsubscribedTrailer =
|
|
|
|
channelSettingsOptions.unsubscribedTrailer as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
}
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const imageSettingsValues = (updateFields.brandingSettingsUi as IDataObject)
|
|
|
|
.imageSettingsValues as IDataObject | undefined;
|
2021-07-19 23:58:54 -07:00
|
|
|
const imageSettings: IDataObject = {};
|
|
|
|
if (imageSettingsValues?.image) {
|
|
|
|
const imageSettingsOptions = imageSettings.image as IDataObject;
|
|
|
|
if (imageSettingsOptions.bannerExternalUrl) {
|
2022-08-17 08:50:24 -07:00
|
|
|
imageSettings.bannerExternalUrl =
|
|
|
|
imageSettingsOptions.bannerExternalUrl as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (imageSettingsOptions.trackingImageUrl) {
|
|
|
|
imageSettings.trackingImageUrl = imageSettingsOptions.trackingImageUrl as string;
|
|
|
|
}
|
|
|
|
if (imageSettingsOptions.watchIconImageUrl) {
|
2022-08-17 08:50:24 -07:00
|
|
|
imageSettings.watchIconImageUrl =
|
|
|
|
imageSettingsOptions.watchIconImageUrl as string;
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
}
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
//@ts-ignore
|
|
|
|
body.brandingSettings.channel = channelSettings;
|
|
|
|
//@ts-ignore
|
|
|
|
body.brandingSettings.image = imageSettings;
|
|
|
|
}
|
2020-07-01 19:54:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PUT',
|
|
|
|
'/youtube/v3/channels',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-08-14 15:36:47 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/channelBanners/insert
|
|
|
|
if (operation === 'uploadBanner') {
|
|
|
|
const channelId = this.getNodeParameter('channelId', i) as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const binaryProperty = this.getNodeParameter('binaryProperty', i);
|
2020-08-14 15:36:47 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let mimeType;
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Is binary file to upload
|
|
|
|
const item = items[i];
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary === undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryProperty] === undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`No binary data property "${binaryProperty}" does not exists on item!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryProperty].mimeType) {
|
|
|
|
mimeType = item.binary[binaryProperty].mimeType;
|
|
|
|
}
|
2020-08-14 15:36:47 -07:00
|
|
|
|
2022-01-03 13:42:42 -08:00
|
|
|
const body = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const requestOptions = {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': mimeType,
|
|
|
|
},
|
|
|
|
json: false,
|
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const response = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/upload/youtube/v3/channelBanners/insert',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
undefined,
|
|
|
|
requestOptions,
|
|
|
|
);
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const { url } = JSON.parse(response);
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = 'brandingSettings';
|
|
|
|
|
|
|
|
responseData = await googleApiRequest.call(
|
2020-08-09 14:39:28 -07:00
|
|
|
this,
|
2021-07-19 23:58:54 -07:00
|
|
|
'PUT',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/channels',
|
2021-07-19 23:58:54 -07:00
|
|
|
{
|
|
|
|
id: channelId,
|
|
|
|
brandingSettings: {
|
|
|
|
image: {
|
|
|
|
bannerExternalUrl: url,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-10-22 09:00:28 -07:00
|
|
|
qs,
|
2020-08-09 14:39:28 -07:00
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'playlist') {
|
|
|
|
//https://developers.google.com/youtube/v3/docs/playlists/list
|
|
|
|
if (operation === 'get') {
|
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
|
|
|
const playlistId = this.getNodeParameter('playlistId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
if (part.includes('*')) {
|
2022-08-17 08:50:24 -07:00
|
|
|
part = ['contentDetails', 'id', 'localizations', 'player', 'snippet', 'status'];
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
qs.part = part.join(',');
|
|
|
|
|
|
|
|
qs.id = playlistId;
|
|
|
|
|
|
|
|
Object.assign(qs, options);
|
|
|
|
|
2020-08-09 14:39:28 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/playlists',
|
2020-08-09 14:39:28 -07:00
|
|
|
{},
|
2020-10-22 09:00:28 -07:00
|
|
|
qs,
|
2020-08-09 14:39:28 -07:00
|
|
|
);
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.items;
|
2020-08-09 14:39:28 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlists/list
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
if (part.includes('*')) {
|
2022-08-17 08:50:24 -07:00
|
|
|
part = ['contentDetails', 'id', 'localizations', 'player', 'snippet', 'status'];
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = part.join(',');
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, options, filters);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.mine = true;
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (qs.channelId || qs.id) {
|
|
|
|
delete qs.mine;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll) {
|
|
|
|
responseData = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/playlists',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.maxResults = this.getNodeParameter('limit', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/playlists',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlists/insert
|
|
|
|
if (operation === 'create') {
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = 'snippet';
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
snippet: {
|
|
|
|
title,
|
|
|
|
},
|
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.tags) {
|
|
|
|
//@ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
body.snippet.tags = (options.tags as string).split(',');
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.description) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.privacyStatus = options.privacyStatus as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.defaultLanguage) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.defaultLanguage = options.defaultLanguage as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.onBehalfOfContentOwnerChannel) {
|
|
|
|
qs.onBehalfOfContentOwnerChannel = options.onBehalfOfContentOwnerChannel as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/youtube/v3/playlists',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-08-15 19:36:11 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlists/update
|
|
|
|
if (operation === 'update') {
|
|
|
|
const playlistId = this.getNodeParameter('playlistId', i) as string;
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
qs.part = 'snippet, status';
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
id: playlistId,
|
|
|
|
snippet: {
|
|
|
|
title,
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
status: {},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (updateFields.tags) {
|
|
|
|
//@ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
body.snippet.tags = (updateFields.tags as string).split(',');
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.privacyStatus) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.privacyStatus = updateFields.privacyStatus as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.description) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.description = updateFields.description as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.defaultLanguage) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.defaultLanguage = updateFields.defaultLanguage as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = updateFields.onBehalfOfContentOwner as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PUT',
|
|
|
|
'/youtube/v3/playlists',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-08-15 19:36:11 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlists/delete
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const playlistId = this.getNodeParameter('playlistId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
id: playlistId,
|
|
|
|
};
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
2020-08-15 19:36:11 -07:00
|
|
|
this,
|
2021-07-19 23:58:54 -07:00
|
|
|
'DELETE',
|
|
|
|
'/youtube/v3/playlists',
|
|
|
|
body,
|
2020-08-15 19:36:11 -07:00
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resource === 'playlistItem') {
|
|
|
|
//https://developers.google.com/youtube/v3/docs/playlistItems/list
|
|
|
|
if (operation === 'get') {
|
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
|
|
|
const playlistItemId = this.getNodeParameter('playlistItemId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
if (part.includes('*')) {
|
2022-08-17 08:50:24 -07:00
|
|
|
part = ['contentDetails', 'id', 'snippet', 'status'];
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
qs.part = part.join(',');
|
|
|
|
|
|
|
|
qs.id = playlistItemId;
|
|
|
|
|
|
|
|
Object.assign(qs, options);
|
|
|
|
|
2020-08-15 19:36:11 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/playlistItems',
|
2020-08-15 19:36:11 -07:00
|
|
|
{},
|
2020-10-22 09:00:28 -07:00
|
|
|
qs,
|
2020-08-15 19:36:11 -07:00
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
2020-08-15 19:36:11 -07:00
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlistItems/list
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const playlistId = this.getNodeParameter('playlistId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
//const filters = this.getNodeParameter('filters', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
if (part.includes('*')) {
|
2022-08-17 08:50:24 -07:00
|
|
|
part = ['contentDetails', 'id', 'snippet', 'status'];
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
qs.playlistId = playlistId;
|
|
|
|
|
|
|
|
qs.part = part.join(',');
|
|
|
|
|
|
|
|
Object.assign(qs, options);
|
|
|
|
|
|
|
|
if (returnAll) {
|
|
|
|
responseData = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/playlistItems',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.maxResults = this.getNodeParameter('limit', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/playlistItems',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//https://developers.google.com/youtube/v3/docs/playlistItems/insert
|
|
|
|
if (operation === 'add') {
|
|
|
|
const playlistId = this.getNodeParameter('playlistId', i) as string;
|
|
|
|
const videoId = this.getNodeParameter('videoId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
qs.part = 'snippet, contentDetails';
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
snippet: {
|
|
|
|
playlistId,
|
|
|
|
resourceId: {
|
|
|
|
kind: 'youtube#video',
|
|
|
|
videoId,
|
|
|
|
},
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
contentDetails: {},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.position) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.position = options.position as number;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.note) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.contentDetails.note = options.note as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.startAt) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.contentDetails.startAt = options.startAt as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.endAt) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.contentDetails.endAt = options.endAt as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
|
|
|
|
}
|
|
|
|
|
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/youtube/v3/playlistItems',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-08-15 19:36:11 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlistItems/delete
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const playlistItemId = this.getNodeParameter('playlistItemId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
id: playlistItemId,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
|
|
|
|
}
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'DELETE',
|
|
|
|
'/youtube/v3/playlistItems',
|
|
|
|
body,
|
|
|
|
);
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-08-15 19:36:11 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (resource === 'video') {
|
|
|
|
//https://developers.google.com/youtube/v3/docs/search/list
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
|
|
|
const filters = this.getNodeParameter('filters', i);
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = 'snippet';
|
2020-08-15 19:36:11 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.type = 'video';
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.forMine = true;
|
2020-08-14 15:36:47 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, options, filters);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (Object.keys(filters).length > 0) {
|
|
|
|
delete qs.forMine;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (qs.relatedToVideoId && qs.forDeveloper !== undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
2022-12-29 03:20:43 -08:00
|
|
|
"When using the parameter 'related to video' the parameter 'for developer' cannot be set",
|
2022-08-17 08:50:24 -07:00
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll) {
|
|
|
|
responseData = await googleApiRequestAllItems.call(
|
|
|
|
this,
|
|
|
|
'items',
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/search',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} else {
|
2022-11-18 06:26:22 -08:00
|
|
|
qs.maxResults = this.getNodeParameter('limit', i);
|
2022-12-29 03:20:43 -08:00
|
|
|
responseData = await googleApiRequest.call(this, 'GET', '/youtube/v3/search', {}, qs);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2020-08-14 15:36:47 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/videos/list?hl=en
|
|
|
|
if (operation === 'get') {
|
|
|
|
let part = this.getNodeParameter('part', i) as string[];
|
|
|
|
const videoId = this.getNodeParameter('videoId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
if (part.includes('*')) {
|
|
|
|
part = [
|
|
|
|
'contentDetails',
|
|
|
|
'id',
|
|
|
|
'liveStreamingDetails',
|
|
|
|
'localizations',
|
|
|
|
'player',
|
|
|
|
'recordingDetails',
|
|
|
|
'snippet',
|
|
|
|
'statistics',
|
|
|
|
'status',
|
|
|
|
'topicDetails',
|
|
|
|
];
|
|
|
|
}
|
2020-08-14 15:36:47 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = part.join(',');
|
|
|
|
|
|
|
|
qs.id = videoId;
|
|
|
|
|
|
|
|
Object.assign(qs, options);
|
2020-08-11 13:07:23 -07:00
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
responseData = await googleApiRequest.call(this, 'GET', '/youtube/v3/videos', {}, qs);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
2020-08-09 14:39:28 -07:00
|
|
|
responseData = responseData.items;
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/guides/uploading_a_video?hl=en
|
|
|
|
if (operation === 'upload') {
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
|
|
|
const categoryId = this.getNodeParameter('categoryId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2022-12-02 03:53:59 -08:00
|
|
|
const binaryProperty = this.getNodeParameter('binaryProperty', i);
|
2020-08-14 15:36:47 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let mimeType;
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
// Is binary file to upload
|
|
|
|
const item = items[i];
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary === undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryProperty] === undefined) {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`No binary data property "${binaryProperty}" does not exists on item!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryProperty].mimeType) {
|
|
|
|
mimeType = item.binary[binaryProperty].mimeType;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-01-03 13:42:42 -08:00
|
|
|
const body = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const requestOptions = {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': mimeType,
|
|
|
|
},
|
|
|
|
json: false,
|
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const response = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/upload/youtube/v3/videos',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
undefined,
|
|
|
|
requestOptions,
|
|
|
|
);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const { id } = JSON.parse(response);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = 'snippet, status, recordingDetails';
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const data = {
|
|
|
|
id,
|
|
|
|
snippet: {
|
|
|
|
title,
|
|
|
|
categoryId,
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
status: {},
|
|
|
|
recordingDetails: {},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.description) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.snippet.description = options.description as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.privacyStatus) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.status.privacyStatus = options.privacyStatus as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.tags) {
|
|
|
|
//@ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
data.snippet.tags = (options.tags as string).split(',');
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.embeddable) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.status.embeddable = options.embeddable as boolean;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.publicStatsViewable) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.status.publicStatsViewable = options.publicStatsViewable as boolean;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.publishAt) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.status.publishAt = options.publishAt as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.recordingDate) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.recordingDetails.recordingDate = options.recordingDate as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.selfDeclaredMadeForKids) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.status.selfDeclaredMadeForKids = options.selfDeclaredMadeForKids as boolean;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.license) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.status.license = options.license as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.defaultLanguage) {
|
|
|
|
//@ts-ignore
|
|
|
|
data.snippet.defaultLanguage = options.defaultLanguage as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.notifySubscribers) {
|
|
|
|
qs.notifySubscribers = options.notifySubscribers;
|
|
|
|
delete options.notifySubscribers;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
responseData = await googleApiRequest.call(this, 'PUT', '/youtube/v3/videos', data, qs);
|
2020-08-09 14:39:28 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/playlists/update
|
|
|
|
if (operation === 'update') {
|
|
|
|
const id = this.getNodeParameter('videoId', i) as string;
|
|
|
|
const title = this.getNodeParameter('title', i) as string;
|
|
|
|
const categoryId = this.getNodeParameter('categoryId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
qs.part = 'snippet, status, recordingDetails';
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
id,
|
|
|
|
snippet: {
|
|
|
|
title,
|
|
|
|
categoryId,
|
|
|
|
},
|
2022-08-17 08:50:24 -07:00
|
|
|
status: {},
|
|
|
|
recordingDetails: {},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.description) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.description = updateFields.description as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.privacyStatus) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.privacyStatus = updateFields.privacyStatus as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.tags) {
|
|
|
|
//@ts-ignore
|
2022-12-02 12:54:28 -08:00
|
|
|
body.snippet.tags = (updateFields.tags as string).split(',');
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.embeddable) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.embeddable = updateFields.embeddable as boolean;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.publicStatsViewable) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.publicStatsViewable = updateFields.publicStatsViewable as boolean;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.publishAt) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.publishAt = updateFields.publishAt as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.selfDeclaredMadeForKids) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.selfDeclaredMadeForKids = updateFields.selfDeclaredMadeForKids as boolean;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.recordingDate) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.recordingDetails.recordingDate = updateFields.recordingDate as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.license) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.status.license = updateFields.license as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (updateFields.defaultLanguage) {
|
|
|
|
//@ts-ignore
|
|
|
|
body.snippet.defaultLanguage = updateFields.defaultLanguage as string;
|
|
|
|
}
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await googleApiRequest.call(this, 'PUT', '/youtube/v3/videos', body, qs);
|
2020-08-09 14:39:28 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/videos/delete?hl=en
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const videoId = this.getNodeParameter('videoId', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
id: videoId,
|
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (options.onBehalfOfContentOwner) {
|
|
|
|
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
|
|
|
|
}
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
responseData = await googleApiRequest.call(this, 'DELETE', '/youtube/v3/videos', body);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-08-09 14:39:28 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
//https://developers.google.com/youtube/v3/docs/videos/rate?hl=en
|
|
|
|
if (operation === 'rate') {
|
|
|
|
const videoId = this.getNodeParameter('videoId', i) as string;
|
|
|
|
const rating = this.getNodeParameter('rating', i) as string;
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
id: videoId,
|
|
|
|
rating,
|
|
|
|
};
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/youtube/v3/videos/rate',
|
|
|
|
body,
|
|
|
|
);
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-08-09 14:39:28 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (resource === 'videoCategory') {
|
|
|
|
//https://developers.google.com/youtube/v3/docs/videoCategories/list
|
|
|
|
if (operation === 'getAll') {
|
2022-11-18 05:31:38 -08:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
const regionCode = this.getNodeParameter('regionCode', i) as string;
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.regionCode = regionCode;
|
2020-08-09 14:39:28 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.part = 'snippet';
|
|
|
|
|
|
|
|
responseData = await googleApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2022-12-29 03:20:43 -08:00
|
|
|
'/youtube/v3/videoCategories',
|
2021-07-19 23:58:54 -07:00
|
|
|
{},
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
responseData = responseData.items;
|
|
|
|
|
2022-12-02 12:54:28 -08:00
|
|
|
if (!returnAll) {
|
2022-11-18 06:26:22 -08:00
|
|
|
const limit = this.getNodeParameter('limit', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, limit);
|
|
|
|
}
|
2020-08-11 13:07:23 -07:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-08-11 13:07:23 -07:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2020-07-01 19:54:51 -07:00
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
return this.prepareOutputData(returnData);
|
2020-07-01 19:54:51 -07:00
|
|
|
}
|
|
|
|
}
|