void do_expr(char *dir, char *file) { id3_tag_list *list, *fstlist; id3_tag *tag; mpeg_header *head; printf("Checking tag of file %s\n", file); res->checked++; head = mp_get_mpeg_header_from_file(file); if(!head) { printf("W A R N I N G: Cannot get mpeg header for file %s\n", file); } // TODO xfree(head); /* Get tag list */ if((fstlist = list = mp_get_tag_list_from_file(file))) { id3_content* cont; id3_text_content* tcont; id3_comment_content* ccont; do { char* curver = (list->tag->version == 2 ? "v2" : "v1"); tag = list->tag; if(!tag) { printf("%s: empty tag as list element\n"); } cont = mp_get_content(tag, MP_ARTIST); if(cont) { tcont = mp_parse_artist(cont); if(!tcont) printf("%s: artist text content is null", file); else if(!tcont->text) printf("%s: artist string provided with value null", file); else printf("artist %s: %s\n", curver, tcont->text); mp_free_text_content(tcont); mp_free_content(cont); } /* Beware! C&P code */ cont = mp_get_content(tag, MP_TITLE); if(cont) { tcont = mp_parse_title(cont); if(!tcont) printf("E R R O R: title text content is null", file); else if(!tcont->text) printf("E R R O R: artist string provided with value null", file); else printf("title %s: %s\n", curver, tcont->text); mp_free_text_content(tcont); mp_free_content(cont); } cont = mp_get_content(tag, MP_ALBUM); if(cont) { tcont = mp_parse_album(cont); if(!tcont) printf("E R R O R: album text content is null", file); else if(!tcont->text) printf("E R R O R: album string provided with value null", file); else printf("album %s: %s\n", curver, tcont->text); mp_free_text_content(tcont); mp_free_content(cont); } cont = mp_get_content(tag, MP_YEAR); if(cont) { tcont = mp_parse_year(cont); if(!tcont) printf("E R R O R: year text content is null", file); else if(!tcont->text) printf("E R R O R: year string provided with value null", file); else printf("year %s: %s\n", curver, tcont->text); mp_free_text_content(tcont); mp_free_content(cont); } cont = mp_get_content(tag, MP_TRACK); if(cont) { tcont = mp_parse_track(cont); if(!tcont) printf("E R R O R: track text content is null", file); else if(!tcont->text) printf("E R R O R: track string provided with value null", file); else printf("track %s: %s\n", curver, tcont->text); mp_free_text_content(tcont); mp_free_content(cont); } cont = mp_get_content(tag, MP_GENRE); if(cont) { tcont = mp_parse_genre(cont); if(!tcont) printf("E R R O R: genre text content is null", file); else if(!tcont->text) printf("E R R O R: genre string provided with value null", file); else printf("genre %s: %s\n", curver, tcont->text); mp_free_text_content(tcont); mp_free_content(cont); } cont = mp_get_content(tag, MP_COMMENT); if(cont) { ccont = mp_parse_comment(cont); if(!ccont) printf("E R R O R: comment text content is null", file); else if(!ccont->text) printf("E R R O R: comment string provided with value null", file); else printf("comment %s: %s\n", curver, ccont->text); mp_free_comment_content(ccont); mp_free_content(cont); } } while((list = list->next)); mp_free_list(fstlist); } else { puts("No tags found"); } }
int mp_set_content(id3_tag* tag, const int field, id3_content* new_content) { id3v1_tag *v1; id3v2_tag *v2; if(!tag) return MP_EERROR; if(tag->version == 2) { return mp_set_content_at_pos(tag, field, new_content, 0); } else if(tag->version == 1) { unsigned char c; char *my_val; int len, j; v1 = tag->tag; switch(field) { #define FLD(str1, str2, str3, str4) \ case str1:\ if(!new_content) v1->str2 = NULL;\ else\ {\ id3_text_content *tc = str4(new_content);\ if(strlen(tc->text) > str3 || tc->encoding != ISO_8859_1)\ {\ mp_convert_to_v2(tag);\ mp_free_text_content(tc);\ return mp_set_content(tag, field, new_content);\ }\ \ v1->str2 = tc->text;\ xfree(tc);\ }\ break; FLD(MP_ARTIST, artist, 30, mp_parse_artist); FLD(MP_TITLE, title, 30, mp_parse_title); FLD(MP_ALBUM, album, 30, mp_parse_album); FLD(MP_YEAR, year, 4, mp_parse_year); case MP_COMMENT: if(!new_content) v1->comment = NULL; else { id3_comment_content *tc = mp_parse_comment(new_content); if(strlen(tc->text) > 30 || tc->short_descr || tc->encoding != ISO_8859_1) { mp_convert_to_v2(tag); mp_free_comment_content(tc); return mp_set_content(tag, field, new_content); } v1->comment = xmallocd0(strlen(tc->text)+1, "mp_set_content:v1->comment"); memcpy(v1->comment, tc->text, strlen(tc->text)); mp_free_comment_content(tc); } break; case MP_TRACK: if(!new_content) v1->track = 0; else { id3_text_content *tc = mp_parse_track(new_content); #ifdef HAVE_STRTOL errno = 0; j = strtol(tc->text, (char **)NULL, 10); if(errno != ERANGE) v1->track = j; else return MP_EERROR; #else v1->track = atoi(tc->text); #endif mp_free_text_content(tc); } break; case MP_GENRE: if(!new_content) v1->genre = 0xFF; else { int b = 0, i; id3_text_content *tc = mp_parse_genre(new_content); /* i = strlen(tc->text); */ for(c = 0; c < GLL; c++) { if(!strcmp(genre_list[c], tc->text)) { v1->genre = c; b = 1; } } mp_free_text_content(tc); if(!b) { mp_convert_to_v2(tag); return mp_set_content(tag, field, new_content); } break; } } } else if(tag->version == -1) return MP_EVERSION; else return MP_EFNF; return 0; }