Skip to content

A public domain, single header C/C++ library to read ID3 Tags from MP3 files.

Notifications You must be signed in to change notification settings

Arcxm/mp3_id3_tags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

About mp3_id3_tags

mp3_id3_tags is a public domain single header C/C++ library to read ID3 Tags from an MP3.

After looking at multiple single header C/C++ libraries and using them (especially the stb ones), i decided to try and make one myself.

Supported tags

  • Title
  • Artist
  • Album
  • Year
  • Comment
  • Genre

Defines

These need to be defined before the mp3_id3_tags.h file is included:

  • MP3_ID3_TAGS_IMPLEMENTATION in one C or C++ file to create the implementation
  • MP3_ID3_TAGS_USE_GENRES to be able to read the genre tag

Documentation

Example

A full example program can be found here.

Function variants

Each function comes in two variants:

  1. Takes a filename and opens a file by itself
  2. Takes a file pointer and uses the already opened file ('file' in function name)

mp3_id3_has_tags and mp3_id3_file_has_tags

Checks if an mp3 file has tag information.
Returns 1 on success, 0 on failure.

if (mp3_id3_has_tags("song.mp3")) {
  fprintf(stdout, "Song has tags!\n");
} else {
  fprintf(stdout, "Song has no tags!\n");
}

mp3_id3_read_tag and mp3_id3_file_read_tag

Read a specific tag from an mp3 file.
Returns a null terminated string which contains the data of the requested tag or NULL on failure.

Note that the returned string has to be freed after usage.

char *artist = mp3_id3_read_tag("song.mp3", ARTIST);
if (artist) {
  fprintf(stdout, "Artist: %s\n", artist);
  free(artist);
  artist = NULL;
} else {
  fprintf(stderr, "error: %s\n", mp3_id3_failure_reason());
}

mp3_id3_read_tags and mp3_id3_file_read_tags

Read all tags from an mp3 file.
Returns 1 on success, 0 on failure.
The supplied mp3_id3_tags structure will contain the tag information.

mp3_id3_tags tags;
if (mp3_id3_read_tags("song.mp3", &tags)) {
  fprintf(stdout, "%s by %s\n", tags.title, tags.artist);
} else {
  fprintf(stderr, "error: %s\n", mp3_id3_failure_reason());
}

Releases

No releases published

Packages

No packages published

Languages