36 ID3 *metadata = malloc(
sizeof(
ID3));
38 metadata->
id3v2 = id3v2;
39 metadata->
id3v1 = id3v1;
115 if (toCopy == NULL) {
131 if (metadata1 == NULL || metadata2 == NULL) {
145 if (v1 ==
false && (v2 ==
true && metadata1->
id3v1 == NULL && metadata2->
id3v1 == NULL)) {
149 if (v2 ==
false && (v1 ==
true && metadata1->
id3v2 == NULL && metadata2->
id3v2 == NULL)) {
168 if (metadata == NULL) {
172 if (metadata->
id3v1 == NULL) {
231 size = snprintf(NULL, 0,
"%d", metadata->
id3v1->
year);
232 str = calloc(size + 1,
sizeof(
char));
233 (void) snprintf(str, size + 1,
"%d", metadata->
id3v1->
year);
245 size = snprintf(NULL, 0,
"%d", metadata->
id3v1->
track);
246 str = calloc(size + 1,
sizeof(
char));
247 (void) snprintf(str, size + 1,
"%d", metadata->
id3v1->
track);
275 if (metadata->
id3v2 != NULL) {
279 metadata->
id3v2 = newTag;
296 if (metadata == NULL) {
300 if (metadata->
id3v2 == NULL) {
310 char *comment = NULL;
327 if (artist != NULL) {
350 while (track[i] !=
'\0') {
351 if (track[i] >=
'0' && track[i] <=
'9') {
352 if (!flag && track[i] ==
'0') {
363 dec = calloc(i - offset0 + 1,
sizeof(
char));
364 memcpy(dec, track + offset0, i - offset0);
365 convi = (int) strtol(dec, &end, 10);
372 if (comment != NULL) {
382 if (metadata->
id3v1 != NULL) {
386 metadata->
id3v1 = newTag;
392static int internal_getSafePrefStd(
const ID3 *metadata) {
418 if (metadata == NULL) {
422 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
426 switch (internal_getSafePrefStd(metadata)) {
449 if (metadata == NULL) {
453 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
457 switch (internal_getSafePrefStd(metadata)) {
480 if (metadata == NULL) {
484 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
488 switch (internal_getSafePrefStd(metadata)) {
510 if (metadata == NULL) {
514 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
518 switch (internal_getSafePrefStd(metadata)) {
542 if (metadata == NULL) {
546 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
550 switch (internal_getSafePrefStd(metadata)) {
552 if (metadata->
id3v1 == NULL) {
559 size = snprintf(NULL, 0,
"%d", metadata->
id3v1->
year);
560 year = calloc(size + 1,
sizeof(
char));
561 (void) snprintf(year, size + 1,
"%d", metadata->
id3v1->
year);
586 if (metadata == NULL) {
590 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
594 switch (internal_getSafePrefStd(metadata)) {
596 if (metadata->
id3v1 == NULL) {
604 genre = calloc(size + 1,
sizeof(
char));
629 if (metadata == NULL) {
633 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
637 switch (internal_getSafePrefStd(metadata)) {
639 if (metadata->
id3v1 == NULL) {
646 size = snprintf(NULL, 0,
"%d", metadata->
id3v1->
track);
647 track = calloc(size + 1,
sizeof(
char));
648 (void) snprintf(track, size + 1,
"%d", metadata->
id3v1->
track);
671 if (metadata == NULL) {
675 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
679 switch (internal_getSafePrefStd(metadata)) {
701 if (metadata == NULL) {
705 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
709 switch (internal_getSafePrefStd(metadata)) {
731 if (metadata == NULL) {
735 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
739 switch (internal_getSafePrefStd(metadata)) {
761 if (metadata == NULL) {
765 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
769 switch (internal_getSafePrefStd(metadata)) {
795 if (metadata == NULL) {
800 if (metadata->
id3v2 == NULL && metadata->
id3v1 == NULL) {
805 switch (internal_getSafePrefStd(metadata)) {
831 if (metadata == NULL || title == NULL) {
835 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
839 switch (internal_getSafePrefStd(metadata)) {
863 if (metadata == NULL || artist == NULL) {
867 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
871 switch (internal_getSafePrefStd(metadata)) {
895 if (metadata == NULL || albumArtist == NULL) {
899 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
903 switch (internal_getSafePrefStd(metadata)) {
926 if (metadata == NULL || album == NULL) {
930 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
934 switch (internal_getSafePrefStd(metadata)) {
959 if (metadata == NULL || year == NULL) {
963 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
967 switch (internal_getSafePrefStd(metadata)) {
971 convi = (int) strtol(year, &end, 10);
996 if (metadata == NULL || genre == NULL) {
1000 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1004 switch (internal_getSafePrefStd(metadata)) {
1031 if (metadata == NULL || track == NULL) {
1035 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1039 switch (internal_getSafePrefStd(metadata)) {
1043 convi = (int) strtol(track, &end, 10);
1045 if (convi > UINT8_MAX) {
1047 }
else if (convi < 0) {
1074 if (metadata == NULL || disc == NULL) {
1078 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1082 switch (internal_getSafePrefStd(metadata)) {
1105 if (metadata == NULL || composer == NULL) {
1109 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1113 switch (internal_getSafePrefStd(metadata)) {
1136 if (metadata == NULL || lyrics == NULL) {
1140 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1144 switch (internal_getSafePrefStd(metadata)) {
1167 if (metadata == NULL || comment == NULL) {
1171 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1175 switch (internal_getSafePrefStd(metadata)) {
1202 if (metadata == NULL || image == NULL || kind == NULL) {
1206 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1210 switch (internal_getSafePrefStd(metadata)) {
1235 if (metadata == NULL || filename == NULL || kind == NULL) {
1239 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1243 switch (internal_getSafePrefStd(metadata)) {
1275 size_t memCount = 3;
1277 if (metadata == NULL) {
1278 json = calloc(memCount,
sizeof(
char));
1279 memcpy(json,
"{}\0", memCount);
1286 memCount += snprintf(NULL, 0,
"{\"id3v1\":%s,\"id3v2\":%s}", id3v1, id3v2);
1287 json = calloc(memCount,
sizeof(
char));
1288 (void) snprintf(json, memCount,
"{\"ID3v1\":%s,\"ID3v2\":%s}", id3v1, id3v2);
1306 if (filePath == NULL || metadata == NULL) {
1311 if (metadata->
id3v1 == NULL && metadata->
id3v2 == NULL) {
1327 if (v1 ==
false && (v2 ==
true && metadata->
id3v1 == NULL)) {
1331 if (v2 ==
false && (v1 ==
true && metadata->
id3v2 == NULL)) {
char * id3ReadDisc(const ID3 *metadata)
Reads the disc number from an ID3 metadata structure using the preferred standard.
ID3 * id3FromFile(const char *filePath)
Reads both ID3v1 and ID3v2 tags from a file into an ID3 metadata structure.
char * id3ReadComposer(const ID3 *metadata)
Reads the composer from an ID3 metadata structure using the preferred standard.
char * id3ToJSON(const ID3 *metadata)
Converts an ID3 metadata structure to a JSON string.
int id3WriteTitle(const char *title, ID3 *metadata)
Writes a title to an ID3 metadata structure using the preferred standard.
char * id3ReadArtist(const ID3 *metadata)
Reads the artist from an ID3 metadata structure using the preferred standard.
char * id3ReadGenre(const ID3 *metadata)
Reads the genre from an ID3 metadata structure using the preferred standard.
bool id3SetPreferredStandard(uint8_t standard)
Sets the preferred ID3 standard for reading metadata from tag structures.
void id3Destroy(ID3 **toDelete)
Destroys an ID3 metadata structure and frees all associated memory.
int id3WriteComposer(const char *composer, ID3 *metadata)
Writes a composer to an ID3 metadata structure using the preferred standard.
char * id3ReadAlbum(const ID3 *metadata)
Reads the album from an ID3 metadata structure using the preferred standard.
int id3WriteAlbumArtist(const char *albumArtist, ID3 *metadata)
Writes an album artist to an ID3 metadata structure using the preferred standard.
int id3WriteYear(const char *year, ID3 *metadata)
Writes a year to an ID3 metadata structure using the preferred standard.
char * id3ReadYear(const ID3 *metadata)
Reads the year from an ID3 metadata structure using the preferred standard.
int id3WriteTrack(const char *track, ID3 *metadata)
Writes a track number to an ID3 metadata structure using the preferred standard.
int id3WritePicture(uint8_t *image, size_t imageSize, const char *kind, uint8_t type, ID3 *metadata)
Writes a picture to an ID3 metadata structure using the preferred standard.
static uint8_t id3PreferredStandard
default standard for reading ID3 tags from a data structure representation.
bool id3Compare(const ID3 *metadata1, const ID3 *metadata2)
Compares two ID3 metadata structures for equality.
char * id3ReadAlbumArtist(const ID3 *metadata)
Reads the album artist from an ID3 metadata structure using the preferred standard.
bool id3ConvertId3v1ToId3v2(ID3 *metadata)
Converts the ID3v1 tag to an ID3v2 tag within the metadata structure.
int id3WriteArtist(const char *artist, ID3 *metadata)
Writes an artist to an ID3 metadata structure using the preferred standard.
ID3 * id3Copy(const ID3 *toCopy)
Creates a deep copy of an ID3 metadata structure.
ID3 * id3Create(Id3v2Tag *id3v2, Id3v1Tag *id3v1)
Creates a new ID3 metadata structure containing ID3v2 and ID3v1 tags.
int id3WriteDisc(const char *disc, ID3 *metadata)
Writes a disc number to an ID3 metadata structure using the preferred standard.
uint8_t * id3ReadPicture(uint8_t type, const ID3 *metadata, size_t *dataSize)
Reads a picture of the specified type from an ID3 metadata structure using the preferred standard.
int id3WriteComment(const char *comment, ID3 *metadata)
Writes a comment to an ID3 metadata structure using the preferred standard.
char * id3ReadLyrics(const ID3 *metadata)
Reads the lyrics from an ID3 metadata structure using the preferred standard.
int id3WritePictureFromFile(const char *filename, const char *kind, uint8_t type, ID3 *metadata)
Writes a picture from a file to an ID3 metadata structure using the preferred standard.
int id3WriteToFile(const char *filePath, const ID3 *metadata)
Writes both ID3v1 and ID3v2 tags to a file using the given ID3 structure.
char * id3ReadTrack(const ID3 *metadata)
Reads the track number from an ID3 metadata structure using the preferred standard.
int id3WriteLyrics(const char *lyrics, ID3 *metadata)
Writes lyrics to an ID3 metadata structure using the preferred standard.
int id3WriteAlbum(const char *album, ID3 *metadata)
Writes an album to an ID3 metadata structure using the preferred standard.
bool id3ConvertId3v2ToId3v1(ID3 *metadata)
Converts the ID3v2 tag to an ID3v1 tag within the metadata structure.
char * id3ReadComment(const ID3 *metadata)
Reads the comment from an ID3 metadata structure using the preferred standard.
char * id3ReadTitle(const ID3 *metadata)
Reads the title from an ID3 metadata structure using the preferred standard.
int id3WriteGenre(const char *genre, ID3 *metadata)
Writes a genre to an ID3 metadata structure using the preferred standard.
uint8_t id3GetPreferredStandard(void)
Returns the currently configured preferred ID3 standard.
Decleations for reading, writing, converting, and comparing ID3v1 and ID3v2 metadata tags.
struct _ID3 ID3
A structure of both ID3v1 and ID3v2 tags.
Id3v1Tag * id3v1CopyTag(Id3v1Tag *toCopy)
Creates a deep copy of an Id3v1Tag structure.
char * id3v1ReadComment(const Id3v1Tag *tag)
Reads the comment member from an Id3v1Tag.
char * id3v1GenreFromTable(Genre val)
Converts a Genre enum value to it's string representation.
int id3v1WriteArtist(const char *artist, Id3v1Tag *tag)
Writes an artist to an Id3v1Tag.
char * id3v1ReadArtist(const Id3v1Tag *tag)
Reads the artist member from an Id3v1Tag.
int id3v1WriteGenre(Genre genre, Id3v1Tag *tag)
Writes a Genre to an Id3v1Tag.
int id3v1WriteTagToFile(const char *filePath, const Id3v1Tag *tag)
Writes/Overwrites an Id3v1Tag to the bottom of a file .
char * id3v1ToJSON(const Id3v1Tag *tag)
Converts an Id3v1Tag to a JSON string representation.
int id3v1WriteComment(const char *comment, Id3v1Tag *tag)
Writes a comment to an Id3v1Tag.
char * id3v1ReadTitle(const Id3v1Tag *tag)
Reads the title member from an Id3v1Tag.
int id3v1WriteAlbum(const char *album, Id3v1Tag *tag)
Writes an album to an Id3v1Tag.
int id3v1WriteTitle(const char *title, Id3v1Tag *tag)
Writes a title to an Id3v1Tag.
Id3v1Tag * id3v1TagFromFile(const char *filePath)
Creates an Id3v1Tag from a provided file path.
int id3v1WriteTrack(int track, Id3v1Tag *tag)
Writes a track number to an Id3v1Tag.
int id3v1WriteYear(int year, Id3v1Tag *tag)
Writes a year to an Id3v1Tag.
bool id3v1CompareTag(const Id3v1Tag *tag1, const Id3v1Tag *tag2)
Compares two Id3v1Tag structures for equality.
char * id3v1ReadAlbum(const Id3v1Tag *tag)
Reads the album member from an Id3v1Tag.
void id3v1DestroyTag(Id3v1Tag **toDelete)
Frees an Id3v1Tag and nullifies the pointer.
Id3v1Tag * id3v1CreateTag(uint8_t *title, uint8_t *artist, uint8_t *albumTitle, int year, int track, uint8_t *comment, Genre genre)
Creates and allocates a new Id3v1Tag structure.
@ OTHER_GENRE
Other Music Genres not Defined.
@ PSYBIENT_GENRE
Psybient Audio.
#define ID3V1_TAG_VERSION
Major version number for ID3v1 and ID3v1.1 specification (always 1)
struct _Id3v1Tag Id3v1Tag
ID3v1/ID3v1.1 tag structure containing all metadata fields.
Declarations of ID3v2 tag operations including reading/writing metadata frames, tag serialization,...
int id3v2WriteLyrics(const char *lyrics, Id3v2Tag *tag)
Writes lyrics to the appropriate unsynchronized lyrics frame in a tag.
char * id3v2ReadAlbum(Id3v2Tag *tag)
Extracts the album name from an ID3v2 tag.
int id3v2WriteGenre(const char *genre, Id3v2Tag *tag)
Writes the genre/content type to an ID3v2 tag.
bool id3v2CompareTag(Id3v2Tag *tag1, Id3v2Tag *tag2)
Performs deep structural comparison of two ID3v2 tags for equality.
int id3v2WritePictureFromFile(const char *filename, const char *kind, uint8_t type, Id3v2Tag *tag)
Reads a picture from a file and writes it to the appropriate attached picture frame in a tag.
char * id3v2ReadGenre(Id3v2Tag *tag)
Extracts the genre/content type from an ID3v2 tag.
int id3v2WriteYear(const char *year, Id3v2Tag *tag)
Writes the year to an ID3v2 tag.
char * id3v2ReadTrack(Id3v2Tag *tag)
Extracts the track number/position from an ID3v2 tag.
char * id3v2ReadYear(Id3v2Tag *tag)
Extracts the year from an ID3v2 tag.
char * id3v2ReadTitle(Id3v2Tag *tag)
Extracts the title/song name from an ID3v2 tag.
char * id3v2ReadAlbumArtist(Id3v2Tag *tag)
Extracts the album artist/band/orchestra from an ID3v2 tag.
int id3v2WritePicture(uint8_t *image, size_t imageSize, const char *kind, uint8_t type, Id3v2Tag *tag)
Writes a picture to the appropriate attached picture frame in a tag.
char * id3v2ReadComment(Id3v2Tag *tag)
Extracts the comment text from an ID3v2 tag.
uint8_t * id3v2ReadPicture(uint8_t type, const Id3v2Tag *tag, size_t *dataSize)
Extracts picture/artwork data of a specific type from an ID3v2 tag.
char * id3v2ReadComposer(Id3v2Tag *tag)
Extracts the composer from an ID3v2 tag.
int id3v2WriteAlbumArtist(const char *albumArtist, Id3v2Tag *tag)
Writes the album artist/band/orchestra to an ID3v2 tag.
char * id3v2ReadArtist(Id3v2Tag *tag)
Extracts the lead artist/performer from an ID3v2 tag.
int id3v2WriteDisc(const char *disc, Id3v2Tag *tag)
Writes a disc number to the appropriate disc number frame in a tag.
char * id3v2ReadDisc(Id3v2Tag *tag)
Extracts the disc number/position from an ID3v2 tag.
int id3v2WriteComposer(const char *composer, Id3v2Tag *tag)
Writes a composer name to the appropriate composer frame in a tag.
Id3v2Tag * id3v2TagFromFile(const char *filename)
Reads and parses an ID3v2 tag from a file.
int id3v2WriteTagToFile(const char *filename, Id3v2Tag *tag)
Writes an ID3v2 tag to a file, creating, prepending, or replacing as needed.
Id3v2Tag * id3v2CopyTag(const Id3v2Tag *toCopy)
Creates a deep copy of an ID3v2 tag structure.
int id3v2WriteTitle(const char *title, Id3v2Tag *tag)
Writes the title/song name to an ID3v2 tag.
char * id3v2TagToJSON(Id3v2Tag *tag)
Serializes an ID3v2 tag structure to JSON format.
int id3v2WriteArtist(const char *artist, Id3v2Tag *tag)
Writes the lead artist/performer to an ID3v2 tag.
int id3v2WriteTrack(const char *track, Id3v2Tag *tag)
Writes the track number/position to an ID3v2 tag.
int id3v2WriteAlbum(const char *album, Id3v2Tag *tag)
Writes the album name to an ID3v2 tag.
char * id3v2ReadLyrics(Id3v2Tag *tag)
Extracts unsynchronised lyrics/text transcription from an ID3v2 tag.
int id3v2WriteComment(const char *comment, Id3v2Tag *tag)
Writes a comment to the appropriate comment frame in a tag.
Function definitions for ID3v2 frame lifecycle, traversal, serialization, and content management.
int id3v2CompareFrame(const void *first, const void *second)
Performs deep comparison of two ID3v2 frame structures.
void * id3v2CopyFrame(const void *toBeCopied)
Creates a deep copy of an ID3v2 frame structure.
char * id3v2PrintFrame(const void *toBePrinted)
Generates a string representation of a frame for debugging.
void id3v2DeleteFrame(void *toBeDeleted)
Frees all memory allocated for an ID3v2 frame structure.
Id3v2Tag * id3v2CreateTag(Id3v2TagHeader *header, List *frames)
Creates and allocates an ID3v2 tag structure.
void id3v2DestroyTag(Id3v2Tag **toDelete)
Frees an ID3v2 tag and all associated resources, nullifying the pointer.
Id3v2TagHeader * id3v2CreateTagHeader(uint8_t majorVersion, uint8_t minorVersion, uint8_t flags, Id3v2ExtendedTagHeader *extendedHeader)
Creates and allocates an ID3v2 tag header structure.
#define ID3V2_TAG_VERSION_3
ID3v2.3 major version number (3)
struct _Id3v2Tag Id3v2Tag
Complete ID3v2 tag structure containing header and metadata frames.
#define ID3V2_TAG_VERSION_2
ID3v2.2 major version number (2)
#define ID3V2_TAG_VERSION_4
ID3v2.4 major version number (4)
struct _Id3v2TagHeader Id3v2TagHeader
ID3v2 tag header containing version and parsing information.
Id3v1Tag * id3v1
An ID3v1 or ID3v1.1 Tag.
Id3v2Tag * id3v2
An ID3v2.2, ID3v2.3, or ID3v2.4 Tag.
int track
Track number (0 if not present, ID3v1.1 only)
Genre genre
Genre value (0-191, maps to Genre enum)
uint8_t artist[ID3V1_FIELD_SIZE]
Artist name (ID3V1_FIELD_SIZE bytes, null-padded)
uint8_t comment[ID3V1_FIELD_SIZE]
Comment text (ID3V1_FIELD_SIZE bytes, null-padded; ID3V1_FIELD_SIZE - 2 bytes if track number present...
uint8_t title[ID3V1_FIELD_SIZE]
Song title (ID3V1_FIELD_SIZE bytes, null-padded)
int year
Release year (4-digit integer)
uint8_t albumTitle[ID3V1_FIELD_SIZE]
Album title (ID3V1_FIELD_SIZE bytes, null-padded)