예제 #1
0
/*
 * Function id3_get_comment(frame)
 *
 *    Return string contents of a comment frame.
 *
 */
char *id3_get_comment(struct id3_frame *frame)
{
	int offset;
	/* Type check */
	if (frame->fr_desc->fd_id != ID3_COMM)
		return NULL;

	/* Check if frame is compressed */
	if (id3_decompress_frame(frame) == -1)
		return NULL;

	if (frame->fr_size < 5)
		return NULL;

	/* Skip language id */
	offset = 3;
	
	/* Skip the description */
	offset += id3_string_size(ID3_TEXT_FRAME_ENCODING(frame),
				  ID3_TEXT_FRAME_PTR(frame) + offset);
	if (offset >= frame->fr_size)
		return NULL;

	return id3_string_decode(ID3_TEXT_FRAME_ENCODING(frame),
				 ID3_TEXT_FRAME_PTR(frame) + offset);
}
예제 #2
0
/*
 * Function id3_get_text (frame)
 *
 *    Return string contents of frame.
 *
 */
char *id3_get_text(struct id3_frame *frame)
{
	int offset = 0;
	/* Type check */
	if (frame->fr_desc->fd_idstr[0] != 'T')
		return NULL;

	/* Check if frame is compressed */
	if (id3_decompress_frame(frame) == -1)
		return NULL;

	if (frame->fr_desc->fd_id == ID3_TXXX)
	{
		/*
		 * This is a user defined text frame.  Skip the description.
		 */
		offset = id3_string_size(ID3_TEXT_FRAME_ENCODING(frame),
					 ID3_TEXT_FRAME_PTR(frame));
		if (offset >= frame->fr_size)
			return NULL;
	}

	return id3_string_decode(ID3_TEXT_FRAME_ENCODING(frame),
				 ID3_TEXT_FRAME_PTR(frame) + offset);
}
예제 #3
0
static GSList* id3_get_content_v24(struct id3_frame *frame)
{
	GSList *list = NULL;
	int offset = 0;
	
	while (offset < frame->fr_size - 1)
	{
		int num;
		char *input, *endptr;

		input = id3_string_decode(ID3_TEXT_FRAME_ENCODING(frame),
					  ID3_TEXT_FRAME_PTR(frame) + offset);

		if (!input)
			break;

		/* Get ID3v1 genre number */
		num = strtol(input, &endptr, 10);
		if (endptr && endptr != input && *endptr == '\0' &&
		    num >= 0 && num < 256)
			list = push_element(list, num, NULL);
		else if (!strcmp(input, "RX"))
			list = push_element(list, -1, _("Remix"));
		else if (!strcmp(input, "CR"))
			list = push_element(list, -1, _("Cover"));
		else
			list = push_element(list, -1, input);

		offset += id3_string_size(ID3_TEXT_FRAME_ENCODING(frame),
					  ID3_TEXT_FRAME_PTR(frame) + offset);
	}

	return list;
}
예제 #4
0
/*
 * Function id3_get_text_desc (frame)
 *
 *    Get description part of a text frame.
 *
 */
char *id3_get_text_desc(struct id3_frame *frame)
{
	/* Type check */
	if (frame->fr_desc->fd_idstr[0] != 'T')
		return NULL;

	/* If predefined text frame, return description. */
	if (frame->fr_desc->fd_id != ID3_TXXX)
		return frame->fr_desc->fd_description;

	/* Check if frame is compressed */
	if (id3_decompress_frame(frame) == -1)
		return NULL;

	return id3_string_decode(ID3_TEXT_FRAME_ENCODING(frame),
				 ID3_TEXT_FRAME_PTR(frame));
}
예제 #5
0
/*
 * Function id3_get_text_number (frame)
 *
 *    Return string contents of frame translated to a positive
 *    integer, or -1 if an error occured.
 *
 */
int id3_get_text_number(struct id3_frame *frame)
{
	int number = 0;
	char* number_str;

	/* Check if frame is compressed */
	if (id3_decompress_frame(frame) == -1)
		return -1;

	number_str = id3_string_decode(ID3_TEXT_FRAME_ENCODING(frame),
				       ID3_TEXT_FRAME_PTR(frame));

	if (number_str != NULL)
	{
		sscanf(number_str, "%d", &number);
		free(number_str);
	}

	return number;
}
예제 #6
0
static GSList* id3_get_content_v23(struct id3_frame *frame)
{
	GSList *list = NULL;
	char *input, *ptr;

	input = id3_string_decode(ID3_TEXT_FRAME_ENCODING(frame),
				  ID3_TEXT_FRAME_PTR(frame));

	if (!input)
		return NULL;

	ptr = input;
	while (ptr[0] == '(' && ptr[1] != '(')
	{
		if (!strchr(ptr, ')'))
			break;

		if (strncmp(ptr, "(RX)", 4) == 0)
		{
			list = push_element(list, -1, _("Remix"));
			ptr += 4;
		}
		else if (strncmp(ptr, "(CR)", 4) == 0)
		{
			list = push_element(list, -1, _("Cover"));
			ptr += 4;
		}
		else
		{
			/* Get ID3v1 genre number */
			int num;
			char *endptr;
			num = strtol(ptr + 1, &endptr, 10);
			if (*endptr == ')' && num >= 0 && num <= 255)
			{
				list = push_element(list, num, NULL);
				ptr = endptr + 1;
			}
			else if (*endptr == ')')
				ptr = endptr + 1;
			else
				break;
		}
	}

	if (*ptr == 0) {
		/* Unexpected end of ID */
		g_slist_free(list);
		g_free(input);
		return NULL;
	}

	/*
	 * Add plaintext refinement.
	 */
	if (strncmp(ptr, "((", 2))
		ptr++;
	list = push_element(list, -1, ptr);
	g_free(input);

	return list;
}