View Single Post
  #1363  
Old 12.05.2020, 20:37
zreenmkr zreenmkr is offline
JD Addict
 
Join Date: Feb 2020
Posts: 174
Default

Quote:
Originally Posted by martian View Post
Hi all. I'm very new to this and it was recommended to me that I ask the question in this thread. I've used JD2 to download a series of music (.acc and .ogg) files from Youtube playlists so that I can load them into Traktor. The problem is that they won't load because they lack ID3 tags.

I have no real idea what I'm doing here; but might anyone be able to help with a script that could create those tags? A massive thanks for any advice here!
Quote:
Originally Posted by mgpai View Post
It is not possible to add ID3 tags to those formats, since neither of them support that tag type. Also, metadata is not necessary to play media files. It should play just fine without them. Only the song information will not be displayed by the player.

Most likely, the player (or the version of the player) you are using does not have the necessary codecs to play the files...
yep, as mgpai pointed out, possibly codec issue, try this hxxps://codecguide.com/download_kl.htm

if still curious on adding ID3v2 Tags to future downloads give this a try, it's nice to have embed metadata.
Code:
//Add ID3v2 Tags to Youtube Audio Files Includes AAC* & OGG* (w/ffmpeg)
//Trigger: A Download Stopped
//
//IMPORTANT:
//      must config Youtube Plugin with this preset
//      Goto:   [Settings > Plugins > (choose) Youtube > Filename to Audio files > (copy and paste custom audio preset below here)]
//      Preset: [track=`*PLAYLIST_POSITION*`;title=`*TITLE*`;artist=`*USERNAME*`;album=`*PLAYLIST_NAME*`;date=`*DATE*`;.*EXT*] <--without square brackets
//
//      add or remove ID3v2 tags pattern must follow this format:
//      [ffmpegKeyForID3v2Tag=`*YOUTUBE FileNames/PackageNames*`;] <--without square brackets
//
//      ffmpegKeyForID3v2Tags found here > hxxps://gist.github.com/eyecatchup/0757b3d8b989fe433979db2ea7d95a01
//      YOUTUBE FileNames/PackageNames properties are found in [Settings > Plugins > (choose) Youtube > (scroll down toward the bottom)]
//
//NOTE* ffmpeg cant set ID3v2 tags to some audio formats directly e.g aac&ogg but have no problems with container e.g m4a
//      hence this script will wrap aac&ogg file in m4a container then add ID3v2 tags that way
//
//      After finished crawling File Name will be temporary hold Id3v2 metadata retrieved. It'll be messy at first both in DL/LG
//          e.g [track=`0001`;title=`Song Title (Official Video)`;artist=`Uploader Name`;album=`Playlist Name`;date=`Uploaded Date`;.aac]
//      Once finished downloading Id3v2 tags will be applied then custom File Name will be set as [sTrack - sTitle - sArtist - sDate]
//          e.g [0001 - Song Title (Official Video) - Uploader Name - Uploaded Date.acc]           
//

//--------------------------------------------------------
disablePermissionChecks(); //no prompting persmision dialog

var hoster = link.getHost();

if (hoster == 'youtube.com') {
    
    var regexAudioExt = /.+\.(aac|ogg|mp3)$/ig; //<-- add/remove audio file extensions
    var isFinished = link.isFinished();
    var fileName = link.getName();
    var fileExt = fileName.replace(regexAudioExt, '$1');

    if (fileExt && isFinished && hoster == 'youtube.com') {

        var sTrack = '';
        var sTitle = '';
        var sArtist = '';
        var sDate = '';
        var metaData = '';
        var fileDir = link.getPackage().getDownloadFolder();
        var filePath = getPath(fileDir + '/' + fileName)

        var regexMetadata = /^(?:^|\s+)?(track|title|artist|album|date|author_url|comment|copyright)(=`.+`)(?:^|\s+)?$/ig; //<--add/remove ffmpeg keys for ID3v2 tags
        var regexYear = /^(date=`).+(\d{4}`)$/ig;

        var regexFile = /^(.*?)\..{2,4}$/ig;
        var string = fileName.replace(regexFile, '$1');

        string.split(';').forEach(function(tag) {
            var tagTmp = tag;
            //if (regexMetadata.test(tagTmp)) { //this fails when string contains utf-8
            if (tag.match(regexMetadata)) {
                if (regexYear.test(tag)) tagTmp = tag.replace(regexYear, '$1$2');
                if (/^track=/.test(tag)) sTrack = tag.replace(/.+\=`(.+)`$/, '$1 - ');
                if (/^title=/.test(tag)) sTitle = tag.replace(/.+\=`(.+)`$/, '$1 - ');
                if (/^artist=/.test(tag)) sArtist = tag.replace(/.+\=`(.+)`$/, '$1 - ');
                if (/^date=/.test(tag)) sDate = tag.replace(/.+\=`(.+)`$/, '$1');

                tagTmp = tagTmp.replace(/`$/g, '"');
                tagTmp = tagTmp.replace(/=`/g, '="');
                if (tagTmp.length) metaData += ' -metadata ' + tagTmp;
            }
        })

        var m4aExt = 'm4a'
        var newFileName = sTrack + sTitle + sArtist + sDate + ' [' + m4aExt + ']' + '.' + fileExt //Custum final file name
        var m4aContainer = sTrack + sTitle + sArtist + sDate + ' [' + m4aExt + ']' + '.' + m4aExt
        var newFileNameWithNoID3Set = sTrack + sTitle + sArtist + sDate + '.' + fileExt //Custum final file name
        var m4aContainerPath = getPath(fileDir + '/' + m4aContainer);
        var newFilePath = getPath(fileDir + '/' + newFileName);

        //var ffmpeg = callAPI("config", "get", "org.jdownloader.controlling.ffmpeg.FFmpegSetup", null, "binarypath"); //download ffmpeg
        var ffmpeg = getPath(JD_HOME + '/tools/Windows/ffmpeg/x64/ffmpeg.exe');
        var ffmpegID3Cmd = getPath(fileDir + '/setID3' + newFileName + '.cmd');

        if (ffmpeg.exists() && filePath.exists()) {

            //Option 1 - will fail with some filename contains none ASCII chars or filename is too long.
            //vbs or ps1 might fix this issue.
            var deleteOrigFile = '\n\r' + 'del "' + filePath + '"'
            var deleteBatchCmd = '\n\r' + 'del "' + ffmpegID3Cmd + '"'
            var renameBacktoOrigExt = '\n\r' + 'ren "' + m4aContainerPath + '" *.' + fileExt //m4aExt > fileExt
            var windowsId3v2dot3comp = ' -id3v2_version 3 -write_id3v1 1 ';

            if (/.+\.(aac|ogg)$/ig.test(fileName)) {
                var ffmpegId3 = '"' + ffmpeg + '" -i "' + filePath + '" ' + metaData + windowsId3v2dot3comp + ' "' + m4aContainerPath + '"' //wrap audio file(s) in m4a container
                var cmd = ffmpegId3 + renameBacktoOrigExt + deleteOrigFile + deleteBatchCmd;
            } else {
                var ffmpegId3 = '"' + ffmpeg + '" -i "' + filePath + '" ' + metaData + windowsId3v2dot3comp + ' "' + newFilePath + '"'
                var cmd = ffmpegId3 + deleteOrigFile + deleteBatchCmd;
            }

            try {
                deleteFile(ffmpegID3Cmd, false);
                writeFile(ffmpegID3Cmd, cmd, false);
                callSync(ffmpegID3Cmd);
                link.setName(newFileName)
            } catch (e) {
                deleteFile(ffmpegID3Cmd, false);
                link.setName(newFileNameWithNoID3Set) //failed wrapping audio file in m4aExt and no Id3v2 tags applied (occurrs on some non ASCII file names/long file names)
            }

            //Option 2 - not working (inputs welcome)
            //callAsync(ffmpeg, '-i', filePath, '-metadata title="Test Set Title"', newFilePath);
            //callAsync(ffmpeg, '-i', filePath, metaData, newFilePath);

        }
    }
}

Last edited by zreenmkr; 13.05.2020 at 03:21. Reason: added host and container check
Reply With Quote