View Single Post
  #18  
Old 17.11.2016, 17:23
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,533
Default

Replace 128kbit audio with 192kbit audio in 1080p youtube videos
  • The 1080p video file and 192kbit audio file must be placed in the same package and the package must contain only those two files.
  • Sometimes the actual bitrate of the downloaded audio file can be less than the bitrate stated in the variant. In "Advanced Settings", enable "Youtube.doextendedaudiobitratelookupenabled", to detect the actual audio bitrate before the file is downloaded.
Code:
// Replace 128kbit audio with 192kbit audio in 1080p youtube videos
// Trigger Required: "Package Finished"
// Forum Topic: https://board.jdownloader.org/showthread.php?t=69971

var links = package.getDownloadLinks();

if (links.length == 2) {
    var video = false;
    var audio = false;

    for (i = 0; i < links.length; i++) {
        var link = links[i];
        if (link.getHost() == "youtube.com") {
            var file = link.getDownloadPath();
            var variant = JSON.parse(link.getProperty("YT_VARIANT")).id;
            if ((/DEMUX.+192KBIT/i).test(variant)) {
                audio = file;
                var audioURL = link.getContainerURL();
            }
            if ((/1080P.+128KBIT/i).test(variant)) {
                video = file;
                var videoURL = link.getContainerURL();
                var out = (/128/).test(file) ? file.replace(/128/, "192") : file.replace(/(.+)(\..+)/, "$1 (192kbit Audio)$2");
            }
        }
    }

    if (video && audio && videoURL == audioURL) {
        var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath");
        callSync(ffmpeg, "-i", video, "-i", audio, "-c", "copy", "-map", "0:v:0", "-map", "1:a:0", out);
    }
}

Last edited by mgpai; 17.11.2016 at 18:21. Reason: Added fallback method for 'output' file name
Reply With Quote