Esempio n. 1
0
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");
  }
}
Esempio n. 2
0
int 
mp_convert_to_v1(id3_tag *tag)
{
	id3v1_tag *v1;
	id3_tag* tmp;
	id3_content* content;
	id3_text_content* tc;
	id3_comment_content* cc;
	char* c;
	int j, k = 0;
	
	if(tag->version == 1) return 0;
	else if(tag->version == -1) return MP_EVERSION;
	
	v1 = XMALLOCD0(id3v1_tag, "mp_convert_to_v1:v1");
	
	content = mp_get_content(tag, MP_ARTIST);
	tc = mp_parse_artist(content);
	v1->artist = tc->text;
	xfree(tc);
	mp_free_content(content);
	
	content = mp_get_content(tag, MP_TITLE);
	tc = mp_parse_title(content);
	v1->title = tc->text;
	xfree(tc);
	mp_free_content(content);
	
	content = mp_get_content(tag, MP_ALBUM);
	tc = mp_parse_album(content);
	v1->album = tc->text;
	xfree(tc);
	mp_free_content(content);
	
	content = mp_get_content(tag, MP_YEAR);
	tc = mp_parse_year(content);
	v1->year = tc->text;
	xfree(tc);
	mp_free_content(content);
	
	content = mp_get_content(tag, MP_COMMENT);
	cc = mp_parse_comment(content);
	v1->comment = cc->text;
	xfree(cc->language);
	xfree(cc->short_descr);
	xfree(cc);
	mp_free_content(content);
	
	content = mp_get_content(tag, MP_TRACK);
	tc = mp_parse_track(content);
	c = tc->text;
	if(c)
	{
#ifdef HAVE_STRTOL
		errno = 0;
		j = strtol(c, (char **)NULL, 10);
		if(errno != ERANGE) v1->track = j;
		else v1->track = 0;
#else
		v1->track = atoi(c);
#endif
	}
	else v1->track = 0;
	xfree(c);
	mp_free_text_content(tc);
	mp_free_content(content);
	
	content = mp_get_content(tag, MP_GENRE);
	tc = mp_parse_genre(content);
	c = tc->text;
	for(j = 0; c, j < GLL; j++) {
		if(!strcmp(genre_list[j], c))
		{
			v1->genre = j;
			k = 1;
		}
	}
	if(!c) v1->genre = 0xFF;
	xfree(c);
	mp_free_text_content(tc);
	mp_free_content(content);
	
	id3v1_truncate_tag(v1);
	
	id3v2_free_tag(tag->tag);
	
	tag->version = 1;
	tag->tag = v1;
	
	return 0;
}