-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
83 lines (69 loc) · 1.83 KB
/
index.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#! /usr/bin/env node
/**
* Main file of application. Giving a path to a folder of mp3s,
* tries to concat them together, create a video, and upload it to youtube.
* @example youtube-album-uploader "/path/to/music/folder"
* @example node index.js "/path/to/music/folder"
*/
var concatMp3s = require('./src/concatMp3s'),
albumInfo = require('./src/albumInfo'),
createVideoDescription = require('./src/createVideoDescription'),
convert = require('./src/convert'),
fs = require('fs'),
path = require('path'),
upload = require('./src/upload');
var albumDir = process.argv[2];
if(albumDir === undefined) {
console.log('Missing required path to album!');
return;
}
/**
* Removes any temporary files
*/
function cleanUp () {
if(fs.lstatSync('album.mp3').isFile()) {
fs.unlink('album.mp3');
}
if(fs.lstatSync('album.mp4').isFile()) {
fs.unlink('album.mp4');
}
}
albumInfo(albumDir, function (err, albumData) {
if(err) {
console.log(err);
return;
}
if(!albumData) {
console.log('Could not read metadata of mp3s in given directory.');
return;
}
console.log('Creating video (this will take awhile)...');
concatMp3s(albumDir, 'album.mp3', function(err, concatSuccess) {
if(err) {
console.log(err);
cleanUp();
return;
}
convert(albumData.albumArt, 'album.mp3', 'album.mp4', function(err, convertSuccess) {
if(err) {
console.log(err);
cleanUp();
return;
}
console.log('Uploading Video...');
var uploadOptions = {
title: albumData.artist + " - " + albumData.album + ' [FULL ALBUM]',
description: createVideoDescription(albumData.tracks)
};
upload('credentials.json', 'album.mp4', uploadOptions, function (err, videoObj) {
if(err) {
console.log(err);
cleanUp();
return;
}
console.log('Video uploaded successfully!');
cleanUp();
});
});
});
});