Improvements

This commit is contained in:
ricardo 2020-08-09 17:39:28 -04:00
parent d4313defdc
commit 1e81b7d54f
7 changed files with 3450 additions and 16 deletions

View file

@ -9,6 +9,7 @@ const scopes = [
'https://www.googleapis.com/auth/youtubepartner',
'https://www.googleapis.com/auth/youtube.force-ssl',
'https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtubepartner-channel-audit',
];
export class YouTubeOAuth2Api implements ICredentialType {

View file

@ -142,8 +142,8 @@ export const channelFields = [
description: 'How many results to return.',
},
{
displayName: 'Options',
name: 'options',
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Option',
default: {},
@ -193,6 +193,25 @@ export const channelFields = [
default: false,
description: `This parameter can only be used in a properly authorized request. Set this parameter's value to true to instruct the API to only return channels owned by the authenticated user.`,
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'channel',
],
},
},
options: [
{
displayName: 'Language Code',
name: 'h1',

File diff suppressed because it is too large Load diff

View file

@ -29,14 +29,26 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
if (Object.keys(body).length === 0) {
delete options.body;
}
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, 'youTubeOAuth2Api', options);
} catch (error) {
if (error.response && error.response.body && error.response.body.error) {
let errors = error.response.body.error.errors;
let errors;
if (error.response && error.response.body) {
if (resource === '/upload/youtube/v3/videos') {
error.response.body = JSON.parse(error.response.body);
}
if (error.response.body.error) {
errors = error.response.body.error.errors;
errors = errors.map((e: IDataObject) => e.message);
}
errors = errors.map((e: IDataObject) => e.message);
// Try to return the error prettier
throw new Error(
`YouTube error response [${error.statusCode}]: ${errors.join('|')}`

View file

@ -0,0 +1,449 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const playlistOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'playlist',
],
},
},
options: [
{
name: 'Create',
value: 'create',
description: 'Create a playlist',
},
{
name: 'Delete',
value: 'delete',
description: 'Delete a playlist',
},
{
name: 'Get All',
value: 'getAll',
description: 'Retrieve all playlists',
},
{
name: 'Update',
value: 'update',
description: 'Update a playlist',
},
],
default: 'getAll',
description: 'The operation to perform.'
}
] as INodeProperties[];
export const playlistFields = [
/* -------------------------------------------------------------------------- */
/* playlist:create */
/* -------------------------------------------------------------------------- */
{
displayName: 'Title',
name: 'title',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'playlist',
],
},
},
default: '',
description: `The playlist's title.`,
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'create',
],
resource: [
'playlist',
],
},
},
options: [
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: `The playlist's description.`,
},
{
displayName: 'Privacy Status',
name: 'privacyStatus',
type: 'options',
options: [
{
name: 'Private',
value: 'private',
},
{
name: 'Public',
value: 'public',
},
{
name: 'Unlisted',
value: 'unlistef',
},
],
default: '',
description: `The playlist's privacy status.`,
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
default: '',
description: `Keyword tags associated with the playlist. Mulplie can be defined separated by comma`,
},
{
displayName: 'Default Language',
name: 'defaultLanguage',
type: 'string',
default: '',
description: `The language of the text in the playlist resource's title and description properties.`,
},
{
displayName: 'On Behalf Of Content Owner Channel',
name: 'onBehalfOfContentOwnerChannel',
type: 'string',
default: '',
description: `The onBehalfOfContentOwnerChannel parameter specifies the YouTube channel ID of the channel to which a video is being added.<br>
This parameter is required when a request specifies a value for the onBehalfOfContentOwner parameter, and it can only be used in conjunction with that parameter.`,
},
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
/* -------------------------------------------------------------------------- */
/* playlist:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Playlist ID',
name: 'playlistId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'playlist',
],
},
},
default: '',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'playlist',
],
},
},
options: [
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
/* -------------------------------------------------------------------------- */
/* playlist:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Fields',
name: 'part',
type: 'multiOptions',
options: [
{
name: 'Content Details',
value: 'contentDetails',
},
{
name: 'ID',
value: 'id',
},
{
name: 'Localizations',
value: 'localizations',
},
{
name: 'Player',
value: 'player',
},
{
name: 'Snippet',
value: 'snippet',
},
{
name: 'Status',
value: 'status',
},
],
required: true,
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'playlist',
],
},
},
description: 'The fields parameter specifies a comma-separated list of one or more playlist resource properties that the API response will include.',
default: ''
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'playlist',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'playlist',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'playlist',
],
},
},
options: [
{
displayName: 'Channel ID',
name: 'channelId',
type: 'string',
default: '',
description: `This value indicates that the API should only return the specified channel's playlists.`,
},
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
description: `The id parameter specifies a comma-separated list of the YouTube playlist ID(s) for the resource(s) that are being retrieved. In a playlist resource, the id property specifies the playlist's YouTube playlist ID.`,
},
{
displayName: 'Mine',
name: 'mine',
type: 'boolean',
default: false,
description: `Set this parameter's value to true to instruct the API to only return playlists owned by the authenticated user.`,
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'playlist',
],
},
},
options: [
{
displayName: 'On Behalf Of Content Owner Channel',
name: 'onBehalfOfContentOwnerChannel',
type: 'string',
default: '',
description: `The onBehalfOfContentOwnerChannel parameter specifies the YouTube channel ID of the channel to which a video is being added.<br>
This parameter is required when a request specifies a value for the onBehalfOfContentOwner parameter, and it can only be used in conjunction with that parameter.`,
},
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
/* -------------------------------------------------------------------------- */
/* playlist:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Playlist ID',
name: 'playlistId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'playlist',
],
},
},
default: '',
description: `The playlist's title.`,
},
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'playlist',
],
},
},
options: [
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: `The playlist's description.`,
},
{
displayName: 'Privacy Status',
name: 'privacyStatus',
type: 'options',
options: [
{
name: 'Private',
value: 'private',
},
{
name: 'Public',
value: 'public',
},
{
name: 'Unlisted',
value: 'unlistef',
},
],
default: '',
description: `The playlist's privacy status.`,
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
default: '',
description: `Keyword tags associated with the playlist. Mulplie can be defined separated by comma`,
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
},
{
displayName: 'Default Language',
name: 'defaultLanguage',
type: 'string',
default: '',
description: `The language of the text in the playlist resource's title and description properties.`,
},
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
] as INodeProperties[];

View file

@ -0,0 +1,862 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const videoOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'video',
],
},
},
options: [
{
name: 'Delete',
value: 'delete',
description: 'Delete a video',
},
{
name: 'Get',
value: 'get',
description: 'Get a video',
},
{
name: 'Get All',
value: 'getAll',
description: 'Retrieve all videos',
},
{
name: 'Rate',
value: 'rate',
description: 'Rate a video',
},
{
name: 'Update',
value: 'update',
description: 'Update a video',
},
{
name: 'Upload',
value: 'upload',
description: 'Upload a video',
},
],
default: 'getAll',
description: 'The operation to perform.'
}
] as INodeProperties[];
export const videoFields = [
/* -------------------------------------------------------------------------- */
/* video:upload */
/* -------------------------------------------------------------------------- */
{
displayName: 'Title',
name: 'title',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'upload',
],
resource: [
'video',
],
},
},
default: '',
},
{
displayName: 'Country Code',
name: 'countryCode',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCountriesCodes',
},
displayOptions: {
show: {
operation: [
'upload',
],
resource: [
'video',
],
},
},
default: '',
},
{
displayName: 'Category ID',
name: 'categoryId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getVideoCategories',
loadOptionsDependsOn: [
'countryCode',
],
},
displayOptions: {
show: {
operation: [
'upload',
],
resource: [
'video',
],
},
},
default: '',
},
{
displayName: 'Binary Property',
name: 'binaryProperty',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'upload',
],
resource: [
'video',
],
},
},
default: 'data',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'upload',
],
resource: [
'video',
],
},
},
options: [
{
displayName: 'Default Language',
name: 'defaultLanguage',
type: 'string',
default: '',
description: `The language of the text in the playlist resource's title and description properties.`,
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: `The playlist's description.`,
},
{
displayName: 'Embeddable',
name: 'embeddable',
type: 'boolean',
default: false,
description: `This value indicates whether the video can be embedded on another website.`,
},
{
displayName: 'License',
name: 'license',
type: 'options',
options: [
{
name: 'Creative Common',
value: 'creativeCommon',
},
{
name: 'Youtube',
value: 'youtube',
},
],
default: false,
description: `The video's license.`,
},
{
displayName: 'Notify Subscribers',
name: 'notifySubscribers',
type: 'boolean',
default: false,
description: `The notifySubscribers parameter indicates whether YouTube should send a notification about the new video to users who subscribe to the video's channel`,
},
{
displayName: 'Privacy Status',
name: 'privacyStatus',
type: 'options',
options: [
{
name: 'Private',
value: 'private',
},
{
name: 'Public',
value: 'public',
},
{
name: 'Unlisted',
value: 'unlistef',
},
],
default: '',
description: `The playlist's privacy status.`,
},
{
displayName: 'Public Stats Viewable',
name: 'publicStatsViewable',
type: 'boolean',
default: true,
description: `This value indicates whether the extended video statistics on the video's watch page are publicly viewable.`,
},
{
displayName: 'Publish At',
name: 'publishAt',
type: 'dateTime',
default: '',
description: `If you set a value for this property, you must also set the status.privacyStatus property to private.`,
},
{
displayName: 'Recording Date',
name: 'recordingDate',
type: 'dateTime',
default: '',
description: `The date and time when the video was recorded`,
},
{
displayName: 'Self Declared Made For Kids',
name: 'selfDeclaredMadeForKids',
type: 'boolean',
default: false,
description: `This value indicates whether the video is designated as child-directed, and it contains the current "made for kids" status of the video`,
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
default: '',
description: `Keyword tags associated with the playlist. Mulplie can be defined separated by comma`,
},
],
},
/* -------------------------------------------------------------------------- */
/* video:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Video ID',
name: 'videoId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'video',
],
},
},
default: '',
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'delete',
],
resource: [
'video',
],
},
},
options: [
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
/* -------------------------------------------------------------------------- */
/* video:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Video ID',
name: 'videoId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'video',
],
},
},
default: ''
},
{
displayName: 'Fields',
name: 'part',
type: 'multiOptions',
options: [
{
name: 'Content Details',
value: 'contentDetails',
},
{
name: 'Field Details',
value: 'fieldDetails',
},
{
name: 'ID',
value: 'id',
},
{
name: 'Live Streaming Details',
value: 'liveStreamingDetails',
},
{
name: 'Localizations',
value: 'localizations',
},
{
name: 'Player',
value: 'player',
},
{
name: 'Processing Details',
value: 'processingDetails',
},
{
name: 'Recording Details',
value: 'recordingDetails',
},
{
name: 'Snippet',
value: 'snippet',
},
{
name: 'Statistics',
value: 'statistics',
},
{
name: 'Status',
value: 'status',
},
{
name: 'Suggestions',
value: 'suggestions',
},
{
name: 'Topic Details',
value: 'topicDetails',
},
],
required: true,
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'video',
],
},
},
description: 'The fields parameter specifies a comma-separated list of one or more video resource properties that the API response will include.',
default: ''
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'get',
],
resource: [
'video',
],
},
},
options: [
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
/* -------------------------------------------------------------------------- */
/* video:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Fields',
name: 'part',
type: 'multiOptions',
options: [
{
name: 'Content Details',
value: 'contentDetails',
},
{
name: 'File Details',
value: 'fileDetails',
},
{
name: 'ID',
value: 'id',
},
{
name: 'Live Streaming Details',
value: 'liveStreamingDetails',
},
{
name: 'Localizations',
value: 'localizations',
},
{
name: 'Player',
value: 'player',
},
{
name: 'Processing Details',
value: 'processingDetails',
},
{
name: 'Recording Details',
value: 'recordingDetails',
},
{
name: 'Snippet',
value: 'snippet',
},
{
name: 'Statistics',
value: 'statistics',
},
{
name: 'Status',
value: 'status',
},
{
name: 'Suggestions',
value: 'suggestions',
},
{
name: 'Topic Details',
value: 'topicDetails',
},
],
required: true,
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'video',
],
},
},
description: 'The fields parameter specifies a comma-separated list of one or more video resource properties that the API response will include.',
default: ''
},
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'video',
],
},
},
default: false,
description: 'If all results should be returned or only up to a given limit.',
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'video',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 500,
},
default: 100,
description: 'How many results to return.',
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'video',
],
},
},
options: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
description: `The id parameter specifies a comma-separated list of the YouTube video ID(s) for the resource(s) that are being retrieved. In a video resource, the id property specifies the video's YouTube video ID.`,
},
{
displayName: 'My Rating',
name: 'myRating',
type: 'options',
options: [
{
name: 'Dislike',
value: 'dislike',
},
{
name: 'Like',
value: 'like',
},
],
default: '',
description: `Set this parameter's value to like or dislike to instruct the API to only return videos liked or disliked by the authenticated user.`,
},
{
displayName: 'Region Code',
name: 'regionCode',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getCountriesCodes',
},
default: '',
description: `The regionCode parameter instructs the API to select a video chart available in the specified region.`,
},
{
displayName: 'Video Category ID',
name: 'videoCategoryId',
type: 'string',
default: '',
description: `The videoCategoryId parameter identifies the video category for which the chart should be retrieved.`,
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'video',
],
},
},
options: [
{
displayName: 'On Behalf Of Content Owner',
name: 'onBehalfOfContentOwner',
type: 'string',
default: '',
description: `The onBehalfOfContentOwner parameter indicates that the request's authorization credentials identify<br>
a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value`,
},
],
},
/* -------------------------------------------------------------------------- */
/* video:rate */
/* -------------------------------------------------------------------------- */
{
displayName: 'Video ID',
name: 'videoId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'rate',
],
resource: [
'video',
],
},
},
default: '',
},
{
displayName: 'Rating',
name: 'rating',
type: 'options',
displayOptions: {
show: {
operation: [
'rate',
],
resource: [
'video',
],
},
},
options: [
{
name: 'Dislike',
value: 'dislike',
description: 'Records that the authenticated user disliked the video.',
},
{
name: 'Like',
value: 'like',
description: 'Records that the authenticated user liked the video.',
},
{
name: 'None',
value: 'none',
description: 'Removes any rating that the authenticated user had previously set for the video.',
},
],
default: '',
},
/* -------------------------------------------------------------------------- */
/* video:update */
/* -------------------------------------------------------------------------- */
{
displayName: 'Video ID',
name: 'videoId',
type: 'string',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'video',
],
},
},
default: '',
},
// {
// displayName: 'Country Code',
// name: 'countryCode',
// type: 'options',
// typeOptions: {
// loadOptionsMethod: 'getCountriesCodes',
// },
// displayOptions: {
// show: {
// operation: [
// 'update',
// ],
// resource: [
// 'video',
// ],
// },
// },
// default: '',
// },
// {
// displayName: 'Category ID',
// name: 'categoryId',
// type: 'options',
// typeOptions: {
// loadOptionsMethod: 'getVideoCategories',
// loadOptionsDependsOn: [
// 'countryCode',
// ],
// },
// displayOptions: {
// show: {
// operation: [
// 'update',
// ],
// resource: [
// 'video',
// ],
// },
// },
// default: '',
// },
{
displayName: 'Update Fields',
name: 'updateFields',
type: 'collection',
placeholder: 'Add Option',
default: {},
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'video',
],
},
},
options: [
{
displayName: 'Default Language',
name: 'defaultLanguage',
type: 'string',
default: '',
description: `The language of the text in the playlist resource's title and description properties.`,
},
{
displayName: 'Description',
name: 'description',
type: 'string',
default: '',
description: `The playlist's description.`,
},
{
displayName: 'Embeddable',
name: 'embeddable',
type: 'boolean',
default: false,
description: `This value indicates whether the video can be embedded on another website.`,
},
{
displayName: 'License',
name: 'license',
type: 'options',
options: [
{
name: 'Creative Common',
value: 'creativeCommon',
},
{
name: 'Youtube',
value: 'youtube',
},
],
default: false,
description: `The video's license.`,
},
{
displayName: 'Notify Subscribers',
name: 'notifySubscribers',
type: 'boolean',
default: false,
description: `The notifySubscribers parameter indicates whether YouTube should send a notification about the new video to users who subscribe to the video's channel`,
},
{
displayName: 'Privacy Status',
name: 'privacyStatus',
type: 'options',
options: [
{
name: 'Private',
value: 'private',
},
{
name: 'Public',
value: 'public',
},
{
name: 'Unlisted',
value: 'unlistef',
},
],
default: '',
description: `The playlist's privacy status.`,
},
{
displayName: 'Public Stats Viewable',
name: 'publicStatsViewable',
type: 'boolean',
default: true,
description: `This value indicates whether the extended video statistics on the video's watch page are publicly viewable.`,
},
{
displayName: 'Publish At',
name: 'publishAt',
type: 'dateTime',
default: '',
description: `If you set a value for this property, you must also set the status.privacyStatus property to private.`,
},
{
displayName: 'Recording Date',
name: 'recordingDate',
type: 'dateTime',
default: '',
description: `The date and time when the video was recorded`,
},
{
displayName: 'Self Declared Made For Kids',
name: 'selfDeclaredMadeForKids',
type: 'boolean',
default: false,
description: `This value indicates whether the video is designated as child-directed, and it contains the current "made for kids" status of the video`,
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
default: '',
description: `Keyword tags associated with the playlist. Mulplie can be defined separated by comma`,
},
{
displayName: 'Title',
name: 'title',
type: 'string',
default: '',
},
],
},
] as INodeProperties[];

View file

@ -1,5 +1,6 @@
import {
IExecuteFunctions, BINARY_ENCODING,
IExecuteFunctions,
BINARY_ENCODING,
} from 'n8n-core';
import {
@ -21,6 +22,20 @@ import {
channelFields,
} from './ChannelDescription';
import {
playlistOperations,
playlistFields,
} from './PlaylistDescription';
import {
videoOperations,
videoFields,
} from './VideoDescription';
import {
countriesCodes,
} from './CountryCodes';
export class YouTube implements INodeType {
description: INodeTypeDescription = {
displayName: 'Youtube',
@ -52,12 +67,26 @@ export class YouTube implements INodeType {
name: 'Channel',
value: 'channel',
},
{
name: 'Playlist',
value: 'playlist',
},
{
name: 'Video',
value: 'video',
},
],
default: 'channel',
description: 'The resource to operate on.'
},
...channelOperations,
...channelFields,
...playlistOperations,
...playlistFields,
...videoOperations,
...videoFields,
],
};
@ -85,6 +114,48 @@ export class YouTube implements INodeType {
}
return returnData;
},
// 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
async getVideoCategories(
this: ILoadOptionsFunctions
): Promise<INodePropertyOptions[]> {
const countryCode = this.getCurrentNodeParameter('countryCode') as string;
const returnData: INodePropertyOptions[] = [];
const qs: IDataObject = {};
qs.regionCode = countryCode;
qs.part = 'snippet';
const categories = await googleApiRequestAllItems.call(
this,
'items',
'GET',
'/youtube/v3/videoCategories',
{},
qs,
);
for (const category of categories) {
const categoryName = category.snippet.title;
const categoryId = category.id;
returnData.push({
name: categoryName,
value: categoryId
});
}
return returnData;
},
}
};
@ -103,23 +174,24 @@ export class YouTube implements INodeType {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject;
qs.part = part.join(',');
if (options.categoryId) {
qs.categoryId = options.categoryId as string;
if (filters.categoryId) {
qs.categoryId = filters.categoryId as string;
}
if (options.forUsername) {
qs.forUsername = options.forUsername as string;
if (filters.forUsername) {
qs.forUsername = filters.forUsername as string;
}
if (options.id) {
qs.id = options.id as string;
if (filters.id) {
qs.id = filters.id as string;
}
if (options.managedByMe) {
qs.managedByMe = options.managedByMe as boolean;
if (filters.managedByMe) {
qs.managedByMe = filters.managedByMe as boolean;
}
if (options.mine) {
qs.mine = options.mine as boolean;
if (filters.mine) {
qs.mine = filters.mine as boolean;
}
if (options.h1) {
qs.h1 = options.h1 as string;
@ -298,6 +370,446 @@ export class YouTube implements INodeType {
);
}
}
if (resource === 'playlist') {
//https://developers.google.com/youtube/v3/docs/playlists/list
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject;
qs.part = part.join(',');
Object.assign(qs, options, filters);
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'items',
'GET',
`/youtube/v3/playlists`,
{},
qs
);
} else {
qs.maxResults = this.getNodeParameter('limit', i) as number;
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/playlists`,
{},
qs
);
responseData = responseData.items;
}
}
//https://developers.google.com/youtube/v3/docs/playlists/insert
if (operation === 'create') {
const title = this.getNodeParameter('title', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
qs.part = 'snippet';
const body: IDataObject = {
snippet: {
title,
},
};
if (options.tags) {
//@ts-ignore
body.snippet.tags = (options.tags as string).split(',') as string[];
}
if (options.description) {
//@ts-ignore
body.snippet.privacyStatus = options.privacyStatus as string;
}
if (options.defaultLanguage) {
//@ts-ignore
body.snippet.defaultLanguage = options.defaultLanguage as string;
}
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
if (options.onBehalfOfContentOwnerChannel) {
qs.onBehalfOfContentOwnerChannel = options.onBehalfOfContentOwnerChannel as string;
}
responseData = await googleApiRequest.call(
this,
'POST',
'/youtube/v3/playlists',
body,
qs
);
}
//https://developers.google.com/youtube/v3/docs/playlists/update
if (operation === 'update') {
const playlistId = this.getNodeParameter('playlistId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
qs.part = 'snippet';
const body: IDataObject = {
id: playlistId,
snippet: {
}
};
if (updateFields.tags) {
//@ts-ignore
body.snippet.tags = (updateFields.tags as string).split(',') as string[];
}
if (updateFields.title) {
//@ts-ignore
body.snippet.title = updateFields.title as string
}
if (updateFields.description) {
//@ts-ignore
body.snippet.description = updateFields.description as string;
}
if (updateFields.defaultLanguage) {
//@ts-ignore
body.snippet.defaultLanguage = updateFields.defaultLanguage as string;
}
if (updateFields.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = updateFields.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'PUT',
'/youtube/v3/playlists',
body,
qs
);
}
//https://developers.google.com/youtube/v3/docs/playlists/delete
if (operation === 'delete') {
const playlistId = this.getNodeParameter('playlistId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const body: IDataObject = {
id: playlistId,
};
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'DELETE',
'/youtube/v3/playlists',
body,
);
responseData = { success: true };
}
}
if (resource === 'video') {
//https://developers.google.com/youtube/v3/docs/videos/list?hl=en
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const part = this.getNodeParameter('part', i) as string[];
const options = this.getNodeParameter('options', i) as IDataObject;
const filters = this.getNodeParameter('filters', i) as IDataObject;
qs.part = part.join(',');
qs.chart = 'mostPopular';
Object.assign(qs, options, filters);
if (returnAll) {
responseData = await googleApiRequestAllItems.call(
this,
'items',
'GET',
`/youtube/v3/videos`,
{},
qs
);
} else {
qs.maxResults = this.getNodeParameter('limit', i) as number;
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/videos`,
{},
qs
);
responseData = responseData.items;
}
}
//https://developers.google.com/youtube/v3/docs/videos/list?hl=en
if (operation === 'get') {
const part = this.getNodeParameter('part', i) as string[];
const videoId = this.getNodeParameter('videoId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
qs.part = part.join(',');
qs.id = videoId;
Object.assign(qs, options);
responseData = await googleApiRequest.call(
this,
'GET',
`/youtube/v3/videos`,
{},
qs
);
responseData = responseData.items;
}
//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;
const options = this.getNodeParameter('options', i) as IDataObject;
const binaryProperty = this.getNodeParameter('binaryProperty', i) as string;
let mimeType;
// Is binary file to upload
const item = items[i];
if (item.binary === undefined) {
throw new Error('No binary data exists on item!');
}
if (item.binary[binaryProperty] === undefined) {
throw new Error(`No binary data property "${binaryProperty}" does not exists on item!`);
}
if (item.binary[binaryProperty].mimeType) {
mimeType = item.binary[binaryProperty].mimeType;
}
const body = Buffer.from(item.binary[binaryProperty].data, BINARY_ENCODING);
const requestOptions = {
headers: {
'Content-Type': mimeType,
},
json: false,
};
let response = await googleApiRequest.call(this, 'POST', '/upload/youtube/v3/videos', body, qs, undefined, requestOptions);
const { id } = JSON.parse(response);
qs.part = 'snippet, status, recordingDetails';
const data = {
id,
snippet: {
title,
categoryId,
},
status: {
},
recordingDetails: {
},
}
if (options.description) {
//@ts-ignore
data.snippet.description = options.description as string;
}
if (options.privacyStatus) {
//@ts-ignore
data.status.privacyStatus = options.privacyStatus as string;
}
if (options.tags) {
//@ts-ignore
data.snippet.tags = (options.tags as string).split(',') as string[];
}
if (options.embeddable) {
//@ts-ignore
data.status.embeddable = options.embeddable as boolean;
}
if (options.publicStatsViewable) {
//@ts-ignore
data.status.publicStatsViewable = options.publicStatsViewable as boolean;
}
if (options.publishAt) {
//@ts-ignore
data.status.publishAt = options.publishAt as string;
}
if (options.recordingDate) {
//@ts-ignore
data.recordingDetails.recordingDate = options.recordingDate as string;
}
if (options.selfDeclaredMadeForKids) {
//@ts-ignore
data.status.selfDeclaredMadeForKids = options.selfDeclaredMadeForKids as boolean;
}
if (options.license) {
//@ts-ignore
data.status.license = options.license as string;
}
if (options.defaultLanguage) {
//@ts-ignore
data.snippet.defaultLanguage = options.defaultLanguage as string;
}
if (options.notifySubscribers) {
qs.notifySubscribers = options.notifySubscribers;
delete options.notifySubscribers;
}
responseData = await googleApiRequest.call(
this,
'PUT',
`/youtube/v3/videos`,
data,
qs,
);
}
//https://developers.google.com/youtube/v3/docs/playlists/update
if (operation === 'update') {
const id = this.getNodeParameter('videoId', i) as string;
//const categoryId = this.getNodeParameter('categoryId', i) as string;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
qs.part = 'snippet, status, recordingDetails';
const body = {
id,
snippet: {
//categoryId,
},
status: {
},
recordingDetails: {
},
}
if (updateFields.description) {
//@ts-ignore
data.snippet.description = updateFields.description as string;
}
if (updateFields.privacyStatus) {
//@ts-ignore
data.status.privacyStatus = updateFields.privacyStatus as string;
}
if (updateFields.tags) {
//@ts-ignore
data.snippet.tags = (updateFields.tags as string).split(',') as string[];
}
if (updateFields.description) {
//@ts-ignore
data.snippet.title = updateFields.title as string;
}
if (updateFields.embeddable) {
//@ts-ignore
data.status.embeddable = updateFields.embeddable as boolean;
}
if (updateFields.publicStatsViewable) {
//@ts-ignore
data.status.publicStatsViewable = updateFields.publicStatsViewable as boolean;
}
if (updateFields.publishAt) {
//@ts-ignore
data.status.publishAt = updateFields.publishAt as string;
}
if (updateFields.recordingDate) {
//@ts-ignore
data.recordingDetails.recordingDate = updateFields.recordingDate as string;
}
if (updateFields.selfDeclaredMadeForKids) {
//@ts-ignore
data.status.selfDeclaredMadeForKids = updateFields.selfDeclaredMadeForKids as boolean;
}
if (updateFields.license) {
//@ts-ignore
data.status.license = options.license as string;
}
if (updateFields.defaultLanguage) {
//@ts-ignore
data.snippet.defaultLanguage = updateFields.defaultLanguage as string;
}
responseData = await googleApiRequest.call(
this,
'PUT',
'/youtube/v3/videos',
body,
qs
);
}
//https://developers.google.com/youtube/v3/docs/videos/delete?hl=en
if (operation === 'delete') {
const videoId = this.getNodeParameter('videoId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const body: IDataObject = {
id: videoId,
};
if (options.onBehalfOfContentOwner) {
qs.onBehalfOfContentOwner = options.onBehalfOfContentOwner as string;
}
responseData = await googleApiRequest.call(
this,
'DELETE',
'/youtube/v3/video',
body,
);
responseData = { success: true };
}
//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;
const body: IDataObject = {
id: videoId,
rating,
};
responseData = await googleApiRequest.call(
this,
'POST',
'/youtube/v3/videos/rate',
body,
);
responseData = { success: true };
}
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);