MIdNight 0 Denunciar post Postado Abril 4, 2010 Oi gente :) Alguém sabe como posso em C alterar as ID3 tags de arquivos MP3? Procurei mas não encontrei nada de útil. Ex: Mudar artista/título de uma música.. Compartilhar este post Link para o post Compartilhar em outros sites
Beraldo 864 Denunciar post Postado Abril 4, 2010 Com uma simples pesquisa no Google, encontrei este projeto: http://id3lib.sourceforge.net/ Já o viu? Compartilhar este post Link para o post Compartilhar em outros sites
VictorCacciari 42 Denunciar post Postado Abril 4, 2010 Nem é preciso utilizar nenhuma biblioteca, apenas siga a especificação do arquivo... http://en.wikipedia.org/wiki/ID3 Compartilhar este post Link para o post Compartilhar em outros sites
MIdNight 0 Denunciar post Postado Abril 7, 2010 Logo após postar o tópico axei um código e esqueci de postar pedindo para fecharem o tópico. Se alguém se interessar, está ai: ID3v1.c: /****************************************************/ /* */ /* C-Library zum Auslesen von ID3v1-TAGs */ /* */ /* Version: 2.0.0.0. */ /* Autor: tgc_md */ /* Copyright: tgc_md */ /* Datum: 16.12.2002 */ /* Mail: coding@tool-garage.de */ /* */ /****************************************************/ #ifndef ID3 #define ID3 # include "ID3v1.h" #endif const int TAG = -128; const int TITLE = -125; const int ARTIST = -95; const int ALBUM = -65; const int YEAR = -35; const int COMMENT = -31; const int TRACK = -2; const int GENRE = -1; int ID3v1 = 1; char *Genres[148] = { "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", "Alternative Rock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native US", "Cabaret", "New Wave", "Psychadelic", "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", "--- Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhytmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "Acapella", "Euro-House", "Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore", "Terror", "Indie", "BritPop", "Negerpunk", "Polsk Punk", "Beat", "Christian Gangsta", "Heavy Metal", "Black Metal", "Crossover", "Contemporary C", "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop", "SynthPop" }; int checkID3v1(char *path) { FILE *fp; char *tag = (char *) calloc(1, 4); if(fp = fopen( path, "rb")) { fseek(fp, TAG, SEEK_END); fread(tag, 3, 1, fp); fclose(fp); if(!strcmp(tag, "TAG")) return 0; else return 1; } return 2; } /*---------------------------------------------*/ int checkVersion(char *path) { FILE *fp2; char byte28, byte29; int i = checkID3v1(path); if(i == 0) /* TAG valid */ { if(fp2 = fopen( path, "rb")) { fseek(fp2, TRACK-1, SEEK_END); fread(&byte28, 1, 1, fp2); fread(&byte29, 1, 1, fp2); fclose(fp2); if( byte28=='\0' && byte29!='\0') return 11; else return 10; } } return i; } /*---------------------------------------------*/ int removeTag(char *path) { FILE *fp; int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "r+b")) { if( !chsize(fileno(fp), filelength( fileno(fp) ) - 128) ) { fclose(fp); return 0; } } } if(i == 1) return 0; return 1; } /*---------------------------------------------*/ char *getTitle(char *path) { FILE *fp; char *title = (char *) calloc(1, 31); int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "rb")) { fseek(fp, TITLE, SEEK_END); fread(title, 30, 1, fp); fclose(fp); return title; } } if(i == 1) return "noTAG"; return "FileNotFound"; } /*---------------------------------------------*/ int setTitle(char *path, char *newTitle) { FILE *fp; int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "r+b")) { fseek(fp, TITLE, SEEK_END); if( fwrite(newTitle, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } if(i == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, TITLE, SEEK_END); if( fwrite(newTitle, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } return 2; } /*---------------------------------------------*/ char *getArtist(char *path) { FILE *fp; char *artist = (char *) calloc(1, 31); int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "rb")) { fseek(fp, ARTIST, SEEK_END); fread(artist, 30, 1, fp); fclose(fp); return artist; } } if(i == 1) return "noTAG"; return "FileNotFound"; } /*---------------------------------------------*/ int setArtist(char *path, char *newArtist) { FILE *fp; int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "r+b")) { fseek(fp, ARTIST, SEEK_END); if( fwrite(newArtist, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } if(i == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, ARTIST, SEEK_END); if( fwrite(newArtist, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } return 2; } /*---------------------------------------------*/ char *getAlbum(char *path) { FILE *fp; char *album = (char *) calloc(1, 31); int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "rb")) { fseek(fp, ALBUM, SEEK_END); fread(album, 30, 1, fp); fclose(fp); return album; } } if(i == 1) return "noTAG"; return "FileNotFound"; } /*---------------------------------------------*/ int setAlbum(char *path, char *newAlbum) { FILE *fp; int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "r+b")) { fseek(fp, ALBUM, SEEK_END); if( fwrite(newAlbum, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } if(i == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, ALBUM, SEEK_END); if( fwrite(newAlbum, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } return 2; } /*---------------------------------------------*/ char *getGenre(char *path) { FILE *fp; char genre; int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "rb")) { fseek(fp, GENRE, SEEK_END); fread(&genre, 1, 1, fp); fclose(fp); return Genres[(int) genre]; } } if(i == 1) return "noTAG"; return "FileNotFound"; } /*---------------------------------------------*/ int validGenre(char *genre) { int i; for(i=0; i<148; i++) { if( strcmp(genre, Genres[i])==0 ) return i; } return -1; } int setGenre(char *path, char *newGenre) { FILE *fp; int g, i = checkID3v1(path); char gID; if(i == 0) { if( (g=validGenre(newGenre)) != -1 ) { if(fp = fopen(path, "r+b")) { gID = g; fseek(fp, GENRE, SEEK_END); if( fwrite(&gID, 1, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } else return 3; } if(i == 1) { if( (g=validGenre(newGenre)) != -1 ) { if(fp = fopen(path, "r+b")) { gID = g; chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, GENRE, SEEK_END); if( fwrite(&gID, 1, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } else return 3; } return 2; } /*---------------------------------------------*/ char *getComment(char *path) { FILE *fp; char *comment = (char *) calloc(1, 31); int len = 30; int i = checkVersion(path); if( i == 11 ) len = 28; if(i == 10 || i == 11) { if(fp = fopen(path, "rb")) { fseek(fp, COMMENT, SEEK_END); fread(comment, len, 1, fp); fclose(fp); return comment; } } if(i == 1) return "noTAG"; if(i == 2) return "FileNotFound"; } /*---------------------------------------------*/ int setComment(char *path, char *newComment) { FILE *fp; int len = 30; int i = checkID3v1(path); if( ID3v1==1 ) len = 28; if(i == 0) { if(fp = fopen(path, "r+b")) { fseek(fp, COMMENT, SEEK_END); if( fwrite(newComment, len, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } if(i == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, COMMENT, SEEK_END); if( fwrite(newComment, 30, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } return 2; } /*---------------------------------------------*/ int getYear(char *path) { FILE *fp; char *year = (char *) calloc(1, 5); int i = checkID3v1(path); if(i == 0) { if(fp = fopen(path, "rb")) { fseek(fp, YEAR, SEEK_END); fread(year, 4, 1, fp); fclose(fp); return atoi(year); } } if(i == 1) return -1; return -2; } /*---------------------------------------------*/ int setYear(char *path, int year) { FILE *fp; char *newYear = (char *) calloc(1, 5); int i = checkID3v1(path); itoa( year, newYear, 10 ); if( year < 0 || year > 9999 ) return 3; if(i == 0) { if(fp = fopen(path, "r+b")) { fseek(fp, YEAR, SEEK_END); if( fwrite(newYear, 4, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } if(i == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, YEAR, SEEK_END); if( fwrite(newYear, 4, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } } return 2; } /*---------------------------------------------*/ int getTrack(char *path) { FILE *fp; char track; int i = checkVersion(path); if(i == 11) { if(fp = fopen(path, "rb")) { fseek(fp, TRACK, SEEK_END); fread(&track, 1, 1, fp); fclose(fp); return (int) track; } } if( i == 10 ) return -1; if( i==1 ) return -2; if( i==2 ) return -3; } /*---------------------------------------------*/ int setTrack(char *path, int newTrack) { FILE *fp; char c_track = newTrack; int i = checkID3v1(path); if( newTrack<0 || newTrack>255 ) return 3; if(i == 0) { if(fp = fopen(path, "r+b")) { fseek(fp, TRACK-1, SEEK_END); if( fwrite( "", 1, 1, fp) ) { if( fwrite( &c_track, 1, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } else { fclose(fp); return 1; } } } if(i == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); fseek(fp, TRACK-1, SEEK_END); if( fwrite("", 1, 1, fp) ) { if( fwrite( &c_track, 1, 1, fp) ) { fclose(fp); return 0; } else { fclose(fp); return 1; } } else { fclose(fp); return 1; } } } return 2; } /*---------------------------------------------*/ mpeg3 getFullTag(char *path) { mpeg3 m; FILE *fp; char tmp, *c_year = (char *) calloc(1, 5); char *year = (char *) calloc(1, 5); int i = checkID3v1(path), v; m.title = (char *) calloc(1, 31); m.artist = (char *) calloc(1, 31); m.album = (char *) calloc(1, 31); m.comment = (char *) calloc(1, 31); m.genre = (char *) calloc(1, 31); m.err = NULL; m.track = -1; if(i == 0) { if(fp = fopen(path, "rb")) { fseek(fp, TITLE, SEEK_END); fread(m.title, 30, 1, fp); fread(m.artist, 30, 1, fp); fread(m.album, 30, 1, fp); fread(c_year, 4, 1, fp); m.year = atoi(c_year); v = checkVersion(path); if( v==10 ) fread(m.comment, 30, 1, fp); if( v==11 ) { fread(m.comment, 28, 1, fp); fseek(fp, TRACK, SEEK_END); fread(&tmp, 1, 1, fp); m.track = (int) tmp; } fread(&tmp, 1, 1, fp); if( (int)tmp<0 || (int)tmp>147 ) m.genre = ""; else m.genre = Genres[(int) tmp]; fclose(fp); } } if(i == 1) { m.err = (char *) calloc(1, 6); m.err = "noTAG"; } if(i == 2) { m.err = (char *) calloc(1, 15); m.err = "FileNotFound"; } return m; } /*---------------------------------------------*/ int setFullTag( char *path, char *title, char *artist, char *album, int year, char *comment, int track, char *genre ) { FILE *fp; int v = checkID3v1(path); char c_tmp = track, *c_year = (char *) calloc(1, 5); itoa( year, c_year, 10 ); if( year < 0 || year > 9999 ) return 3; if( track<0 || track>255 ) return 4; if(v == 0 ) { if(fp = fopen(path, "r+b")) { fseek(fp, TITLE, SEEK_END); if( fwrite(title, 30, 1, fp) ) { fwrite(artist, 30, 1, fp); fwrite(album, 30, 1, fp); fwrite(c_year, 4, 1, fp); if( ID3v1 == 0 ) fwrite(comment, 30, 1, fp); if( ID3v1 == 1 ) { fwrite(comment, 28, 1, fp); fwrite( "", 1, 1, fp); fwrite( &c_tmp, 1, 1, fp); } c_tmp = validGenre(genre); fwrite( &c_tmp, 1, 1, fp); fclose(fp); return 0; } else { fclose(fp); return 1; } } } if(v == 1) { if(fp = fopen(path, "r+b")) { chsize( fileno(fp), filelength( fileno(fp) ) + 128 ); fseek(fp, TAG, SEEK_END); fwrite("TAG", 3, 1, fp); if( fwrite(title, 30, 1, fp) ) { fwrite(artist, 30, 1, fp); fwrite(album, 30, 1, fp); fwrite(c_year, 4, 1, fp); if( ID3v1 == 0 ) fwrite(comment, 30, 1, fp); if( ID3v1 == 1 ) { fwrite(comment, 28, 1, fp); fwrite( "", 1, 1, fp); fwrite( &c_tmp, 1, 1, fp); } c_tmp = validGenre(genre); fwrite( &c_tmp, 1, 1, fp); fclose(fp); return 0; } else { fclose(fp); return 1; } } } return 2; } ID3v1.h: /****************************************************/ /* */ /* C-Library zum Auslesen von ID3v1-TAGs */ /* */ /* Version: 2.0.0.0. */ /* Autor: tgc_md */ /* Copyright: tgc_md */ /* Datum: 16.12.2002 */ /* Mail: coding@tool-garage.de */ /* */ /****************************************************/ #include <stdio.h> #include <string.h> #include <malloc.h> #include <io.h> #include <stdlib.h> typedef struct { char *title, *artist, *album, *comment, *genre, *err; int year, track; } mpeg3; int checkID3v1(char *path); int removeTag(char *path); char *getTitle(char *path); int setTitle(char *path, char *newTitle); char *getArtist(char *path); int setArtist(char *path, char *newArtist); char *getAlbum(char *path); int setAlbum(char *path, char *newAlbum); char *getGenre(char *path); int setGenre(char *path, char *newGenre); char *getComment(char *path); int setComment(char *path, char *newComment); int getYear(char *path); int setYear(char *path, int newYear); int getTrack(char *path); int setTrack(char *path, int newTrack); mpeg3 getFullTag(char *path); int setFullTag( char *path, char *title, char *artist, char *album, int year, char *comment, int track, char *genre ); Cheguei a este código a partir da source do PHP, nela tem referências :)Mas obrigado àqueles que postaram. Compartilhar este post Link para o post Compartilhar em outros sites
quitZAUMMM 18 Denunciar post Postado Abril 7, 2010 Obrigado por compartilhar a solução! http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif Compartilhar este post Link para o post Compartilhar em outros sites