#include "id3.h" #include #include #include const char *genres[NR_GENRES] = { "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "Alt", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta Rap", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", "Psychedelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing", "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A Cappella", "Euro-House", "Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore", "Terror", "Indie", "BritPop", "Negerpunk", "Polsk Punk", "Beat", "Christian Gangsta Rap", "Heavy Metal", "Black Metal", "Crossover", "Contemporary Christian", "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop", "Synthpop" }; int id3_open(struct id3 *id3, const char *filename, int wr) { char *ptr; int size; if (wr) { id3->fd = open(filename, O_RDWR); } else { id3->fd = open(filename, O_RDONLY); } if (id3->fd == -1) return -1; if (lseek(id3->fd, -128, SEEK_END) == -1) { int save = errno; close(id3->fd); errno = save; return -1; } size = 128; ptr = (char *)&id3->tag; do { int rc; rc = read(id3->fd, ptr, size); if (rc == -1) { close(id3->fd); return -1; } ptr += rc; size -= rc; } while (size > 0); if (id3->tag.tag[0] == 'T' && id3->tag.tag[1] == 'A' && id3->tag.tag[2] == 'G') { id3->has_tag = 1; } else { id3_clear_tags(id3); id3->has_tag = 0; } if (id3->tag.genre >= NR_GENRES) id3->tag.genre = 0xff; id3->version = ((id3->tag.u.v1_1.zero == 0) && (id3->tag.u.v1_1.track != 0)) ? ID3_V1_1 : ID3_V1_0; return 0; } int id3_save(struct id3 *id3) { char *ptr; int size; if (lseek(id3->fd, -128 * id3->has_tag, SEEK_END) == -1) return -1; size = 128; ptr = (char *)&id3->tag; do { int rc; rc = write(id3->fd, ptr, size); if (rc == -1) return -1; ptr += rc; size -= rc; } while (size > 0); id3->has_tag = 1; return 0; } void id3_close(struct id3 *id3) { close(id3->fd); id3->fd = -1; } void id3_clear_tags(struct id3 *id3) { memset(&id3->tag, 0, 128); id3->tag.tag[0] = 'T'; id3->tag.tag[1] = 'A'; id3->tag.tag[2] = 'G'; id3->tag.genre = 0xff; } void __id3_buf_to_str(char *str, const char *buf, int buf_size) { int i = buf_size - 1; while ((buf[i] == 0 || buf[i] == ' ') && i >= 0) i--; str[i + 1] = 0; while (i >= 0) { str[i] = buf[i]; i--; } }