Sonerezh Album Covers

Sonerezh is a self-hosted music streaming platform that is still fairly young. It works very well, until I recently updated to PHP7. I had to manually update the CakePHP libraries that came with it to get past a error “String is a built in function”. After I fixed that error, I decided to try and get the album cover images working.

By default Sonerezh pulls the album covers from the mp3 files themselves via the ID3 info, but I don’t keep those tags when I clean my mp3 files up I have the album art stored as ‘folder.jpg’ in the album folder itself. So I started to dig around and came up with a simple solution that works for me.

Edit the file SongsController.php inside the app/Controllers folder. Around line 93 or so it starts with pulling the photos out of the ID3 information. I added a new section and commented out the old, as displayed below:

            if (!empty($songInfo['comments']['genre'])) {
                $genre_array_length = count($songInfo['comments']['genre']);
                $newSong['genre'] = $songInfo['comments']['genre'][$genre_array_length - 1];
            }

            $extension = 'jpg';
            $name = md5($newSong['artist'].$newSong['album']);
            $path = IMAGES.THUMBNAILS_DIR.DS.$name.'.'.$extension;

            if (!file_exists($path)) {
                if (!file_exists(IMAGES.THUMBNAILS_DIR)) {
                    new Folder(IMAGES.THUMBNAILS_DIR, true, 0777);
                }
                if (copy("/...music path here.../".$newSong['artist']."/folder.jpg", $path)) {
                    $newSong['cover'] = $name.'.'.$extension;
                }
            }
/*
            if (isset($songInfo['comments']['picture'])) {
                if (isset($songInfo['comments']['picture'][0]['image_mime'])) {
                    $mime = preg_split('/\//', $songInfo['comments']['picture'][0]['image_mime']);
                    $extension = $mime[1];
                } else {
                    $extension = 'jpg';
                }

                $name = md5($newSong['artist'].$newSong['album']);
                $path = IMAGES.THUMBNAILS_DIR.DS.$name.'.'.$extension;

                if (!file_exists($path)) {
                    if (!file_exists(IMAGES.THUMBNAILS_DIR)) {
                        new Folder(IMAGES.THUMBNAILS_DIR, true, 0777);
                    }
                    $file = fopen($path, "w");
                    fwrite($file, $songInfo['comments']['picture'][0]['data']);
                    fclose($file);
                }
                $newSong['cover'] = $name.'.'.$extension;
            }
*/
        }

        if (!isset($newSong['title'])) {

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation