ID3v1 reader

From ProjectWiki
(Difference between revisions)
Jump to: navigation, search
(fdCRoaTRHdA)
Line 1: Line 1:
<big>Simple ID3v1 Reader</big>
+
Slam dunkin like Shaquille O'Neal, if he wrote informative atricles.
__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 was taking too long so decided to write this one night. Most of the others had lots of excess features, like a GUI, pffft! Enjoy the redundancy! :P
+
 
+
==Examples==
+
'''Compile'''<br>
+
This is obvious, just copy the code below to main.c and:
+
<source lang="bash">
+
gcc -o id3 main.c
+
</source>
+
 
+
'''Using'''<br>
+
<pre>
+
~/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
+
</pre>
+
 
+
'''Getting just one field'''
+
<pre>
+
~/Projects/mp3tagread$ ./id3 /media/160gb/e/MP3s/Dead\ Prez\ -\ Hip-Hop.mp3 | grep "^title\:"
+
title: Hip-Hop
+
</pre>
+
 
+
'''Translating SJIS to UTF-8'''<br>
+
Requires the recode command, but can be used to translate id3 tags :D
+
<pre>
+
~/Projects/mp3tagread$ ./id3 ~/Music/th03_東方夢時空\ ~\ Phantasmagoria\ \
+
of\ Dim.Dream/th03_08-夢消失 ~Lost\ \
+
Dream.mp3 | grep "^title\:" | recode -f SJIS...UTF-8
+
title: 夢消失 〜Lost Dream          ZUN(太田順也)            東方夢時空
+
</pre>
+
 
+
(please note: the last example is entirely why i wrote this :P)
+
 
+
==Source Code==
+
<source lang="c">
+
/**************************************************************
+
*  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]);
+
}
+
}
+
</source>
+

Revision as of 21:17, 22 July 2011

Slam dunkin like Shaquille O'Neal, if he wrote informative atricles.

Personal tools
irssi scripts
eggdrop scripts