Thread: [Solved] ffmpeg mp3
View Single Post
  #20  
Old 25.10.2019, 17:35
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 853
Default

@smokiemamour,
  1. Click 'edit' to open the script editor and create a new script
  2. Clear any contents which are present in the editor
  3. Copy and paste the contents which are in the following "code" box.
  4. Save the script
  5. In the Eventscripter panel, select "A Download Stopped" trigger from the drop down box in the "Trigger" column.
  6. Double-click the field in the 'name' column to specify a name for the script (optional)
  7. Enable the script 'checkbox'
Code:
// 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);
        }
    }
}

When aac/m4a/ogg file is downloaded, the script will automatically convert it into mp3.

If you are still having problem running the script, you can also contact me in JD Chat:
Code:
webchat.freenode.net//#jdownloader?nick=JD_00?
Reply With Quote