AlbumArt.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. ** Copyright © 2007-2014 Winamp SA
  3. **
  4. ** This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held
  5. ** liable for any damages arising from the use of this software.
  6. **
  7. ** Permission is granted to anyone to use this software for any purpose, including commercial applications, and to
  8. ** alter it and redistribute it freely, subject to the following restrictions:
  9. **
  10. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
  11. ** If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  12. **
  13. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  14. **
  15. ** 3. This notice may not be removed or altered from any source distribution.
  16. **
  17. ** Author: Ben Allison [email protected]
  18. ** Created: July 25, 2007
  19. **
  20. */
  21. #include "main.h"
  22. #include "api__in_flv.h"
  23. #include "Metadata.h"
  24. #include "../nu/AutoWide.h"
  25. #include "AlbumArt.h"
  26. #include <shlwapi.h>
  27. #include <strsafe.h>
  28. bool FLAC_AlbumArtProvider::IsMine(const wchar_t *filename)
  29. {
  30. const wchar_t *extension = PathFindExtensionW(filename);
  31. if (extension && *extension)
  32. {
  33. wchar_t exts[128] = {0};
  34. GetPrivateProfileStringW(L"in_flac", L"extensions", DEFAULT_EXTENSIONSW, exts, 128, winampINI);
  35. extension++;
  36. wchar_t *b = exts;
  37. wchar_t *c;
  38. do
  39. {
  40. wchar_t d[20] = {0};
  41. StringCchCopyW(d, 15, b);
  42. if ((c = wcschr(b, L';')))
  43. {
  44. if ((c-b)<15)
  45. d[c - b] = 0;
  46. }
  47. if (!lstrcmpiW(extension, d))
  48. return true;
  49. b = c + 1;
  50. }
  51. while (c);
  52. }
  53. return false;
  54. }
  55. int FLAC_AlbumArtProvider::ProviderType()
  56. {
  57. return ALBUMARTPROVIDER_TYPE_EMBEDDED;
  58. }
  59. bool NameToAPICType(const wchar_t *name, FLAC__StreamMetadata_Picture_Type &num)
  60. {
  61. if (!name || !*name) // default to cover
  62. num=FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER;
  63. else if (!_wcsicmp(name, L"fileicon")) // 32x32 pixels 'file icon' (PNG only)
  64. num=FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD;
  65. else if (!_wcsicmp(name, L"icon")) // Other file icon
  66. num=FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON;
  67. else if (!_wcsicmp(name, L"cover")) // Cover (front)
  68. num=FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER;
  69. else if (!_wcsicmp(name, L"back")) // Cover (back)
  70. num=FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER;
  71. else if (!_wcsicmp(name, L"leaflet")) // Leaflet page
  72. num=FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE;
  73. else if (!_wcsicmp(name, L"media")) // Media (e.g. lable side of CD)
  74. num=FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA;
  75. else if (!_wcsicmp(name, L"leadartist")) //Lead artist/lead performer/soloist
  76. num=FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST;
  77. else if (!_wcsicmp(name, L"artist")) // Artist/performer
  78. num=FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST;
  79. else if (!_wcsicmp(name, L"conductor")) // Conductor
  80. num=FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR;
  81. else if (!_wcsicmp(name, L"band")) // Band/Orchestra
  82. num=FLAC__STREAM_METADATA_PICTURE_TYPE_BAND;
  83. else if (!_wcsicmp(name, L"composer")) // Composer
  84. num=FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER;
  85. else if (!_wcsicmp(name, L"lyricist")) // Lyricist/text writer
  86. num=FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST;
  87. else if (!_wcsicmp(name, L"location")) // Recording Location
  88. num=FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION;
  89. else if (!_wcsicmp(name, L"recording")) // During recording
  90. num=FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING;
  91. else if (!_wcsicmp(name, L"performance")) // During performance
  92. num=FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE;
  93. else if (!_wcsicmp(name, L"preview")) // Movie/video screen capture
  94. num=FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE;
  95. else if (!_wcsicmp(name, L"fish")) // A bright coloured fish
  96. num=FLAC__STREAM_METADATA_PICTURE_TYPE_FISH;
  97. else if (!_wcsicmp(name, L"illustration")) // Illustration
  98. num=FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION;
  99. else if (!_wcsicmp(name, L"artistlogo")) // Band/artist logotype
  100. num=FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE;
  101. else if (!_wcsicmp(name, L"publisherlogo")) // Publisher/Studio logotype
  102. num=FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE;
  103. else
  104. return false;
  105. return true;
  106. }
  107. int FLAC_AlbumArtProvider::GetAlbumArtData(const wchar_t *filename, const wchar_t *type, void **bits, size_t *len, wchar_t **mimeType)
  108. {
  109. FLACMetadata metadata;
  110. if (metadata.Open(filename))
  111. {
  112. FLAC__StreamMetadata_Picture_Type pictype;
  113. if (NameToAPICType(type, pictype))
  114. {
  115. if (metadata.GetPicture(pictype, bits, len, mimeType))
  116. return ALBUMARTPROVIDER_SUCCESS;
  117. }
  118. }
  119. return ALBUMARTPROVIDER_FAILURE;
  120. }
  121. int FLAC_AlbumArtProvider::SetAlbumArtData(const wchar_t *filename, const wchar_t *type, void *bits, size_t len, const wchar_t *mimeType)
  122. {
  123. if (!info || info && _wcsicmp(filename, info->filename))
  124. {
  125. FLACMetadata metadata;
  126. if (metadata.Open(filename))
  127. {
  128. FLAC__StreamMetadata_Picture_Type pictype;
  129. if (NameToAPICType(type, pictype))
  130. {
  131. if (metadata.SetPicture(pictype, bits, len, mimeType, 0/*TODO*/, 0/*TODO*/))
  132. {
  133. if (metadata.Save(filename))
  134. return ALBUMARTPROVIDER_SUCCESS;
  135. else
  136. return ALBUMARTPROVIDER_FAILURE;
  137. }
  138. }
  139. }
  140. }
  141. else
  142. {
  143. FLAC__StreamMetadata_Picture_Type pictype;
  144. if (NameToAPICType(type, pictype))
  145. {
  146. if (info->metadata.SetPicture(pictype, bits, len, mimeType, 0/*TODO*/, 0/*TODO*/))
  147. {
  148. return ALBUMARTPROVIDER_SUCCESS;
  149. }
  150. }
  151. }
  152. return ALBUMARTPROVIDER_FAILURE;
  153. }
  154. int FLAC_AlbumArtProvider::DeleteAlbumArt(const wchar_t *filename, const wchar_t *type)
  155. {
  156. if (!info || info && _wcsicmp(filename, info->filename))
  157. {
  158. FLACMetadata metadata;
  159. if (metadata.Open(filename))
  160. {
  161. FLAC__StreamMetadata_Picture_Type pictype;
  162. if (NameToAPICType(type, pictype))
  163. {
  164. if (info->metadata.RemovePicture(pictype))
  165. {
  166. if (info->metadata.Save(filename))
  167. return ALBUMARTPROVIDER_SUCCESS;
  168. else
  169. return ALBUMARTPROVIDER_FAILURE;
  170. }
  171. }
  172. }
  173. }
  174. else
  175. {
  176. FLAC__StreamMetadata_Picture_Type pictype;
  177. if (NameToAPICType(type, pictype))
  178. {
  179. if (info->metadata.RemovePicture(pictype))
  180. {
  181. return ALBUMARTPROVIDER_SUCCESS;
  182. }
  183. }
  184. }
  185. return ALBUMARTPROVIDER_FAILURE;
  186. }
  187. #define CBCLASS FLAC_AlbumArtProvider
  188. START_DISPATCH;
  189. CB(SVC_ALBUMARTPROVIDER_PROVIDERTYPE, ProviderType);
  190. CB(SVC_ALBUMARTPROVIDER_GETALBUMARTDATA, GetAlbumArtData);
  191. CB(SVC_ALBUMARTPROVIDER_ISMINE, IsMine);
  192. CB(SVC_ALBUMARTPROVIDER_SETALBUMARTDATA, SetAlbumArtData);
  193. CB(SVC_ALBUMARTPROVIDER_DELETEALBUMART, DeleteAlbumArt);
  194. END_DISPATCH;
  195. #undef CBCLASS
  196. static FLAC_AlbumArtProvider albumArtProvider;
  197. // {622C3B42-866E-4935-AA52-3B456AE8B036}
  198. static const GUID flac_albumartproviderGUID =
  199. { 0x622c3b42, 0x866e, 0x4935, { 0xaa, 0x52, 0x3b, 0x45, 0x6a, 0xe8, 0xb0, 0x36 } };
  200. FOURCC AlbumArtFactory::GetServiceType()
  201. {
  202. return svc_albumArtProvider::SERVICETYPE;
  203. }
  204. const char *AlbumArtFactory::GetServiceName()
  205. {
  206. return "FLAC Album Art Provider";
  207. }
  208. GUID AlbumArtFactory::GetGUID()
  209. {
  210. return flac_albumartproviderGUID;
  211. }
  212. void *AlbumArtFactory::GetInterface(int global_lock)
  213. {
  214. return &albumArtProvider;
  215. }
  216. int AlbumArtFactory::SupportNonLockingInterface()
  217. {
  218. return 1;
  219. }
  220. int AlbumArtFactory::ReleaseInterface(void *ifc)
  221. {
  222. //plugin.service->service_unlock(ifc);
  223. return 1;
  224. }
  225. const char *AlbumArtFactory::GetTestString()
  226. {
  227. return 0;
  228. }
  229. int AlbumArtFactory::ServiceNotify(int msg, int param1, int param2)
  230. {
  231. return 1;
  232. }
  233. #define CBCLASS AlbumArtFactory
  234. START_DISPATCH;
  235. CB(WASERVICEFACTORY_GETSERVICETYPE, GetServiceType)
  236. CB(WASERVICEFACTORY_GETSERVICENAME, GetServiceName)
  237. CB(WASERVICEFACTORY_GETGUID, GetGUID)
  238. CB(WASERVICEFACTORY_GETINTERFACE, GetInterface)
  239. CB(WASERVICEFACTORY_SUPPORTNONLOCKINGGETINTERFACE, SupportNonLockingInterface)
  240. CB(WASERVICEFACTORY_RELEASEINTERFACE, ReleaseInterface)
  241. CB(WASERVICEFACTORY_GETTESTSTRING, GetTestString)
  242. CB(WASERVICEFACTORY_SERVICENOTIFY, ServiceNotify)
  243. END_DISPATCH;
  244. #undef CBCLASS