Skip to content

Commit

Permalink
fix cutted files because in album art flow
Browse files Browse the repository at this point in the history
  • Loading branch information
moshfeu committed Oct 15, 2019
1 parent 2c6ee61 commit a9d8ae5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/services/youtube-mp3-downloader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as async from 'async';
import * as progress from 'progress-stream';
import { audioFormats, videoFormats } from './options';
import { settingsManager } from '../settings';
import { unlinkSync, rename } from 'fs';

function YoutubeMp3Downloader(options) {
const self = this;
Expand Down Expand Up @@ -179,20 +180,27 @@ YoutubeMp3Downloader.prototype.performDownload = function(task, callback) {
resultObj.thumbnail = thumbnail;

if (settingsManager.albumArt) {
const tempFileName = fileName.replace(resultObj.title, `${resultObj.title}-ac`);

ffmpeg(fileName)
.on('error', e => {
console.error('error in adding cover', JSON.stringify(e, null, 2))
callback(e, resultObj);
})
.on('end', () => {
callback(null, resultObj);
console.log('end in adding cover')
// once the new file saved, delete the original (w/o the album art) and rename the new to the original name
unlinkSync(fileName);
rename(tempFileName, fileName, () => ({}));
console.log('end in adding cover');
})
.addInput(resultObj.thumbnail)
.addOutputOption(["-map", '0:0'])
.addOutputOption(["-map", '1:0'])
.addOutputOption('-c', 'copy')
.saveToFile(fileName);
// has to save it in a different name otherwise, ffmpeg take only the first 2 seconds (weird behaviour)
.saveToFile(tempFileName);

} else {
callback(null, resultObj);
}
Expand Down

0 comments on commit a9d8ae5

Please sign in to comment.