leetreveil / musicmetadata

Streaming music metadata parser for node and the browser.
561 stars 66 forks source link

Callback is never called #146

Open dnish opened 7 years ago

dnish commented 7 years ago

Hey when parsing this file https://en.wikipedia.org/wiki/File:ACDC_-_Back_In_Black-sample.ogg - the callback doesn't fire. It's just hanging without any error message.

Tarabass commented 7 years ago

First off, the url you are using is returning a HTML document. If you want the media file you should use this url: https://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg

Second, when I use this code I am getting an error (off course) and the callback is not called:

musicmetadata('https://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg', function(error, metadata) {
    if(error)
        throw error

    console.log(metadata)
})

This is because the error occurred on the first argument, which is not a stream and don't has the pipe function. The error is catch-able though:

try {
    musicmetadata('https://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg', function(error, metadata) {
        if(error)
            throw error

        console.log(metadata)
    })
}
catch(err) {
    console.log('Error occurred', err)
}

Maybe musicmetadata should catch it and return it?

Tarabass commented 7 years ago

Created a solution to this problem: https://github.com/leetreveil/musicmetadata/pull/148

Hopefully the maintainer will merge it..

Tarabass commented 7 years ago

Didn't not test it, but I guess you could something like this using the request library:

request({
    url: 'https://upload.wikimedia.org/wikipedia/en/4/45/ACDC_-_Back_In_Black-sample.ogg',
    encoding: null
}, function (error, response, body) {
    if(error)
        throw error

    var fileStream = fs.createReadStream('ACDC_-_Back_In_Black-sample.ogg')

    musicmetadata(fileStream, { duration: true }, function(err, metadata) {
        if(err)
            throw err

        console.log(metadata)
        fileStream.close()
    })
})
.pipe(fs.createWriteStream('ACDC_-_Back_In_Black-sample.ogg'))
dnish commented 7 years ago

Oh, we are using the fork "music-metadata" instead. This solved the issue and we are able to handle all files without problems.