Winamp5ArtworkManager.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "Winamp5ArtworkManager.h"
  2. #include "api__wasabi2.h"
  3. #include "metadata/MetadataKeys.h"
  4. #include "nswasabi/ReferenceCounted.h"
  5. int Winamp5ArtworkManager::Artwork_GetArtwork(nx_uri_t filename, unsigned int field, artwork_t *artwork, data_flags_t flags, nx_time_unix_64_t *filename_modified)
  6. {
  7. if (!AGAVE_API_ALBUMART)
  8. return NErr_FailedCreate;
  9. if (field != MetadataKeys::ALBUM)
  10. return NErr_Unknown;
  11. if (filename_modified)
  12. {
  13. struct __stat64 buffer;
  14. if (_wstat64(filename->string, &buffer) == 0)
  15. {
  16. *filename_modified = buffer.st_atime;
  17. }
  18. else
  19. {
  20. *filename_modified = 0;
  21. }
  22. }
  23. wchar_t *mime_type;
  24. void *bits;
  25. size_t len;
  26. int ret = AGAVE_API_ALBUMART->GetAlbumArtData(filename->string, L"cover", &bits, &len, &mime_type);
  27. if (ret != 0)
  28. return NErr_Empty;
  29. NXDataCreate(&artwork->data, bits, len);
  30. WASABI_API_MEMMGR->sysFree(bits);
  31. if (mime_type)
  32. {
  33. ReferenceCountedNXString mime_type_nx;
  34. NXStringCreateWithUTF16(&mime_type_nx, mime_type);
  35. NXDataSetMIME(artwork->data, mime_type_nx);
  36. WASABI_API_MEMMGR->sysFree(mime_type);
  37. }
  38. artwork->height = 0;
  39. artwork->width = 0;
  40. return NErr_Success;
  41. }