Album Art using ID3 for Libretime

Hey guys! I ran into this script not too long ago and I will experiment with it. How would you feel about having artwork on tracks?

I understand we could simply use an API to fetch it via Apple Music or another service, but in some cases it’s not enough. So I added support for ID3 tags using getID3 that allow us to do more with tracks, even modify the actual tracks.

I have an app that uses Apple Music to fetch the artwork, but in some cases some tracks are not available (custom, exclusives, etc…) therefor no artwork is available, well the solution was simple, if no track was found in Apple Music then the app fetches the artwork from my server. It’s why I think it should be included. Besides it looks great and give Libretime a little bit of life, being able to see an image attached to the file.

Watch my fork here: https://github.com/codenift/libretime.

It is still very buggy, not completed, but works… Don’t use on a production server yet. Test it, optimize it, improve on it, so we can make this better. Let me know. It can handle loading images quickly for the 100 tracks limit on each page it already queries. For testing, make sure the tracks all have artwork on it. I just did some quick tests and forgot to fix the fallback if it has no artwork. I wasn’t able to upload many of my tracks, maybe an issue with the formatting that needs to get checked, so for testing I had to delete a few of them and upload again. Incase it hangs in the library, just go to Settings > General and in Dangerous Options delete all files. Don’t upload the file that made it hang. This will be fixed in a update.

TODO:

  • Option to not show images in Library, I had this setup in Library columns but it showed the little sorting arrows so I just removed it for now.

  • Drag & drop artwork to the image that’s already there in edit tab using AJAX. Writes data URI into the existing file I set up for artwork. We’re not saving the data URI into database. Now with getID3 we can include artwork inside MP3 file if we wanted to, I know it may not be necessary if nothing is being moved but if something happens or just want to download at least all files will have updated data. And since Libretime has option to download then I think it makes sense.

  • Add artwork next to the current track being played on the top .

  • Scan and update tracks that don’t have artwork set? To have when updating a previous production Libretime.

  • Right click on artwork inside edit tab with option to fetch artwork in MP3

Any thoughts?

I like the idea of aggregating and displaying artwork. Does you solution manage the artwork directly in the files or just in the UI?

The legwork for getting the artwork and storing it should probably be done somewhere in the python parts where there already is code that interacts with ID3 tags. Usually LibreTime has been doing stuff like this in libretime_analyzer and then posting the results to the php api server.

I think the artwork could also be useful in the now-playing widget in some way, I’m not sure if Apple Music T&Cs allow using their images in that way though.

Yes. The artwork is being fetched from the audio file and the Data URI for image is then saved into a file instead of saving into the database, only the path is saved into the cc_files table (eg. imported/1/artwork/artwork-file), i think it’s faster this way and not bloat the database. With getID3 we can also write back directly to the audio file if we wanted to incase someone just wants to replace the artwork with something else. Would just need to do a drag and drop feature on the image itself so that it saves into audio and also updates the Data URI. I’m not a python guy so I kinda avoid looking that way, still studying Libretime itself.

Yes, definitely! That’s the idea. One of the reasons I started it. I’ll push an update in a few since I already managed to set it up nicely on the top for Current Playing songs. So it will just need to be set up in the widget.

As far as Apple, that would be something you do only if developing an app with them. I created an app that is in the App Store for my radio station and uses SamCloud for the service, I fetch artwork from Apple and when it’s not available it fetches the artwork from SamCloud, but I will be switching to Libretime since I have more control here. So the idea is to have all the songs in Libretime using the artwork from MP3s. If you have an app then you can fetch artwork from Apple (which allows it) and if it’s not available in Apple Music it will then fetch the artwork from Libretime with a simple if and else rule. And of course if in Android, you can then make the app fetch from Google Music or other services …or just fetch everything from Libretime for any app or widgets.

Just an update on the artwork feature. Still needs some cleanup.

As far as making this happen with Python in metadata_analyzer, the only way I would see it working is by passing the Data URI and saving it into a bytea column which is what I was trying to prevent since that will just bloat the database, unless you’ll able to make it the same way I have it where it grabs the data and saves into in a file then save the path to the the database instead. I’m not too experienced with Python so I chose to do it this way, since we’re able to use the same library later to do more tasks in PHP such as write back to the file when uploading new artwork using AJAX. Either way, I guess I could work on my example just to get it out there as a proof of concept.

Video: https://youtu.be/yTJy5QcvKDs

ALL FIXED NOW :boom:

TODO:

  • Option to change/reset artwork from the edit tab (reset would just get artwork from file if available incase it is changed or never been set)

  • Setting page with option to scan through files and update previous imported files before this feature? :thinking: Incase it is used on a live server and not trying to “reset” it one by one.

Nice to read this.
Yes, this would give some color to Libretime.
Maybe it’s useful to write the small jpeg into the audio file during the file import process.
This will be complementary with a future option to analyze BPM and write the values into the file tags.
Alternatively we can create a new folder for Album Arts with album-titel.jpeg and write the link in database. Both systems are used in classical radio applications. I think it’s more useful when the cover picture is going out with the streaming of the audio file. So we can show the pictures easily in new DAB receivers. I am very interested by this future. Please do it if it’s possible.

I did change it a bit and now it adds a jpg additionally to the Data URI during import since I was having trouble showing it in my iOS app and needed to retrieve as a jpg instead, and using Data URI only within the LB. To get the JPG I had to add to the existing API where I can just retrieve metadata from any track by ID, so you would get it like this:
https://your-site/api/track?id=1276&return=artwork and I guess if add option for thumbnails later on we could just have it with “_32” and “_64” added to the end. It’s currently being saved in imported/artwork/

I was planning to add the option to add/change that artwork in the file this week, still need to add a few more things such as deleting the linked artwork files if a track is deleted.

thank you very much for this positive information. Artwork in Libretime will be nice.
I’m new coming to Libretime and make much experimentation to understand how thing are organized and working. In the beginning I imported many audio files before I saw that it will be much better to make BPM analyzing/writing to audio files in front of this. So I deleted my maybe 20’000 audio files In Dashboard-Tracks again. Taking a look in /srv/airtime/stor/imported I can see in folder1 that there are still staying 5852 elements. This are the folders and sub folders using 4,9 Go with no audio files inside. How can I erase them without making trouble in Libretime database?
I hope this can be fixes too.
During experimentation with Libretime, I’m writing a french language manual how to work with Airtime.
We need this for our new community radio project in Avignon, south of France. I hope to contribute with testing Libretime and making translations to this wonderful project.

Yes, I agree. I’m actually experimenting with a few things I need for my station and BPM is one of the things I need, this way we can use them in smart blocks, I’m also experimenting with waveforms in edit tab, seeing how you can already cue in and out and I believe it will be much easier for us to actually see what’s going on and use sliders in the waveform to cue in and out, because we could have hundreds of songs and it would be hard to tell if one has empty space. I also think we have to look into ReplayGain, it’s just not working for me. I have a lot audio files that sound low. I think we need some kind of control for track individually that way we can use a slider for up/down on waveform controlling gain.

As far as your files, if you were trying to delete all your tracks. You can do that in Settings>General> and the very last option “Dangerous Options/Delete All Tracks” that should get rid of everything.

If you still see files in stor/imported then you could just remove it at this point. This will empty the directory.
rm -r /srv/airtime/stor/imported/*

Yes it worked fine.
I did dangerous operation and deleted all Tracks. Now in dashboard tracks I can see no more tracks.
The folders /srv/airtime/stor/imported/ was still keeping the empty folders.
sudo rm -r /srv/airtime/stor/imported/* cleaned all.
Now I can start again importing tracks, but I think this is not a general good solution.
I think it needs in the end of deleting tracks procedure the command to delete empty folders too.
Same like it’s done in EasyBrainz Picard. (I’m working with Xubuntu 16.04 and Libretime-Master)

Yes. Adding a function to check if it’s the only track remaining of the album should do the trick, if true then remove it on the fly… and perhaps adding a Clean option that will remove empty subfolders, just incase for people that already have them.