1
0

FileMetadata.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. #include "metadata/svc_metadata.h"
  3. #include "metadata/ifc_metadata.h"
  4. #include "nswasabi/ServiceName.h"
  5. #include "nx/nxuri.h"
  6. #include "nx/nxfile.h"
  7. #include "nsid3v2/nsid3v2.h"
  8. #include "nsid3v1/nsid3v1.h"
  9. #include "nsapev2/nsapev2.h"
  10. #include "nswasabi/ID3v2Metadata.h"
  11. #include "nswasabi/APEv2Metadata.h"
  12. #include "nswasabi/ID3v1Metadata.h"
  13. #include "ifc_filemetadata_editor.h"
  14. // {6FCF1A5A-79D0-4FB8-9911-222638CA32A1}
  15. static const GUID file_metadata_guid =
  16. { 0x6fcf1a5a, 0x79d0, 0x4fb8, { 0x99, 0x11, 0x22, 0x26, 0x38, 0xca, 0x32, 0xa1 } };
  17. class FileMetadataService : public svc_metadata
  18. {
  19. public:
  20. WASABI_SERVICE_NAME("File Metadata");
  21. WASABI_SERVICE_GUID(file_metadata_guid);
  22. private:
  23. int WASABICALL MetadataService_EnumerateExtensions(unsigned int index, nx_string_t *extension);
  24. int WASABICALL MetadataService_CreateMetadata(unsigned int pass, nx_uri_t filename, ifc_metadata **metadata);
  25. int WASABICALL MetadataService_CreateMetadataEditor(unsigned int pass, nx_uri_t filename, ifc_metadata_editor **metadata);
  26. };
  27. class FileMetadata
  28. {
  29. public:
  30. ns_error_t SetFileInformation(nx_uri_t filename, nx_file_stat_t file_stat);
  31. ns_error_t FindMetadata(nx_file_t file);
  32. bool HasMetadata() const; // returns whether or not there was any metadata found
  33. protected:
  34. FileMetadata();
  35. ~FileMetadata();
  36. ns_error_t OwnID3v2(nsid3v2_tag_t id3v2, uint64_t position, uint64_t length);
  37. ns_error_t OwnID3v1(nsid3v1_tag_t id3v1, uint64_t position, uint64_t length);
  38. ns_error_t OwnAPEv2(nsapev2_tag_t apev2, uint64_t position, uint64_t length);
  39. ns_error_t OwnLyrics3(void *lyrics, uint64_t position, uint64_t length);
  40. nx_uri_t filename;
  41. nx_file_stat_s file_stat;
  42. template <class tag_t>
  43. class MetaTag
  44. {
  45. public:
  46. MetaTag() : tag(0), position(0), length(0) {}
  47. tag_t tag;
  48. uint64_t position;
  49. uint64_t length;
  50. };
  51. /* ID3v2 */
  52. MetaTag<nsid3v2_tag_t> id3v2;
  53. ID3v2Metadata id3v2_metadata;
  54. /* ID3v1 */
  55. MetaTag<nsid3v1_tag_t> id3v1;
  56. ID3v1Metadata id3v1_metadata;
  57. /* APEv2 */
  58. MetaTag<nsapev2_tag_t> apev2;
  59. APEv2Metadata apev2_metadata;
  60. MetaTag<void *> lyrics3;
  61. uint64_t start_position;
  62. uint64_t content_length;
  63. uint64_t end_position;
  64. };
  65. class FileMetadataRead : public FileMetadata, public ifc_metadata
  66. {
  67. private:
  68. int WASABICALL Metadata_GetField(int field, unsigned int index, nx_string_t *value);
  69. int WASABICALL Metadata_GetInteger(int field, unsigned int index, int64_t *value);
  70. int WASABICALL Metadata_GetReal(int field, unsigned int index, double *value);
  71. int WASABICALL Metadata_GetArtwork(int field, unsigned int index, artwork_t *artwork, data_flags_t flags);
  72. int WASABICALL Metadata_GetBinary(int field, unsigned int index, nx_data_t *data);
  73. int WASABICALL Metadata_GetMetadata(int field, unsigned int index, ifc_metadata **metadata);
  74. int WASABICALL Metadata_Serialize(nx_data_t *data);
  75. };
  76. class FileMetadataWrite : public FileMetadata, public ifc_metadata_editor
  77. {
  78. public:
  79. FileMetadataWrite();
  80. ~FileMetadataWrite();
  81. int Initialize(ifc_filemetadata_editor *editor);
  82. private:
  83. /* ifc_metadata_editor implementation */
  84. int WASABICALL MetadataEditor_Save();
  85. int WASABICALL MetadataEditor_SaveAs(nx_uri_t destination);
  86. int WASABICALL MetadataEditor_SetField(int field, unsigned int index, nx_string_t value);
  87. int WASABICALL MetadataEditor_SetInteger(int field, unsigned int index, int64_t value);
  88. int WASABICALL MetadataEditor_SetReal(int field, unsigned int index, double value);
  89. int WASABICALL MetadataEditor_SetArtwork(int field, unsigned int index, artwork_t *artwork, data_flags_t flags);
  90. int MakeID3v2();
  91. ifc_filemetadata_editor *editor;
  92. };