Ejemplo n.º 1
0
Archivo: id3.c Proyecto: agranum/libv
int id3_write(const char *path, struct id3 *id3)
{
	struct id3 tmp;
	FILE *fp;

	assert(id3 != NULL);
	assert(path != NULL);

	if((fp = fopen(path, "r+")) == NULL)
	        return(-1);

	if(id3_read(path, &tmp) == 0) {
		if(fseek(fp, -1 * TAG_LENGTH, SEEK_END) == -1)
		        return(-1);
	} else {
		if(fseek(fp, 0, SEEK_END) == -1)
		        return(-1);
	}

        id3_write_tag(fp, id3);

	fclose(fp);

	return(0);
}
Ejemplo n.º 2
0
int mp3cue_write_id3(file_t *outfile, mp3cue_file_t *cuefile,
                     mp3cue_track_t *track) {
  return id3_write_tag(outfile,
                       cuefile->title,
                       track->performer ? track->performer : cuefile->performer,
                       track->title,
                       track->number,
                       "MP3 generated by mp3cue (http://bl0rg.net/software/poc/)");
  return 1;
}
Ejemplo n.º 3
0
int
tag_file (char *fn)
{
  FILE *fp;
  long sizelesstag;
  short found_tag;

  if (id3_open_file(&fp, fn, "rb") == FALSE)
    return FALSE;

  memset(ptrtag,0,sizeof(ID3_tag));

  if (id3_seek_header(fp, fn) == FALSE) return FALSE;
  sizelesstag = ftell(fp);

  if (!id3_read_file(ptrtag->tag, (sizeof(ptrtag->tag)-1), fp, fn))
    return FALSE;
/*
fread(&ptrtag->tag, (sizeof(ptrtag->tag)-1), 1, fp);
*/

  if (strcmp(ptrtag->tag, "TAG") != 0)
    found_tag = FALSE;
  else
   {found_tag = TRUE;
   }
    
  if (found_tag == FALSE)
  {
    id3_close_file(fp);

    user_message(FALSE, "*** No ID3 tag found in %s\n", fn);

    if (flags.strip_tag == TRUE)
      return TRUE;

    /* return FALSE so no renaming is performed on files without a tag */
    if (flags.no_tag_prompt == TRUE)
      return FALSE;

    printf("\n===> Entering new tag info for %s:\n", fn);
    if (ask_tag(fn) == FALSE)
      return FALSE;

    if(id3_write_tag(ptrtag,TRUE, fn) == FALSE)
      return FALSE;

    if (flags.tag_only == TRUE)
      return TRUE;

    if (id3_open_file(&fp, fn, "rb") == FALSE)
      return FALSE;

    if (id3_seek_header(fp, fn) == FALSE) return FALSE;

    if (!id3_read_file(ptrtag->tag, (sizeof(ptrtag->tag)-1), fp, fn))
      return FALSE;
  }  /*** Found a tag ****/
  else if (flags.force_tag == TRUE)    /* Always ask for a tag enabled? */
  {
    if (id3_read_tag(ptrtag,fp, fn) == FALSE)
      return FALSE;

    id3_close_file(fp);
    printf("\n===> Changing old tag info for %s:\n", fn);

    if (ask_tag(fn) == FALSE)
      return FALSE;

    if (id3_write_tag(ptrtag,FALSE, fn) == FALSE)
      return FALSE;

    if (flags.tag_only == TRUE)
      return TRUE;

    if (id3_open_file(&fp, fn, "rb") == FALSE)
      return FALSE;

    if (id3_seek_header(fp, fn) == FALSE) return FALSE;

    if (!id3_read_file(ptrtag->tag, (sizeof(ptrtag->tag)-1), fp, fn))
      return FALSE;
  }
  else if (flags.tag_only == TRUE)
  {
    id3_close_file(fp);
    user_message(FALSE, "===> Already has a tag: %s\n", fn);
    return TRUE;
  }
  else if (flags.strip_tag == TRUE)
  {
    id3_close_file(fp);
    if (id3_strip_tag(sizelesstag, fn) == FALSE)
      return FALSE;
    user_message(FALSE, "===> Removed ID3 tag from %s\n", fn);
    return TRUE;
  }

  if (id3_read_tag(ptrtag,fp, fn) == FALSE)
    return FALSE;

  resize_tag_field(ptrtag->songname);
  resize_tag_field(ptrtag->artist);
  resize_tag_field(ptrtag->album);
  resize_tag_field(ptrtag->year);
  resize_tag_field(ptrtag->u.v10.comment); // v1.1 tag handled
  id3_close_file(fp);
  return TRUE;
}