|
|
@@ -27,7 +27,10 @@ const convert = (url, filename, id) => {
|
|
27
|
27
|
if (err) {
|
|
28
|
28
|
console.log(url);
|
|
29
|
29
|
console.error(err);
|
|
30
|
|
- Converted.update({ _id: id }, { $set: { error: 'Video is unreachable' } });
|
|
|
30
|
+ Converted.update({ _id: id }, { $set: {
|
|
|
31
|
+ error_video: 'Video is unreachable',
|
|
|
32
|
+ error_audio: 'Video is unreachable',
|
|
|
33
|
+ } });
|
|
31
|
34
|
} else {
|
|
32
|
35
|
const totalSeconds = info ? info.length_seconds : 0;
|
|
33
|
36
|
const dl = ytdl(url);
|
|
|
@@ -35,7 +38,7 @@ const convert = (url, filename, id) => {
|
|
35
|
38
|
ffmpeg(dl)
|
|
36
|
39
|
.noVideo()
|
|
37
|
40
|
.on('end', Meteor.bindEnvironment(() => {
|
|
38
|
|
- Converted.update({ _id: id }, { $set: { audio: audioPath, audio_progress: 100 } });
|
|
|
41
|
+ Converted.update({ _id: id }, { $set: { audio: filename + '.mp3', audio_progress: 100 } });
|
|
39
|
42
|
}))
|
|
40
|
43
|
.on('progress', Meteor.bindEnvironment((params) => {
|
|
41
|
44
|
const time = moment(new Date(...[0, 0, 0, ...params.timemark.split(':')]));
|
|
|
@@ -43,7 +46,10 @@ const convert = (url, filename, id) => {
|
|
43
|
46
|
let percent = ((seconds / totalSeconds) * 100).toFixed(0);
|
|
44
|
47
|
Converted.update({ _id: id }, { $set: { audio_progress: percent } });
|
|
45
|
48
|
}))
|
|
46
|
|
- .on('error', (err) => { console.error('MP3 encoding error: ' + err.message); })
|
|
|
49
|
+ .on('error', Meteor.bindEnvironment((err) => {
|
|
|
50
|
+ console.error('MP3 encoding error: ' + err.message);
|
|
|
51
|
+ Converted.update({ _id: id }, { $set: { error_audio: 'Audio cannot be extracted' } });
|
|
|
52
|
+ }))
|
|
47
|
53
|
.format('mp3')
|
|
48
|
54
|
.output(fs.createWriteStream(audioPath))
|
|
49
|
55
|
.run();
|
|
|
@@ -57,9 +63,12 @@ const convert = (url, filename, id) => {
|
|
57
|
63
|
Converted.update({ _id: id }, { $set: { video_progress: (percent * 100).toFixed(0) } });
|
|
58
|
64
|
}));
|
|
59
|
65
|
res.on('end', Meteor.bindEnvironment(() => {
|
|
60
|
|
- Converted.update({ _id: id }, { $set: { video: videoPath, video_progress: 100 } });
|
|
|
66
|
+ Converted.update({ _id: id }, { $set: { video: filename + '.mp4', video_progress: 100 } });
|
|
|
67
|
+ }));
|
|
|
68
|
+ res.on('error', Meteor.bindEnvironment((err) => {
|
|
|
69
|
+ console.error('Error: ' + err.message)
|
|
|
70
|
+ Converted.update({ _id: id }, { $set: { error_video: 'Video cannot be saved' } });
|
|
61
|
71
|
}));
|
|
62
|
|
- res.on('error', (err) => { console.error('Error: ' + err.message) });
|
|
63
|
72
|
}));
|
|
64
|
73
|
}
|
|
65
|
74
|
}));
|
|
|
@@ -73,19 +82,24 @@ Meteor.methods({
|
|
73
|
82
|
check(type, Match.Where(t => ['audio'].includes(t)));
|
|
74
|
83
|
|
|
75
|
84
|
let converted = Converted.findOne({
|
|
76
|
|
- url: video.url
|
|
|
85
|
+ url: video.url,
|
|
|
86
|
+ error_audio: { $ne: null },
|
|
|
87
|
+ error_video: { $ne: null },
|
|
77
|
88
|
});
|
|
78
|
89
|
|
|
79
|
90
|
if (!converted) {
|
|
80
|
91
|
const filename = video.title.replace(/ /g, '_');
|
|
|
92
|
+ Converted.remove({url: video.url});
|
|
81
|
93
|
var inserted_id = Converted.insert({
|
|
82
|
94
|
id: video.id,
|
|
83
|
95
|
url: video.url,
|
|
84
|
96
|
title: video.title,
|
|
85
|
97
|
video: '',
|
|
86
|
98
|
video_progress: 0,
|
|
|
99
|
+ error_video: '',
|
|
87
|
100
|
audio: '',
|
|
88
|
101
|
audio_progress: 0,
|
|
|
102
|
+ error_audio: '',
|
|
89
|
103
|
createdAt: new Date()
|
|
90
|
104
|
});
|
|
91
|
105
|
convert(video.url, filename, inserted_id);
|