Author Topic: Retrieving artwork  (Read 31888 times)

Reonekot

  • Guest
How does the different _GetArtwork functions work? I can't seem to get them to return anything, even though the now playing panel and the Now playing popup contain images. (My cover images are mostly jpg's, named as "Artist - Album - Front.jpg" in the song folder.)

What I have tried so far:
artwork = mbApiInterface.NowPlaying_GetArtwork();
artwork = mbApiInterface.Library_GetArtwork(fileUrl, 0);
artwork = mbApiInterface.Library_GetFileTag(fileUrl, MetaDataType.Artwork);

(Btw. running v2.1.4733.)

Thanks!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
i was thinking of something else when i said the url is now returned - infact its unchanged and returns a base64 encoded string

base64Text = mbApiInterface.NowPlaying_GetArtwork();
or
base64Text = mbApiInterface.Library_GetArtwork(fileUrl, 0);

artwork = (Bitmap)bitmapConverter.ConvertFrom(Convert.FromBase64String(base64Text))

both functions should be working and are used by at least 2 plugins

Reonekot

  • Guest
Hmm looks like NowPlaying_GetArtwork(); does work sometimes. I wonder why it sometimes returns null though, even though the now playing popup does show an albumart?

Btw., what is the index parameter for in mbApiInterface.Library_GetArtwork(fileUrl, index) ?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
index is the picture index for when a music file has multiple pictures - the function will return null when the index exceeds the number of pictures available.
There is a slight inconsistency between the NowPlaying_GetArtwork() function and the MusicBee sidebar artwork. When there is no artwork linked to a music file the API will return null whereas the sidebar artwork does a folder search to retrieve any folder.jpg (or other .jpg files if configured in the Tags(1) artwork retrieval preferences). I have changed the API so it is consistent

The other difference is the sidebar auto-downloads missing artwork. To get the same functionality from the API use this approach:

base64Text = mbApiInterface.NowPlaying_GetArtwork()
if base64Text == null
   // check if any artwork is already downloaded - if not you will receive a notification when it has downloaded
   base64Text = mbApiInterface.NowPlaying_GetDownloadedArtwork()
...

void ReceiveNotification(sourceFileUrl, NotificationType)
{
...
   case NotificationType.NowPlayingArtworkReady:
      base64Text = mbApiInterface.NowPlaying_GetDownloadedArtwork()
...
}




Reonekot

  • Guest
Thanks got it working when artwork is downloaded now, though not for subsequent requests for the artwork. Will wait and see if next version doesn't fix it for me. Thank you for the help.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
this updated version of MB has the tweaked  NowPlaying_GetArtwork() function
http://musicbee.niblseed.com/V2_1/MusicBee_Exe_Patched.zip

if you are still experiencing problems then can you give me a detailed description of the steps you are performing

Reonekot

  • Guest
That does seem to work much better, thanks. (Though I still have at least one album not returning an album, even though the Now playing panel shows an album. But I haven't been able to reproduce with more than one album so far...)

Here's what I'm doing:
String base64Artwork = mbApiInterface.NowPlaying_GetArtwork();
if (base64Artwork == null)
    base64Artwork = mbApiInterface.NowPlaying_GetDownloadedArtwork();
(+ receiving the NotificationType.NowPlayingArtworkReady event)

I wonder though, if I could just use the:
    base64Artwork = mbApiInterface.NowPlaying_GetDownloadedArtwork();
API though? Not sure if that will return the same as _GetArtwork()?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
NowPlaying_GetDownloadedArtwork() only returns downloaded artwork when it has been downloaded - you should use the approach as recommended before.
As to the one album picture not working, how is the artwork stored? (open the file in the tag editor, in the artwork tab click "save to" which will show how it is stored. If there is no artwork, is the picture in the music folder?

Reonekot

  • Guest
For some reason it only picked up the album art the first time a song from that album was played - anyway, I downloaded the album art to the folder now and it works. I'm mostly just curious about the difference between the API and what the now playing panel shows, but it seems to work pretty much as expected now I guess. Thanks for the help!

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
i have added Url equivalents in the next 2.1 update
Library_GetArtworkUrl()
NowPlaying_GetArtworkUrl()
NowPlaying_GetDownloadedArtworkUrl()

in cases where the artwork is embedded, MusicBee creates a temporary file and passes a link to that file. Although MusicBee will automatically clean up the temporary files when it exits, you could delete any files with ".tmp" on the end of the filename when finished with the picture. Of course any cases where the filename does not end in ".tmp" are pointing to existing user folder pictures and should be left untouched.

Grismar

  • Guest
In some other thread you mentioned not breaking the API as it stands. Does that mean that the changes you propose will be in addition to what is already in working order? (hope so, since I'm busy writing a plugin that uses just about every single API call you have to offer)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
all new API functions are added to the end of the interface lookup table and older plugins should not be affected.
The only breaking change i did make was in v2.1, the artist picture function now returns a url rather than a base64 string

Grismar

  • Guest
Understandable, although it does require an extra roundtrip in some cases. Would it be possible to have both with different function names? I kinda liked the zippy base64 function :(
Last Edit: January 07, 2013, 08:36:25 PM by Grismar

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
the artist pictures are already cached as files, and creating a massive base64 string is very bad for the .NET memory management - infact the new way is faster because the API doesnt need to read the file and convert to a string, so i dont plan to change it.

for album covers, you can still retrieve base64 strings using the existing APIs
Library_GetArtwork()
NowPlaying_GetArtwork()
NowPlaying_GetDownloadedArtwork()

the ...Url() variations are additional methods
Last Edit: January 07, 2013, 09:07:14 PM by Steven