Skip to content

Commit

Permalink
feat: add ffmpeg installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Buzzertech committed Jun 17, 2019
1 parent dfcf2e2 commit e6bf223
Show file tree
Hide file tree
Showing 5 changed files with 1,804 additions and 64 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
"trailingComma": "es5"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.27",
"@types/debug": "^4.1.4",
"@types/fluent-ffmpeg": "^2.1.9",
"@types/fs-extra": "^7.0.0",
"@types/jest": "^24.0.13",
"@types/lodash": "^4.14.134",
"@types/puppeteer": "^1.12.4",
"@types/qs": "^6.5.3",
"aws-sdk": "^2.476.0",
"husky": "^2.3.0",
"prettier": "^1.17.1",
"pretty-quick": "^1.10.0",
Expand All @@ -44,6 +46,7 @@
"typescript": "^3.4.5"
},
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.0.18",
"axios": "^0.19.0",
"date-fns": "^1.30.1",
"debug": "^4.1.1",
Expand All @@ -52,6 +55,7 @@
"googleapis": "^40.0.0",
"lodash": "^4.17.11",
"puppeteer": "^1.17.0",
"qs": "^6.7.0"
"qs": "^6.7.0",
"serverless": "^1.45.1"
}
}
41 changes: 21 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@ import { getTracksFromSoundcloud } from './audio';
import { getUnsplashPhoto } from './image';
import { resolve } from 'path';
import { videoLogger } from './lib/utils';
import { Handler } from 'aws-lambda';

const test = async () => {
launchPage();
const song = await getTracksFromSoundcloud();
const image = await getUnsplashPhoto(song.tag_list);
const svgContent = prepareSvg(
image.urls.custom,
song.title.replace(/(")|(')|(\.)/g, ''),
song.user.username
);
await generateImage(svgContent);
await processVideo(song, resolve(__dirname, '../assets/out.png'));
const response = await uploadVideo(song, image);
export const main: Handler = async () => {
try {
launchPage();
const song = await getTracksFromSoundcloud();
const image = await getUnsplashPhoto(song.tag_list);
const svgContent = prepareSvg(
image.urls.custom,
song.title.replace(/(")|(')|(\.)/g, ''),
song.user.username
);
await generateImage(svgContent);
await processVideo(song, resolve(__dirname, '../assets/out.png'));
const response = await uploadVideo(song, image);

videoLogger(`Video has been uploaded!`);
videoLogger(`Youtube video id - ${response.data.id}`);
};
videoLogger(`Video has been uploaded!`);
videoLogger(`Youtube video id - ${response.data.id}`);

test().catch(e => {
console.log('errored');
console.error(e);
closePage();
});
closePage();
} catch (e) {
console.error(e);
}
};
11 changes: 8 additions & 3 deletions src/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { addDays } from 'date-fns';
import { createReadStream, stat } from 'fs-extra';
import { IUnsplashResponse } from 'image';
import { imageLogger, videoLogger, durationToSeconds } from './lib/utils';
import installer from '@ffmpeg-installer/ffmpeg';

ffmpeg.setFfmpegPath(installer.path);

const oauthclient = new google.auth.OAuth2({
clientId: config.YOUTUBE_CLIENT_ID,
Expand Down Expand Up @@ -46,7 +49,7 @@ export const prepareSvg = (

return `
<style>html,body{margin: 0; padding: 0;}</style>
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap&text=${songName}${artistName}" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap&text=${songName.toUpperCase()}${artistName.toUpperCase()}" rel="stylesheet">
<svg viewBox="0 0 1920 1080" lang="en-US" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="bottomGrad" x1="0%" y1="0%" x2="0%" y2="100%">
Expand All @@ -56,8 +59,10 @@ export const prepareSvg = (
</defs>
<image href="${bgUrl}" x="0" y="0" width="100%" height="100%" />
<rect x="0" y="40%" width="100%" height="60%" fill="url(#bottomGrad)"/>
<text x="${textX}" style="font-family: 'Poppins', arial; font-weight: bold; font-size: 5em;" y="90%" fill="white">${songName}</text>
<text x="${textX}" style="font-family: 'Poppins', arial; font-size: 3em; font-weight: 300;" y="95%" fill="white">${artistName}</text>
<text x="${textX}" style="font-family: 'Poppins', arial; font-weight: bold; font-size: 5em;" y="90%" fill="white">${songName.toUpperCase()}</text>
<text x="${textX}" style="font-family: 'Poppins', arial; font-size: 3em; font-weight: 300;" y="95%" fill="white">${
artistName.toUpperCase
}</text>
</svg>
`;
};
Expand Down
11 changes: 11 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare module '@ffmpeg-installer/ffmpeg' {
interface Installer {
path: string;
version: string;
url: string;
}

var installer: Installer;

export = installer;
}
Loading

0 comments on commit e6bf223

Please sign in to comment.