Skip to content

Commit 413b0d4

Browse files
committed
fix: upload not working
1 parent c750ec2 commit 413b0d4

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const config = {
22
SOUNDCLOUD_CLIENT_ID: process.env.SOUNDCLOUD_CLIENT_ID,
33
SOUNDCLOUD_SEARCH_TAGS: ['Chill', 'Trap'],
44
SOUNDCLOUD_SEARCH_LICENSE: 'cc-by',
5-
YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY,
5+
YOUTUBE_CLIENT_ID: process.env.YOUTUBE_CLIENT_ID,
6+
YOUTUBE_CLIENT_SECRET: process.env.YOUTUBE_CLIENT_SECRET,
7+
YOUTUBE_REFRESH_TOKEN: process.env.YOUTUBE_REFRESH_TOKEN,
8+
UNSPLASH_ACCESS_KEY: process.env.UNSPLASH_ACCESS_KEY,
69
};
710

811
export default config;

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,26 @@ import {
44
launchPage,
55
closePage,
66
processVideo,
7+
uploadVideo,
78
} from './video';
89
import { getTracksFromSoundcloud } from './audio';
9-
import { getUnsplashUrl } from './image';
10+
import { getUnsplashPhoto } from './image';
1011
import { resolve } from 'path';
1112

1213
const test = async () => {
1314
launchPage();
1415
const song = await getTracksFromSoundcloud();
16+
const { data: image } = await getUnsplashPhoto(song.tag_list);
1517
const svgContent = prepareSvg(
16-
getUnsplashUrl(song.tag_list),
18+
image.urls.custom,
1719
song.title.replace(/(")|(')|(\.)/g, ''),
1820
song.user.username
1921
);
2022
await generateImage(svgContent);
2123
await processVideo(song, resolve(__dirname, '../assets/out.png'));
24+
const response = await uploadVideo(song, image);
25+
26+
console.log('Youtube video id - ' + response.data.id);
2227
};
2328

2429
test().catch(e => {

src/video.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
import ffmpeg from 'fluent-ffmpeg';
2-
import { Track } from './audio';
2+
import { PickedTrack } from './audio';
33
import { Browser, launch } from 'puppeteer';
44
import config from './config';
55
import path, { resolve } from 'path';
66
import { google } from 'googleapis';
77
import { addDays } from 'date-fns';
88
import { createReadStream } from 'fs';
9+
import { IUnsplashResponse } from 'image';
910

10-
const youtube = google.youtube({ version: 'v3', auth: config.YOUTUBE_API_KEY });
11+
const oauthclient = new google.auth.OAuth2({
12+
clientId: config.YOUTUBE_CLIENT_ID,
13+
clientSecret: config.YOUTUBE_CLIENT_SECRET,
14+
});
15+
16+
oauthclient.setCredentials({
17+
refresh_token: config.YOUTUBE_REFRESH_TOKEN,
18+
});
19+
20+
(async () =>
21+
oauthclient.setCredentials({
22+
access_token: (await oauthclient.getAccessToken()).token,
23+
}))();
24+
25+
const youtube = google.youtube({ version: 'v3', auth: oauthclient });
1126

1227
let window: Browser;
1328

@@ -60,7 +75,7 @@ export const generateImage = async (content: string) => {
6075
};
6176

6277
export const processVideo = (
63-
song: Pick<Track, 'duration' | 'download_url' | 'stream_url'>,
78+
song: PickedTrack,
6479
image: string
6580
): Promise<void> => {
6681
//@ts-ignore
@@ -95,7 +110,11 @@ export const processVideo = (
95110
});
96111
};
97112

98-
const getDescription = (songTitle: string, song: Track) => `
113+
const getDescription = (
114+
songTitle: string,
115+
song: PickedTrack,
116+
imageData: IUnsplashResponse
117+
) => `
99118
${songTitle}
100119
101120
⭐️ DatSongBot brings you another fresh, new music by ${
@@ -108,18 +127,27 @@ const getDescription = (songTitle: string, song: Track) => `
108127
Follow ${song.user.username} on Soundcloud:
109128
🔉${song.user.permalink_url}
110129
130+
The background image used in this video is provided by ${
131+
imageData.user.name
132+
} from Unsplash:
133+
🔗Follow ${imageData.user.name} on Unsplash - ${imageData.user.links.html}
134+
📂Download this background - ${imageData.links.html}
135+
111136
🎵 DatSongBot is a bot built by Buzzertech (https://buzzertech.com) which picks a new, trending song from soundcloud and uploads it to YouTube. This is an experimental tool. With that being said, be sure to subscribe to DatSongBot on YouTube and turn on notifications 'cause we post new music daily on this channel!
112137
113-
❌ DatSongBot doesn't owns this music. Just for entertainment purposes only!
138+
❌ DatSongBot doesn't owns this music nor the image used in this video. Just for entertainment purposes only!
114139
115140
Cheers 🎵
116141
`;
117142

118-
export const uploadVideo = (song: Track) => {
143+
export const uploadVideo = (
144+
song: PickedTrack,
145+
imageData: IUnsplashResponse
146+
) => {
119147
const songTitle =
120148
song.title.replace(/(")|(')|(\.)/g, '').trim() + ` | ${song.user.username}`;
121149

122-
const description = getDescription(songTitle, song);
150+
const description = getDescription(songTitle, song, imageData);
123151
return youtube.videos.insert({
124152
part: 'snippet, status',
125153
requestBody: {

0 commit comments

Comments
 (0)