View Single Post
  #1311  
Old 13.04.2020, 14:24
HeinerL HeinerL is offline
I will play nice!
 
Join Date: Apr 2020
Posts: 3
Default Convert to MP3 Event Scripter doesn't work

Hello,

I am new to this forum and no native speaker of English. So, hopefully I can convey my point in an understandable fashion.

I read on this board about the possibility to convert downloads to MP3 via the employment of the event scripter.
I also found the sticky thread with the event scripter scripts and the regarding script.

// Convert aac/m4a/ogg files to mp3.
// Trigger required: "A Download Stopped".
// Requires ffmpeg/ffprobe. Uses JD ffmpeg/ffprobe settings if available.
// Overwrites destination file (mp3) if it already exists.

if (link.isFinished()) {

var fileName = link.name.replace(/(.+)(\..+$)/, "$1");
var fileType = link.name.replace(/(.+)(\..+$)/, "$2");
var sourceFile = link.getDownloadPath();
var audioFile = /\.(aac|m4a|ogg)$/.test(sourceFile);

if (audioFile) {
var downloadFolder = package.getDownloadFolder();
var destFile = downloadFolder + "/" + fileName + ".mp3";
var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath");
var ffprobe = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypathprobe");
var data = JSON.parse(callSync(ffprobe, "-v", "quiet", "-print_format", "json", "-show_streams", "-show_format", sourceFile));
var streamsBitrate = data.streams[0].bit_rate ? data.streams[0].bit_rate : 0;
var formatBitrate = data.format.bit_rate ? data.format.bit_rate : 0;
var bitrate = Math.max(streamsBitrate, formatBitrate) / 1000;
var deleteSourceFile = false; // Set this to true to delete source file after conversion.

if (bitrate > 0) {
callSync(ffmpeg, "-y", "-i", sourceFile, "-b:a", bitrate + "k", destFile);
if (deleteSourceFile && getPath(destFile).exists()) deleteFile(sourceFile, false);
}
}
}

I have to admit that I have not the first idea about scripting at all. So, I copied and pasted the script into the event scripter.

When I click on testrun it says it failed because in line 6 the link is not defined. I think it's the line which I highlighted. I did the highlighting just in this post not in the event scripter.

I don't know how to fix this problem but I hope you can help me with this.

I appreciate you took the time to read this.

Greetings
Reply With Quote