-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.js
63 lines (50 loc) · 1.94 KB
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const {Command, flags} = require('@oclif/command'),
ora = require("ora"),
path = require("path"),
{YouTubeAPI} = require("../../../lib/youtube");
class PlaylistItemsUpload extends Command {
async run(){
let spinner = await ora();
const {flags} = this.parse(PlaylistItemsUpload),
{profile, thumbnail, schema, media, playlist} = flags,
schemaPath = `${path.resolve()}/${schema}`,
mediaPath = `${path.resolve()}/${media}`
thumbnailPath = (thumbnail) ? `${path.resolve()}/${thumbnail}` : '';
try{
const auth = await require("../../../lib/client")(profile),
YouTubeAPIClient = await new YouTubeAPI(auth.oauth2Client);
spinner.start('Upload video into playlist...');
const video = await YouTubeAPIClient.uploadPlaylistItem(playlist, schemaPath, mediaPath, thumbnailPath);
spinner.succeed(`Item "${video.data.snippet.title}" uploaded in playlist "${playlist}"`);
}catch(err){
spinner.fail(`Error : ${err.message}`);
}
}
}
PlaylistItemsUpload.description = `Upload item into playlist`;
PlaylistItemsUpload.flags = {
profile : flags.string({
char : 'p',
description : 'Name of profile that associated YouTube Data API credential',
default : 'default'
}),
schema : flags.string({
char : 's',
description : 'Playlist items schema path <schema-file-path>',
required : true
}),
media : flags.string({
char : 'm',
description : 'Playlist items media/video path <media-file-path>',
required : true
}),
playlist : flags.string({
description : 'Playlist ID to which item to be uploaded',
required : true
}),
thumbnail : flags.string({
char : 't',
description : 'Video thumbnail(<thumbnail-file-path>)',
})
};
module.exports = PlaylistItemsUpload;