nsid3v2.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #pragma once
  2. /* include any platform-specific stuff, first */
  3. #ifdef __ANDROID__
  4. #include "android/nsid3v2.h"
  5. #elif defined(_WIN32)
  6. #include "windows/nsid3v2.h"
  7. #elif defined(__linux__)
  8. #include "linux/nsid3v2.h"
  9. #elif defined(__APPLE__)
  10. #include "osx/nsid3v2.h"
  11. #endif
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. // must be exactly 10 bytes
  16. NSID3V2_EXPORT int NSID3v2_Header_Valid(const void *header_data);
  17. NSID3V2_EXPORT int NSID3v2_Header_FooterValid(const void *footer_data);
  18. NSID3V2_EXPORT int NSID3v2_Header_Create(nsid3v2_header_t *header, const void *header_data, size_t header_len);
  19. NSID3V2_EXPORT int NSID3v2_Header_New(nsid3v2_header_t *h, uint8_t version, uint8_t revision);
  20. /* Creates from footer data instead of header data */
  21. NSID3V2_EXPORT int NSID3v2_Header_FooterCreate(nsid3v2_header_t *footer, const void *footer_data, size_t footer_len);
  22. NSID3V2_EXPORT int NSID3v2_Header_TagSize(const nsid3v2_header_t header, uint32_t *tag_size);
  23. NSID3V2_EXPORT int NSID3v2_Header_HasFooter(const nsid3v2_header_t header);
  24. NSID3V2_EXPORT int NSID3v2_Header_Destroy(nsid3v2_header_t header);
  25. // currently, this function makes a copy of any necessary data. in the future, it would be better
  26. // to make another version of this function that "borrows" your data
  27. // if you can guarantee that the memory will outlive the nsid3v2_tag_t object
  28. NSID3V2_EXPORT int NSID3v2_Tag_Create(nsid3v2_tag_t *tag, const nsid3v2_header_t header, const void *bytes, size_t bytes_len);
  29. NSID3V2_EXPORT int NSID3v2_Tag_Destroy(nsid3v2_tag_t tag);
  30. NSID3V2_EXPORT int NSID3v2_Tag_GetFrame(const nsid3v2_tag_t tag, int frame_enum, nsid3v2_frame_t *frame);
  31. NSID3V2_EXPORT int NSID3v2_Tag_GetNextFrame(const nsid3v2_tag_t tag, const nsid3v2_frame_t start_frame, nsid3v2_frame_t *frame);
  32. NSID3V2_EXPORT int NSID3v2_Tag_RemoveFrame(nsid3v2_tag_t tag, nsid3v2_frame_t frame);
  33. NSID3V2_EXPORT int NSID3v2_Tag_CreateFrame(nsid3v2_tag_t tag, int frame_enum, int flags, nsid3v2_frame_t *frame);
  34. NSID3V2_EXPORT int NSID3v2_Tag_AddFrame(nsid3v2_tag_t tag, nsid3v2_frame_t frame);
  35. NSID3V2_EXPORT int NSID3v2_Tag_EnumerateFrame(const nsid3v2_tag_t tag, nsid3v2_frame_t position, nsid3v2_frame_t *frame);
  36. NSID3V2_EXPORT int NSID3v2_Tag_GetInformation(nsid3v2_tag_t tag, uint8_t *version, uint8_t *revision, int *flags);
  37. /*
  38. get specific information out of a tag. returns the first one found that matches the requirements.
  39. */
  40. enum
  41. {
  42. NSID3V2_TEXT_SYSTEM=1, // use system code page instead of ISO-8859-1
  43. };
  44. NSID3V2_EXPORT int NSID3v2_Tag_TXXX_Find(const nsid3v2_tag_t tag, const char *description, nsid3v2_frame_t *out_frame, int text_flags);
  45. NSID3V2_EXPORT int NSID3v2_Tag_ID_Find(const nsid3v2_tag_t tag, const char *owner, nsid3v2_frame_t *out_frame, int text_flags);
  46. NSID3V2_EXPORT int NSID3v2_Tag_Comments_Find(const nsid3v2_tag_t tag, const char *description, nsid3v2_frame_t *out_frame, int text_flags);
  47. NSID3V2_EXPORT int NSID3v2_Tag_Text_Get(const nsid3v2_tag_t tag, int frame_enum, nx_string_t *value, int text_flags);
  48. NSID3V2_EXPORT int NSID3v2_Tag_TXXX_Get(const nsid3v2_tag_t tag, const char *description, nx_string_t *value, int text_flags);
  49. NSID3V2_EXPORT int NSID3v2_Tag_Popularimeter_GetRatingPlaycount(const nsid3v2_tag_t tag, const char *email, uint8_t *rating, uint64_t *playcount);
  50. NSID3V2_EXPORT int NSID3v2_Tag_Comments_Get(const nsid3v2_tag_t tag, const char *description, char language[3], nx_string_t *value, int text_flags);
  51. NSID3V2_EXPORT int NSID3v2_Tag_WXXX_Get(const nsid3v2_tag_t tag, const char *description, nx_string_t *value, int text_flags);
  52. NSID3V2_EXPORT int NSID3v2_Tag_ID_Get(const nsid3v2_tag_t tag, const char *owner, const void **id_data, size_t *length, int text_flags);
  53. NSID3V2_EXPORT int NSID3v2_Frame_GetInformation(nsid3v2_frame_t frame, int *type, int *flags);
  54. NSID3V2_EXPORT int NSID3v2_Frame_Text_Get(const nsid3v2_frame_t frame, nx_string_t *value, int text_flags);
  55. NSID3V2_EXPORT int NSID3v2_Frame_UserText_Get(const nsid3v2_frame_t frame, nx_string_t *description, nx_string_t *value, int text_flags);
  56. NSID3V2_EXPORT int NSID3v2_Frame_Private_Get(const nsid3v2_frame_t frame, nx_string_t *description, const void **data, size_t *length);
  57. NSID3V2_EXPORT int NSID3v2_Frame_Object_Get(const nsid3v2_frame_t frame, nx_string_t *mime, nx_string_t *filename, nx_string_t *description, const void **out_data, size_t *length, int text_flags);
  58. NSID3V2_EXPORT int NSID3v2_Frame_Popularity_Get(nsid3v2_frame_t frame, nx_string_t *email, uint8_t *rating, uint64_t *playcount, int text_flags);
  59. NSID3V2_EXPORT int NSID3v2_Frame_Picture_Get(const nsid3v2_frame_t frame, nx_string_t *mime, uint8_t *picture_type, nx_string_t *description, const void **picture_data, size_t *length, int text_flags);
  60. NSID3V2_EXPORT int NSID3v2_Frame_ID_Get(nsid3v2_frame_t frame, nx_string_t *owner, const void **id_data, size_t *length, int text_flags);
  61. NSID3V2_EXPORT int NSID3v2_Frame_Comments_Get(const nsid3v2_frame_t frame, nx_string_t *description, char language[3], nx_string_t *value, int text_flags);
  62. NSID3V2_EXPORT int NSID3v2_Frame_URL_Get(const nsid3v2_frame_t frame, nx_string_t *value, int text_flags);
  63. NSID3V2_EXPORT int NSID3v2_Frame_UserURL_Get(const nsid3v2_frame_t frame, nx_string_t *description, nx_string_t *value, int text_flags);
  64. NSID3V2_EXPORT int NSID3v2_Frame_Binary_Get(nsid3v2_frame_t frame, const void **binary, size_t *length);
  65. NSID3V2_EXPORT int NSID3v2_Frame_GetIdentifier(nsid3v2_frame_t frame, const char **identifier);
  66. enum
  67. {
  68. SerializedSize_Padding = (0x1 << 0), // write 'padding_size' extra 0's to the file
  69. SerializedSize_AbsoluteSize = (0x2 << 0), // 'padding_size' represents the final total tag size
  70. SerializedSize_BlockSize = (0x3 << 0), // 'padding_size' represents a block size. the total tag size will be a multiple of 'padding_size'
  71. SerializedSize_PaddingMask = (0x3 << 0),
  72. // note that setting NEITHER of this will preserve whatever setting was originally used in the tag (or individual frames for ID3v2.4)
  73. Serialize_Unsynchronize = (0x1 << 2), // force the tag to be unsynchronized, even if it wasn't originally
  74. Serialize_NoUnsynchronize = (0x2 << 2), // disable all unsynchronization, even if the tag was originally unsynchronized
  75. Serialize_UnsynchronizeMask = (0x3 << 2),
  76. Serialize_NoCompression = (0x1 << 4), // disables all compression
  77. Serialize_CompressionMask = (0x1 << 4),
  78. };
  79. NSID3V2_EXPORT int NSID3v2_Tag_SerializedSize(nsid3v2_tag_t tag, uint32_t *length, uint32_t padding_size, int flags);
  80. NSID3V2_EXPORT int NSID3v2_Tag_Serialize(nsid3v2_tag_t tag, void *data, uint32_t len, int flags);
  81. NSID3V2_EXPORT int NSID3v2_Tag_Text_Set(nsid3v2_tag_t tag, int frame_enum, nx_string_t value, int text_flags);
  82. NSID3V2_EXPORT int NSID3v2_Tag_TXXX_Set(nsid3v2_tag_t tag, const char *description, nx_string_t value, int text_flags);
  83. NSID3V2_EXPORT int NSID3v2_Tag_Comments_Set(nsid3v2_tag_t tag, const char *description, const char language[3], nx_string_t value, int text_flags);
  84. NSID3V2_EXPORT int NSID3v2_Tag_ID_Set(nsid3v2_tag_t tag, const char *owner, const void *id_data, size_t length, int text_flags);
  85. NSID3V2_EXPORT int NSID3v2_Frame_Text_Set(nsid3v2_frame_t frame, nx_string_t value, int text_flags);
  86. NSID3V2_EXPORT int NSID3v2_Frame_UserText_Set(nsid3v2_frame_t frame, const char *description, nx_string_t value, int text_flags);
  87. NSID3V2_EXPORT int NSID3v2_Frame_Comments_Set(nsid3v2_frame_t frame, const char *description, const char language[3], nx_string_t value, int text_flags);
  88. NSID3V2_EXPORT int NSID3v2_Frame_ID_Set(nsid3v2_frame_t frame, const char *owner, const void *id_data, size_t length, int text_flags);
  89. NSID3V2_EXPORT int NSID3v2_Frame_Picture_Set(nsid3v2_frame_t frame, nx_string_t mime, uint8_t picture_type, nx_string_t description, const void *picture_data, size_t length, int text_flags);
  90. enum
  91. {
  92. NSID3V2_FRAME_PICTURE, // APIC
  93. NSID3V2_FRAME_COMMENTS, // COMM
  94. NSID3V2_FRAME_POPULARIMETER, // POPM
  95. NSID3V2_FRAME_ALBUM, // TALB
  96. NSID3V2_FRAME_BPM, // TBPM
  97. NSID3V2_FRAME_COMPOSER, // TCOM
  98. NSID3V2_FRAME_CONTENTTYPE, // TCON
  99. NSID3V2_FRAME_COPYRIGHT, // TCOP
  100. NSID3V2_FRAME_DATE, // TDAT
  101. NSID3V2_FRAME_PLAYLISTDELAY, // TDLY
  102. NSID3V2_FRAME_RECORDINGTIME, // TDRC
  103. NSID3V2_FRAME_ENCODEDBY, // TENC
  104. NSID3V2_FRAME_LYRICIST, // TEXT
  105. NSID3V2_FRAME_FILETYPE, // TFLT
  106. NSID3V2_FRAME_TIME, // TIME
  107. NSID3V2_FRAME_CONTENTGROUP, // TIT1
  108. NSID3V2_FRAME_TITLE, // TIT2
  109. NSID3V2_FRAME_SUBTITLE, // TIT3
  110. NSID3V2_FRAME_KEY, // TKEY
  111. NSID3V2_FRAME_LANGUAGE, // TLAN
  112. NSID3V2_FRAME_LENGTH, // TLEN
  113. NSID3V2_FRAME_MEDIATYPE, // TMED
  114. NSID3V2_FRAME_MOOD, // TMOO
  115. NSID3V2_FRAME_ORIGINALALBUM, // TOAL
  116. NSID3V2_FRAME_ORIGINALARTIST, // TOPE
  117. NSID3V2_FRAME_LEADARTIST, // TPE1
  118. NSID3V2_FRAME_BAND, // TPE2
  119. NSID3V2_FRAME_CONDUCTOR, // TPE3
  120. NSID3V2_FRAME_REMIXER, // TPE4
  121. NSID3V2_FRAME_PARTOFSET, // TPOS
  122. NSID3V2_FRAME_PUBLISHER, // TPUB
  123. NSID3V2_FRAME_TRACK, // TRCK
  124. NSID3V2_FRAME_RECORDINGDATES, // TRDA
  125. NSID3V2_FRAME_ISRC, // TSRC
  126. NSID3V2_FRAME_ENCODERSETTINGS, // TSSE
  127. NSID3V2_FRAME_YEAR, // TYER
  128. NSID3V2_FRAME_USER_TEXT, // TXXX
  129. NSID3V2_FRAME_ID, // UFID
  130. };
  131. /* frame types */
  132. enum
  133. {
  134. NSID3V2_FRAMETYPE_UNKNOWN,
  135. NSID3V2_FRAMETYPE_TEXT,
  136. NSID3V2_FRAMETYPE_USERTEXT,
  137. NSID3V2_FRAMETYPE_COMMENTS,
  138. NSID3V2_FRAMETYPE_URL,
  139. NSID3V2_FRAMETYPE_USERURL,
  140. NSID3V2_FRAMETYPE_PRIVATE,
  141. NSID3V2_FRAMETYPE_OBJECT,
  142. NSID3V2_FRAMETYPE_POPULARITY,
  143. NSID3V2_FRAMETYPE_PICTURE,
  144. NSID3V2_FRAMETYPE_ID,
  145. };
  146. /* these DO NOT map to the actual flag bitmasks, they are only for API usage! */
  147. enum
  148. {
  149. NSID3V2_TAGFLAG_EXTENDED_HEADER = 1<<1,
  150. NSID3V2_TAGFLAG_UNSYNCHRONIZED = 1<<2,
  151. NSID3V2_TAGFLAG_HASFOOTER = 1<<3,
  152. NSID3V2_FRAMEFLAG_TAG_ALTER_PRESERVATION = 1<<1,
  153. NSID3V2_FRAMEFLAG_FILE_ALTER_PRESERVATION = 1<<2,
  154. NSID3V2_FRAMEFLAG_ENCRYPTED = 1<<3,
  155. NSID3V2_FRAMEFLAG_COMPRESSED = 1<<4,
  156. NSID3V2_FRAMEFLAG_GROUPED = 1<<5,
  157. NSID3V2_FRAMEFLAG_READONLY =1<<6,
  158. NSID3V2_FRAMEFLAG_UNSYNCHRONIZED =1<<7,
  159. NSID3V2_FRAMEFLAG_DATALENGTHINDICATED =1<<8,
  160. };
  161. #ifdef __cplusplus
  162. }
  163. #endif