ID3v1 reader
From ProjectWiki
(Difference between revisions)
(New page: <big>Simple ID3v1 Reader</big> __TOC__ ==What is this?=== A simple and quick command line ID3v1 tag reader for getting artist, title, etc data from mp3s. Googling for a pre-existing one w...) |
(→What is this?=) |
||
Line 1: | Line 1: | ||
<big>Simple ID3v1 Reader</big> | <big>Simple ID3v1 Reader</big> | ||
__TOC__ | __TOC__ | ||
− | ==What is this? | + | ==What is this?== |
A simple and quick command line ID3v1 tag reader for getting artist, title, etc data from mp3s. Googling for a pre-existing one was taking too long so decided to write this one night. Enjoy the redundancy! :P | A simple and quick command line ID3v1 tag reader for getting artist, title, etc data from mp3s. Googling for a pre-existing one was taking too long so decided to write this one night. Enjoy the redundancy! :P | ||
Revision as of 06:31, 2 August 2009
Simple ID3v1 Reader
Contents |
What is this?
A simple and quick command line ID3v1 tag reader for getting artist, title, etc data from mp3s. Googling for a pre-existing one was taking too long so decided to write this one night. Enjoy the redundancy! :P
Examples
Compile
This is obvious, just copy the code below to main.c and:
gcc -o id3 main.c
Using
~/Projects/mp3tagread$ ./id3 /media/160gb/e/MP3s/Dead\ Prez\ -\ Hip-Hop.mp3 title: Hip-Hop artist: Dead Prez album: Lets Get Free year: 2001 comment: genre: 12
Getting just one field
~/Projects/mp3tagread$ ./id3 /media/160gb/e/MP3s/Dead\ Prez\ -\ Hip-Hop.mp3 | grep "^title\:" title: Hip-Hop
Source Code
/************************************************************** * quicke mp3 id3 tag reader... written in 8 mins by erisu :P ***************************************************************/ #include <stdio.h> #define MP3ID3V1MAGIC "TAG" #define MP3ID3V1MAGIC_SIZE 3 //This at last 128 (-3 for "TAG") bytes of file is the tag typedef struct _ID3V1_T { char magic[3]; char title[30]; char artist[30]; char album[30]; char year[4]; char comment[30]; char genre; #ifdef ARM //This rly should be like "NDS" or something } ID3V1_T; #else } ID3V1_T __attribute__((packed)); #endif int main(int argc, char **argv) { ID3V1_T id3; FILE *file; if(argc==2) { file=fopen(argv[1],"rb"); if(file) { fseek(file, -sizeof(id3), SEEK_END); fread(&id3, sizeof(id3), 1, file); fclose(file); if(strncmp(id3.magic, MP3ID3V1MAGIC, MP3ID3V1MAGIC_SIZE)==0) { printf("title: %s\n", id3.title); printf("artist: %s\n", id3.artist); printf("album: %s\n", id3.album); printf("year: %s\n", id3.year); printf("comment: %s\n", id3.comment); printf("genre: %d\n", id3.genre); } else { printf("not id3?! (or id3 not at end of file)\n"); } } else { printf("unable to open %s u_u\n"); } } else { printf("usage: %s FILENAME.mp3\n",argv[0]); } }