1
0

albumart.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "../../Library/ml_pmp/pmp.h"
  2. #include "api.h"
  3. #include "../agave/albumart/svc_albumartprovider.h"
  4. #include <api/service/waservicefactory.h>
  5. extern PMPDevicePlugin plugin;
  6. static svc_albumArtProvider *FindProvider(const wchar_t *filename, int providerType, waServiceFactory **factory)
  7. {
  8. FOURCC albumartprovider = svc_albumArtProvider::getServiceType();
  9. int n = (int)plugin.service->service_getNumServices(albumartprovider);
  10. for (int i=0; i<n; i++)
  11. {
  12. waServiceFactory *sf = plugin.service->service_enumService(albumartprovider,i);
  13. if (sf)
  14. {
  15. svc_albumArtProvider * provider = (svc_albumArtProvider*)sf->getInterface();
  16. if (provider)
  17. {
  18. if (provider->ProviderType() == providerType && provider->IsMine(filename))
  19. {
  20. *factory = sf;
  21. return provider;
  22. }
  23. sf->releaseInterface(provider);
  24. }
  25. }
  26. }
  27. return NULL;
  28. }
  29. void CopyAlbumArt(const wchar_t *source, const wchar_t *destination)
  30. {
  31. size_t datalen = 0;
  32. void *data = 0;
  33. wchar_t *mimeType = 0;
  34. waServiceFactory *destinationFactory = 0;
  35. svc_albumArtProvider *destinationProvider = FindProvider(destination, ALBUMARTPROVIDER_TYPE_EMBEDDED, &destinationFactory);
  36. if (destinationFactory)
  37. {
  38. /* First, look to see if there's already embedded album art */
  39. if (destinationProvider->GetAlbumArtData(destination, L"cover", &data, &datalen, &mimeType) == ALBUMARTPROVIDER_SUCCESS && data && datalen)
  40. {
  41. destinationFactory->releaseInterface(destinationProvider);
  42. WASABI_API_MEMMGR->sysFree(data);
  43. WASABI_API_MEMMGR->sysFree(mimeType);
  44. return;
  45. }
  46. else if (AGAVE_API_ALBUMART->GetAlbumArtData(source, L"cover", &data, &datalen, &mimeType) == ALBUMART_SUCCESS && data && datalen)
  47. {
  48. destinationProvider->SetAlbumArtData(destination, L"cover", data, datalen, mimeType);
  49. WASABI_API_MEMMGR->sysFree(data);
  50. WASABI_API_MEMMGR->sysFree(mimeType);
  51. destinationFactory->releaseInterface(destinationProvider);
  52. }
  53. }
  54. }