Ejemplo n.º 1
0
char * getTagString(struct id3_tag *tag, const char *frameName) {
	struct id3_frame *frame;
	union id3_field *field;
	int i;
	const id3_ucs4_t *unicode;
	char *ret;
	
	frame = id3_tag_findframe(tag,frameName,0);
	if(!frame) {
		fprintf(stdout,"No frame\n");
		return NULL;
	}
	for(i=0;;i++) {
		field = id3_frame_field(frame,i);
		if(!field) {
			break;
		}
		if(id3_field_type(field) == ID3_FIELD_TYPE_STRINGLIST) {
			unicode = id3_field_getstrings(field,0);
			if(unicode) {
				id3_utf8_t *str;
				str = id3_ucs4_utf8duplicate(unicode);
				ret = (char *) str;
			}
			
		}
	}
	
	return ret;
}
Ejemplo n.º 2
0
wchar_t* GetMP3Tag(const id3_tag* tag, const char* name)
{
	wchar_t* content = NULL;
	id3_frame* frame = id3_tag_findframe(tag, name, 0);
	if (frame != NULL)
	{
		id3_field* field = id3_frame_field(frame, 0);
		id3_field_textencoding encoding = id3_field_gettextencoding(field);
		field = id3_frame_field(frame, 1);

		switch (id3_field_type(field))
		{
		case ID3_FIELD_TYPE_STRING:
			content = GetMP3Text(encoding, field, id3_field_getstring(field));
			break;

		case ID3_FIELD_TYPE_STRINGFULL:						
			content = GetMP3Text(encoding, field, id3_field_getfullstring(field));
			break;

		case ID3_FIELD_TYPE_STRINGLIST:
			{				
				DWORD dataLength = 0, bufferLength = 0;
				unsigned int n = id3_field_getnstrings(field);
				for (unsigned int i = 0; i < n; i++)
				{
					wchar_t* p = GetMP3Text(encoding, field, id3_field_getstrings(field, i));
					if (p == NULL)
						continue;

					AppendBuffer((char**)&content, dataLength, bufferLength, (const char*)p, wcslen(p) * 2 + 1);
					SAFE_DELETE_ARRAY(p);
				}
			}
			break;
		}
	}

	return content;
}
Ejemplo n.º 3
0
int BarFlyID3AddCover(struct id3_tag* tag, uint8_t const* cover_art,
		size_t cover_size, BarSettings_t const* settings)
{
	/*
	 * http://flac.sourceforge.net/api/group__flac__format.html#ga113
	 */
	int const PICTURE_TYPE_FRONT_COVER = 3;

	char const BAR_FLY_ID3_FRAME_PICTURE[] = "APIC";

	int exit_status = 0;
	int status;
	struct id3_frame* frame = NULL;
	union id3_field* field;
	int index;
	char* mime_type;

	assert(tag != NULL);
	assert(cover_art != NULL);
	assert(settings != NULL);

	/*
	 * Get a new picture frame.
	 */
	frame = id3_frame_new(BAR_FLY_ID3_FRAME_PICTURE);
	if (frame == NULL) {
		BarUiMsg(settings, MSG_ERR, "Failed to create new frame (type = %s).\n", 
				BAR_FLY_ID3_FRAME_PICTURE);
		goto error;
	}
	
	/*
	 * Go through all the frame fields setting the mime type, image type, and
	 * the image data.
	 */
	index = 0;
	field = id3_frame_field(frame, index);
	while (field != NULL) {
		switch (id3_field_type(field)) {
			/*
			 * Set the cover art mime type.
			 */
			case (ID3_FIELD_TYPE_LATIN1):
				if ((cover_art[0] == 0xFF) && (cover_art[1] == 0xD8)) {
					mime_type = "image/jpeg";
				} else if ((cover_art[0] == 0x89) &&
				           (cover_art[1] == 0x50) &&
				           (cover_art[2] == 0x4E) &&
				           (cover_art[3] == 0x47) &&
				           (cover_art[4] == 0x0D) &&
				           (cover_art[5] == 0x0A) &&
				           (cover_art[6] == 0x1A) &&
				           (cover_art[7] == 0x0A)) {
					mime_type = "image/png";
				} else {
					mime_type = NULL;
				}

				id3_field_setlatin1(field, (id3_latin1_t const*)mime_type);
				break;

			/*
			 * Designate this as the front cover.
			 */
			case (ID3_FIELD_TYPE_INT8):
				id3_field_setint(field, PICTURE_TYPE_FRONT_COVER);
				break;

			/*
			 * Set the image data.
			 */
			case (ID3_FIELD_TYPE_BINARYDATA):
				id3_field_setbinarydata(field, cover_art, cover_size);
				break;

			default:
				break;
		}

		index++;
		field = id3_frame_field(frame, index);
	}

	/*
	 * Attach the frame to the tag.
	 */
	status = id3_tag_attachframe(tag, frame);
	if (status != 0) {
		BarUiMsg(settings, MSG_ERR, "Failed to attach cover art frame.\n");
		goto error;
	}

	goto end;

error:
	if (frame != NULL) {
		id3_frame_delete(frame);
	}

	exit_status = -1;

end:
	return exit_status;
}
Ejemplo n.º 4
0
int BarFlyID3AddFrame(struct id3_tag* tag, char const* type,
		char const* value, BarSettings_t const* settings)
{
	int exit_status = 0;
	int status;
	struct id3_frame* frame = NULL;
	union id3_field* field;
	id3_ucs4_t* ucs4 = NULL;
	int index;

	assert(tag != NULL);
	assert(type != NULL);
	assert(value != NULL);
	assert(settings != NULL);

	/*
	 * Create the frame.
	 */
	frame = id3_frame_new(type);
	if (frame == NULL) {
		BarUiMsg(settings, MSG_ERR, "Failed to create new frame (type = %s).\n",
				type);
		goto error;
	}

	frame->flags &= ~ID3_FRAME_FLAG_FORMATFLAGS;

	/*
	 * Get the string list field of the frame.
	 */
	index = 0;
	do {
		field = id3_frame_field(frame, index);
		index++;
	} while (id3_field_type(field) != ID3_FIELD_TYPE_STRINGLIST);
	assert(id3_field_type(field) == ID3_FIELD_TYPE_STRINGLIST);

	/*
	 * Add the value as a string to the field.
	 */
	ucs4 = id3_latin1_ucs4duplicate((id3_latin1_t*)value);
	if (ucs4 == NULL) {
		BarUiMsg(settings, MSG_ERR, "Could not allocate memory.\n");
		goto error;
	}

	status = id3_field_addstring(field, ucs4);
	if (status != 0) {
		BarUiMsg(settings, MSG_ERR, "Failed to set field value (value = %s).\n",
				value);
		goto error;
	}

	/*
	 * Attach the frame to the tag.
	 */
	status = id3_tag_attachframe(tag, frame);
	if (status != 0) {
		BarUiMsg(settings, MSG_ERR, "Failed to attach frame (type = %s).\n",
				type);
		goto error;
	}

	goto end;
	
error:
	if (frame != NULL) {
		id3_frame_delete(frame);
	}

	exit_status = -1;

end:
	if (ucs4 != NULL) {
		free(ucs4);
	}

	return exit_status;
}
Ejemplo n.º 5
0
Archivo: id3read.c Proyecto: cjd/mtpfs
static gchar *
getFrameText (struct id3_tag *tag, char *frame_name)
{
  const id3_ucs4_t *string;
  struct id3_frame *frame;
  union id3_field *field;
  gchar *utf8 = NULL;
  enum id3_field_textencoding encoding = ID3_FIELD_TEXTENCODING_ISO_8859_1;

  frame = id3_tag_findframe (tag, frame_name, 0);
  if (!frame)
    return NULL;

  /* Find the encoding used for the field */
  field = id3_frame_field (frame, 0);
  //printf ("field: %p\n", field);
  if (field && (id3_field_type (field) == ID3_FIELD_TYPE_TEXTENCODING))
    {
      encoding = field->number.value;
      //printf ("encoding: %d\n", encoding);
    }

  if (strcmp (frame_name, ID3_FRAME_COMMENT) == 0)
    field = id3_frame_field (frame, 3);
  else
    field = id3_frame_field (frame, 1);

  //printf ("field: %p\n", field);

  if (!field)
    return NULL;

  if (strcmp (frame_name, ID3_FRAME_COMMENT) == 0)
    string = id3_field_getfullstring (field);
  else
    string = id3_field_getstrings (field, 0);

  // g_debug("string: %s\n", string);

  if (!string)
    return NULL;

  if (strcmp (frame_name, ID3_FRAME_GENRE) == 0)
    string = id3_genre_name (string);

  if (encoding == ID3_FIELD_TEXTENCODING_ISO_8859_1)
    {
      /* ISO_8859_1 is just a "marker" -- most people just drop
         whatever coding system they are using into it, so we use
         charset_to_utf8() to convert to utf8 */
      id3_latin1_t *raw = id3_ucs4_latin1duplicate (string);
      utf8 = (gchar *) charset_to_utf8 (raw);
      g_free (raw);
    }
  else
    {
      /* Standard unicode is being used -- we won't have to worry
         about charsets then. */
      // g_debug("This frame is a Unicode frame!\n");
      utf8 = (gchar *) id3_ucs4_utf8duplicate (string);
    }
  // g_debug("Found tag: %s, value: %s\n", frame_name, utf8);
  return utf8;
}