• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

CoverArt not working

Status
Not open for further replies.

Diverse

Member
Hey the
CoverArt 1.0 by Michael Friese <[email protected]> (metadata)
Automagically downloads album art from theaudiodb.com.

Script is not working for me. What i have to configure to make it work? Thanks
 

Syslog

New Member
Changed the script then it works fine for me. See the following code:

Code:
registerPlugin({
    name: 'CoverArt',
    version: '1.0',
    description: 'Automagically downloads album art from theaudiodb.com.',
    author: 'Michael Friese <[email protected]>',
    vars: {}
}, function(sinusbot, config) {
    var invalids = [];
    sinusbot.on('track', function(ev) {
        if (invalids.indexOf(ev.uuid) >= 0) return;
        if (ev.title != '' && ev.artist != '' && !ev.thumbnail && (ev.type === '' || ev.type == 'file')) {
            sinusbot.log('Searching for thumbnail for ' + ev.artist + ' - ' + ev.title);
           
            var out = sinusbot.http({ method: 'GET', url: 'http://www.theaudiodb.com/api/v1/json/1/searchtrack.php?s=' + encodeURIComponent(ev.artist) + '&t=' + encodeURIComponent(ev.title) }, function (err, res) {
           
                if(out) {
                    if (res && res.data) {
                        var ares = JSON.parse(res.data);
                        if (ares && ares.track && ares.track.length > 0) {
                            var track = ares.track[0];
                            sinusbot.log('AlbumTrackId: ' + track.idAlbum);
                                                       
                            var ret = http({ method: 'GET', url: 'http://www.theaudiodb.com/api/v1/json/1/album.php?m=' + track.idAlbum }, function (err, res) {
                               
                                if(ret) {
                                    if (res && res.data) {
                                        var ares = JSON.parse(res.data);
                                        if (ares && ares.album && ares.album.length > 0) {
                                            var album = ares.album[0];
                                            sinusbot.log('AlbumThumbUrl: ' + album.strAlbumThumb);
                                           
                                            if (sinusbot.downloadTrackThumbnail(ev.uuid, album.strAlbumThumb)) {
                                                sinusbot.log('Updated thumbnail!');
                                            } else {
                                                sinusbot.log('Thumbnail failed!');
                                                invalids.push(ev.uuid);
                                            }   
                                        }
                                        else {
                                            sinusbot.log('2:(ares && ares.album && ares.album.length > 0)==null');
                                            invalids.push(ev.uuid);
                                        }
                                    }
                                    else {
                                        sinusbot.log('2:(res && res.data)==null');
                                        invalids.push(ev.uuid);
                                    }
                                }
                                else {
                                    sinusbot.log('2:(ret)==null');
                                    invalids.push(ev.uuid);
                                }
                            });
                        }
                        else {
                            sinusbot.log('1:(ares && ares.track && ares.track.length > 0)==false');
                            invalids.push(ev.uuid);
                        }
                    }
                    else {
                        sinusbot.log('1:(res && res.data false)==false');
                        invalids.push(ev.uuid);
                    }
                }
                else {
                    sinusbot.log('1:(out)== null');
                    invalids.push(ev.uuid);
                }
            });
        }
    });
});
 
Status
Not open for further replies.
Top