AlbumArt.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #include "main.h"
  2. #include "../nu/AutoWide.h"
  3. #include "AlbumArt.h"
  4. #include "util.h"
  5. #include <shlwapi.h>
  6. #include <strsafe.h>
  7. bool ASF_AlbumArtProvider::IsMine(const wchar_t *filename)
  8. {
  9. const wchar_t *ext = PathFindExtension(filename);
  10. if (ext && *ext)
  11. {
  12. ext++;
  13. return fileTypes.GetAVType(ext) != -1;
  14. }
  15. return false;
  16. }
  17. int ASF_AlbumArtProvider::ProviderType()
  18. {
  19. return ALBUMARTPROVIDER_TYPE_EMBEDDED;
  20. }
  21. bool NameToAPICType(const wchar_t *name, int &num)
  22. {
  23. if (!name || !*name) // default to cover
  24. num=0x3;
  25. else if (!_wcsicmp(name, L"fileicon")) // 32x32 pixels 'file icon' (PNG only)
  26. num=0x1;
  27. else if (!_wcsicmp(name, L"icon")) // Other file icon
  28. num=0x2;
  29. else if (!_wcsicmp(name, L"cover")) // Cover (front)
  30. num=0x3;
  31. else if (!_wcsicmp(name, L"back")) // Cover (back)
  32. num=0x4;
  33. else if (!_wcsicmp(name, L"leaflet")) // Leaflet page
  34. num=0x5;
  35. else if (!_wcsicmp(name, L"media")) // Media (e.g. lable side of CD)
  36. num=0x6;
  37. else if (!_wcsicmp(name, L"leadartist")) //Lead artist/lead performer/soloist
  38. num=0x7;
  39. else if (!_wcsicmp(name, L"artist")) // Artist/performer
  40. num=0x8;
  41. else if (!_wcsicmp(name, L"conductor")) // Conductor
  42. num=0x9;
  43. else if (!_wcsicmp(name, L"band")) // Band/Orchestra
  44. num=0xA;
  45. else if (!_wcsicmp(name, L"composer")) // Composer
  46. num=0xB;
  47. else if (!_wcsicmp(name, L"lyricist")) // Lyricist/text writer
  48. num=0xC;
  49. else if (!_wcsicmp(name, L"location")) // Recording Location
  50. num=0xD;
  51. else if (!_wcsicmp(name, L"recording")) // During recording
  52. num=0xE;
  53. else if (!_wcsicmp(name, L"performance")) // During performance
  54. num=0xF;
  55. else if (!_wcsicmp(name, L"preview")) // Movie/video screen capture
  56. num=0x10;
  57. else if (!_wcsicmp(name, L"fish")) // A bright coloured fish
  58. num=0x11;
  59. else if (!_wcsicmp(name, L"illustration")) // Illustration
  60. num=0x12;
  61. else if (!_wcsicmp(name, L"artistlogo")) // Band/artist logotype
  62. num=0x13;
  63. else if (!_wcsicmp(name, L"publisherlogo")) // Publisher/Studio logotype
  64. num=0x14;
  65. else
  66. return false;
  67. return true;
  68. }
  69. int ASF_AlbumArtProvider::GetAlbumArtData(const wchar_t *filename, const wchar_t *type, void **bits, size_t *len, wchar_t **mimeType)
  70. {
  71. int pictype;
  72. if (NameToAPICType(type, pictype))
  73. {
  74. WMInformation wm(filename);
  75. if (wm.GetPicture(bits, len, mimeType, pictype))
  76. return ALBUMARTPROVIDER_SUCCESS;
  77. }
  78. return ALBUMARTPROVIDER_FAILURE;
  79. }
  80. int ASF_AlbumArtProvider::SetAlbumArtData(const wchar_t *filename, const wchar_t *type, void *bits, size_t len, const wchar_t *mimeType)
  81. {
  82. int pictype;
  83. if (NameToAPICType(type, pictype))
  84. {
  85. WMInformation wm(filename);
  86. if (!wm.MakeWritable(filename))
  87. return ALBUMARTPROVIDER_READONLY; // can't write
  88. if (wm.SetPicture(bits, len, mimeType, pictype))
  89. {
  90. wm.Flush();
  91. return ALBUMARTPROVIDER_SUCCESS;
  92. }
  93. }
  94. return ALBUMARTPROVIDER_FAILURE;
  95. }
  96. int ASF_AlbumArtProvider::DeleteAlbumArt(const wchar_t *filename, const wchar_t *type)
  97. {
  98. int pictype;
  99. if (NameToAPICType(type, pictype))
  100. {
  101. WMInformation wm(filename);
  102. if (!wm.MakeWritable(filename))
  103. {
  104. if (wm.HasPicture(pictype))
  105. return ALBUMARTPROVIDER_READONLY; // can't write
  106. else
  107. return ALBUMARTPROVIDER_FAILURE;
  108. }
  109. if (wm.DeletePicture(pictype))
  110. {
  111. wm.Flush();
  112. return ALBUMARTPROVIDER_SUCCESS;
  113. }
  114. }
  115. return ALBUMARTPROVIDER_FAILURE;
  116. }
  117. #define CBCLASS ASF_AlbumArtProvider
  118. START_DISPATCH;
  119. CB(SVC_ALBUMARTPROVIDER_PROVIDERTYPE, ProviderType);
  120. CB(SVC_ALBUMARTPROVIDER_GETALBUMARTDATA, GetAlbumArtData);
  121. CB(SVC_ALBUMARTPROVIDER_SETALBUMARTDATA, SetAlbumArtData);
  122. CB(SVC_ALBUMARTPROVIDER_DELETEALBUMART, DeleteAlbumArt);
  123. CB(SVC_ALBUMARTPROVIDER_ISMINE, IsMine);
  124. END_DISPATCH;
  125. #undef CBCLASS
  126. static ASF_AlbumArtProvider albumArtProvider;
  127. // {B4184902-EE79-4015-B9A4-76209C6153FA}
  128. static const GUID asf_albumartproviderGUID =
  129. { 0xb4184902, 0xee79, 0x4015, { 0xb9, 0xa4, 0x76, 0x20, 0x9c, 0x61, 0x53, 0xfa } };
  130. FOURCC AlbumArtFactory::GetServiceType()
  131. {
  132. return svc_albumArtProvider::SERVICETYPE;
  133. }
  134. const char *AlbumArtFactory::GetServiceName()
  135. {
  136. return "ASF Album Art Provider";
  137. }
  138. GUID AlbumArtFactory::GetGUID()
  139. {
  140. return asf_albumartproviderGUID;
  141. }
  142. void *AlbumArtFactory::GetInterface(int global_lock)
  143. {
  144. return &albumArtProvider;
  145. }
  146. int AlbumArtFactory::SupportNonLockingInterface()
  147. {
  148. return 1;
  149. }
  150. int AlbumArtFactory::ReleaseInterface(void *ifc)
  151. {
  152. //plugin.service->service_unlock(ifc);
  153. return 1;
  154. }
  155. const char *AlbumArtFactory::GetTestString()
  156. {
  157. return 0;
  158. }
  159. int AlbumArtFactory::ServiceNotify(int msg, int param1, int param2)
  160. {
  161. return 1;
  162. }
  163. #ifdef CBCLASS
  164. #undef CBCLASS
  165. #endif
  166. #define CBCLASS AlbumArtFactory
  167. START_DISPATCH;
  168. CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
  169. CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
  170. CB(WASERVICEFACTORY_GETGUID, GetGUID)
  171. CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
  172. CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface)
  173. CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
  174. CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
  175. CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
  176. END_DISPATCH;