Skip to content

Commit e6bf223

Browse files
committed
feat: add ffmpeg installer
1 parent dfcf2e2 commit e6bf223

File tree

5 files changed

+1804
-64
lines changed

5 files changed

+1804
-64
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
"trailingComma": "es5"
3030
},
3131
"devDependencies": {
32+
"@types/aws-lambda": "^8.10.27",
3233
"@types/debug": "^4.1.4",
3334
"@types/fluent-ffmpeg": "^2.1.9",
3435
"@types/fs-extra": "^7.0.0",
3536
"@types/jest": "^24.0.13",
3637
"@types/lodash": "^4.14.134",
3738
"@types/puppeteer": "^1.12.4",
3839
"@types/qs": "^6.5.3",
40+
"aws-sdk": "^2.476.0",
3941
"husky": "^2.3.0",
4042
"prettier": "^1.17.1",
4143
"pretty-quick": "^1.10.0",
@@ -44,6 +46,7 @@
4446
"typescript": "^3.4.5"
4547
},
4648
"dependencies": {
49+
"@ffmpeg-installer/ffmpeg": "^1.0.18",
4750
"axios": "^0.19.0",
4851
"date-fns": "^1.30.1",
4952
"debug": "^4.1.1",
@@ -52,6 +55,7 @@
5255
"googleapis": "^40.0.0",
5356
"lodash": "^4.17.11",
5457
"puppeteer": "^1.17.0",
55-
"qs": "^6.7.0"
58+
"qs": "^6.7.0",
59+
"serverless": "^1.45.1"
5660
}
5761
}

src/index.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@ import { getTracksFromSoundcloud } from './audio';
1010
import { getUnsplashPhoto } from './image';
1111
import { resolve } from 'path';
1212
import { videoLogger } from './lib/utils';
13+
import { Handler } from 'aws-lambda';
1314

14-
const test = async () => {
15-
launchPage();
16-
const song = await getTracksFromSoundcloud();
17-
const image = await getUnsplashPhoto(song.tag_list);
18-
const svgContent = prepareSvg(
19-
image.urls.custom,
20-
song.title.replace(/(")|(')|(\.)/g, ''),
21-
song.user.username
22-
);
23-
await generateImage(svgContent);
24-
await processVideo(song, resolve(__dirname, '../assets/out.png'));
25-
const response = await uploadVideo(song, image);
15+
export const main: Handler = async () => {
16+
try {
17+
launchPage();
18+
const song = await getTracksFromSoundcloud();
19+
const image = await getUnsplashPhoto(song.tag_list);
20+
const svgContent = prepareSvg(
21+
image.urls.custom,
22+
song.title.replace(/(")|(')|(\.)/g, ''),
23+
song.user.username
24+
);
25+
await generateImage(svgContent);
26+
await processVideo(song, resolve(__dirname, '../assets/out.png'));
27+
const response = await uploadVideo(song, image);
2628

27-
videoLogger(`Video has been uploaded!`);
28-
videoLogger(`Youtube video id - ${response.data.id}`);
29-
};
29+
videoLogger(`Video has been uploaded!`);
30+
videoLogger(`Youtube video id - ${response.data.id}`);
3031

31-
test().catch(e => {
32-
console.log('errored');
33-
console.error(e);
34-
closePage();
35-
});
32+
closePage();
33+
} catch (e) {
34+
console.error(e);
35+
}
36+
};

src/video.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { addDays } from 'date-fns';
88
import { createReadStream, stat } from 'fs-extra';
99
import { IUnsplashResponse } from 'image';
1010
import { imageLogger, videoLogger, durationToSeconds } from './lib/utils';
11+
import installer from '@ffmpeg-installer/ffmpeg';
12+
13+
ffmpeg.setFfmpegPath(installer.path);
1114

1215
const oauthclient = new google.auth.OAuth2({
1316
clientId: config.YOUTUBE_CLIENT_ID,
@@ -46,7 +49,7 @@ export const prepareSvg = (
4649

4750
return `
4851
<style>html,body{margin: 0; padding: 0;}</style>
49-
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap&text=${songName}${artistName}" rel="stylesheet">
52+
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap&text=${songName.toUpperCase()}${artistName.toUpperCase()}" rel="stylesheet">
5053
<svg viewBox="0 0 1920 1080" lang="en-US" xmlns="http://www.w3.org/2000/svg">
5154
<defs>
5255
<linearGradient id="bottomGrad" x1="0%" y1="0%" x2="0%" y2="100%">
@@ -56,8 +59,10 @@ export const prepareSvg = (
5659
</defs>
5760
<image href="${bgUrl}" x="0" y="0" width="100%" height="100%" />
5861
<rect x="0" y="40%" width="100%" height="60%" fill="url(#bottomGrad)"/>
59-
<text x="${textX}" style="font-family: 'Poppins', arial; font-weight: bold; font-size: 5em;" y="90%" fill="white">${songName}</text>
60-
<text x="${textX}" style="font-family: 'Poppins', arial; font-size: 3em; font-weight: 300;" y="95%" fill="white">${artistName}</text>
62+
<text x="${textX}" style="font-family: 'Poppins', arial; font-weight: bold; font-size: 5em;" y="90%" fill="white">${songName.toUpperCase()}</text>
63+
<text x="${textX}" style="font-family: 'Poppins', arial; font-size: 3em; font-weight: 300;" y="95%" fill="white">${
64+
artistName.toUpperCase
65+
}</text>
6166
</svg>
6267
`;
6368
};

types/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module '@ffmpeg-installer/ffmpeg' {
2+
interface Installer {
3+
path: string;
4+
version: string;
5+
url: string;
6+
}
7+
8+
var installer: Installer;
9+
10+
export = installer;
11+
}

0 commit comments

Comments
 (0)