-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyoutubeUpload.js
More file actions
103 lines (92 loc) · 3 KB
/
Copy pathyoutubeUpload.js
File metadata and controls
103 lines (92 loc) · 3 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const axios = require('axios');
const config = require('./config.json');
const fs = require('fs');
const { google } = require('googleapis');
const moment = require('moment');
const getAccessToken = () => {
return new Promise(async (resolve, reject) => {
try {
const { data } = await axios.post(
'https://www.googleapis.com/oauth2/v4/token',
{
client_id: config.YT_API.CLIENT_ID,
client_secret: config.YT_API.CLIENT_SECRET,
refresh_token: config.YT_API.REFRESH_TOKEN,
grant_type: 'refresh_token',
}
);
resolve({
refresh_token: config.YT_API.REFRESH_TOKEN,
...data,
});
} catch (err) {
reject(err);
}
});
};
const youtubeUpload = (fileName, facebookVideo) => {
return new Promise(async (resolve, reject) => {
try {
const oAuthClient = new google.auth.OAuth2(
config.YT_API.CLIENT_ID,
config.YT_API.CLIENT_SECRET,
'https://developers.google.com/oauthplayground'
);
oAuthClient.credentials = await getAccessToken();
const youtube = google.youtube({
version: 'v3',
auth: oAuthClient,
});
const startDate = moment(facebookVideo.started)
// .add(2, 'hours')
.locale('pl')
.format('DD MMMM YYYY (H:mm)');
const videoDesc = `Całe archiwum strumieni: https://www.youtube.com/playlist?list=PLWbAUhvm4h-Mz9YKtMZQX2xAR_dzlklUv
oraz na stronie https://jarchiwum.pl
https://www.twitch.tv/mujstach - tu znajdziecie MujStacha
https://twitter.com/glamh0th - tu znajdziecie Glamhotha
https://twitter.com/dzejTH - tu znajdziecie Dżeja.
Śledzić nas można:
http://jadisco.pl - to jest małe centrum sterowania światem.
https://www.facebook.com/StrumienieZRuczaju - obecnie z tego miejsca nadlatują strimy i prowadzone są tam typowo socjalkowe akcji (wpisy, płatne wpisy itd.)
suchykanal@gmail.com - kontakt
http://steamcommunity.com/groups/Szpara - grupa steamowa, też ma powiadomienia
https://twitter.com/wonziu - to mój intymny twitter
https://twitter.com/ruczajircpower - a to twitter, który informuje o tym kiedy i co dzieje się na strumieniu. Realnie to najlepiej działający powiadamiacz.
Współpracują z nami twórcy muzyki:
https://soundcloud.com/atian
https://www.grindpeace.com/
Pozdrawiam,
m.
${facebookVideo.facebookId}`;
const video = await youtube.videos.insert({
part: 'id,snippet,status',
notifySubscribers: false,
requestBody: {
snippet: {
title: `Archiwum strumieni - ${startDate}`,
description: videoDesc,
},
status: {
privacyStatus: 'unlisted',
},
},
media: {
body: fs.createReadStream(fileName),
},
});
resolve(video);
} catch (err) {
const error = {
data: err,
facebookVideo: facebookVideo,
};
reject(error);
}
});
};
// module.exports = youtubeUpload
module.exports = {
youtubeUpload,
getAccessToken,
};