index.js
function getItunesTracks(librarypath) {
    var libraryID;
    var trackObj = {};
    var isTrack = false;
    var line;
    var trackCount = 0;
    var streamIn;
    var streamOut = new stream_1.Readable;
    streamOut._read = function () { };
    streamIn = fs.createReadStream(librarypath);
    streamIn.on('error', function () { return streamOut.emit("error", 'The file you selected does not exist'); });
    streamIn = byline.createStream(streamIn);
    /*
    if (!module.exports.validPath(librarypath)) {
        streamOut.emit("error", 'Not a valid XML file')
    }
    */
    streamIn.on('readable', function () {
        while (null !== (line = streamIn.read())) {
            if (line.indexOf("<key>Library Persistent ID</key>") > -1) {
                /* ADD A KEY/VALUE PROPERTY */
                var iDString = String(line).match("<key>Library Persistent ID</key><string>(.*)</string>");
                libraryID = iDString[1];
            }
            else if (line.indexOf("<dict>") > -1) {
                /* START A NEW TRACK */
                trackObj = {};
                isTrack = true;
            }
            else if (line.indexOf("<key>") > -1) {
                /* ADD A PROPERTY TO THE TRACK */
                Object.assign(trackObj, module.exports.buildProperty(line));
            }
            else if (line.indexOf("</dict>") > -1) {
                /* END OF CURRENT TRACK */
                if (module.exports.objectIsMusicTrack(trackObj)) {
                    trackObj['Library Persistent ID'] = libraryID; //add extra metadata
                    trackCount++;
                    streamOut.push(JSON.stringify(trackObj));
                }
                isTrack = false;
            }
        }
    });
    streamIn.on('end', function () {
        if (trackCount == 0)
            streamOut.emit("error", 'No tracks exist in the file');
        trackCount = 0; //reset it
        streamOut.push(null);
    });
    streamIn.on('error', function (err) {
        streamOut.emit("error", 'Error parsing iTunes XML');
    });
    return streamOut;
}
function getItunesTracks(librarypath) {
    var libraryID;
    var trackObj = {};
    var isTrack = false;
    var line;
    var trackCount = 0;
    var streamIn;
    var streamOut = new stream_1.Readable;
    streamOut._read = function () { };
    streamIn = fs.createReadStream(librarypath);
    streamIn.on('error', function () { return streamOut.emit("error", 'The file you selected does not exist'); });
    streamIn = byline.createStream(streamIn);
    /*
    if (!module.exports.validPath(librarypath)) {
        streamOut.emit("error", 'Not a valid XML file')
    }
    */
    streamIn.on('readable', function () {
        while (null !== (line = streamIn.read())) {
            if (line.indexOf("<key>Library Persistent ID</key>") > -1) {
                /* ADD A KEY/VALUE PROPERTY */
                var iDString = String(line).match("<key>Library Persistent ID</key><string>(.*)</string>");
                libraryID = iDString[1];
            }
            else if (line.indexOf("<dict>") > -1) {
                /* START A NEW TRACK */
                trackObj = {};
                isTrack = true;
            }
            else if (line.indexOf("<key>") > -1) {
                /* ADD A PROPERTY TO THE TRACK */
                Object.assign(trackObj, module.exports.buildProperty(line));
            }
            else if (line.indexOf("</dict>") > -1) {
                /* END OF CURRENT TRACK */
                if (module.exports.objectIsMusicTrack(trackObj)) {
                    trackObj['Library Persistent ID'] = libraryID; //add extra metadata
                    trackCount++;
                    streamOut.push(JSON.stringify(trackObj));
                }
                isTrack = false;
            }
        }
    });
    streamIn.on('end', function () {
        if (trackCount == 0)
            streamOut.emit("error", 'No tracks exist in the file');
        trackCount = 0; //reset it
        streamOut.push(null);
    });
    streamIn.on('error', function (err) {
        streamOut.emit("error", 'Error parsing iTunes XML');
    });
    return streamOut;
}
function getItunesTracks ( librarypath ) { var libraryID ; var trackObj = { } ; var isTrack = false ; var line ; var trackCount = 0 ; var streamIn ; var streamOut = new stream_1 . Readable ; streamOut . _read = function ( ) { } ; streamIn = fs . createReadStream ( librarypath ) ; streamIn . on ( 'error' , function ( ) { return streamOut . emit ( "error" , 'The file you selected does not exist' ) ; } ) ; streamIn = byline . createStream ( streamIn ) ; /*
    if (!module.exports.validPath(librarypath)) {
        streamOut.emit("error", 'Not a valid XML file')
    }
    */ streamIn . on ( 'readable' , function ( ) { while ( null !== ( line = streamIn . read ( ) ) ) { if ( line . indexOf ( "<key>Library Persistent ID</key>" ) > - 1 ) { /* ADD A KEY/VALUE PROPERTY */ var iDString = String ( line ) . match ( "<key>Library Persistent ID</key><string>(.*)</string>" ) ; libraryID = iDString [ 1 ] ; } else if ( line . indexOf ( "<dict>" ) > - 1 ) { /* START A NEW TRACK */ trackObj = { } ; isTrack = true ; } else if ( line . indexOf ( "<key>" ) > - 1 ) { /* ADD A PROPERTY TO THE TRACK */ Object . assign ( trackObj , module . exports . buildProperty ( line ) ) ; } else if ( line . indexOf ( "</dict>" ) > - 1 ) { /* END OF CURRENT TRACK */ if ( module . exports . objectIsMusicTrack ( trackObj ) ) { trackObj [ 'Library Persistent ID' ] = libraryID ; //add extra metadata trackCount ++ ; streamOut . push ( JSON . stringify ( trackObj ) ) ; } isTrack = false ; } } } ) ; streamIn . on ( 'end' , function ( ) { if ( trackCount == 0 ) streamOut . emit ( "error" , 'No tracks exist in the file' ) ; trackCount = 0 ; //reset it streamOut . push ( null ) ; } ) ; streamIn . on ( 'error' , function ( err ) { streamOut . emit ( "error" , 'Error parsing iTunes XML' ) ; } ) ; return streamOut ; }
Creates an stream of JSON tracks from an iTunes Library XML file.

@param  String
@return ReadableStream of JSON objects
Creates an stream of JSON tracks from an iTunes Library XML file .