Example #1
0
static int _id3_find_and_set_frame(ID3Tag *tag, ID3_FrameID id, const char *value)
{
  ID3Frame *frame;
  ID3Field *field;

  /* Remove existing tag to avoid issues with trashed frames. */
  while ((frame = ID3Tag_FindFrameWithID(tag, id)))
    ID3Tag_RemoveFrame(tag, frame);

  if (value && strlen(value) > 0) {
    frame = ID3Frame_NewID(id);
    g_assert(frame);

    ID3Tag_AttachFrame(tag, frame);

    field = ID3Frame_GetField(frame, ID3FN_TEXT);

    if (field)
      ID3Field_SetASCII(field, value); //TODO: UTF8
    else
      return 1;
  }

  return 0;
}
Example #2
0
void
set_TagField (ID3Tag * myTag, char *data, ID3_FrameID id)
{
  ID3Frame *myFrame;
  ID3Frame *pFrame;
  char *conv_str = NULL;

  myFrame = ID3Frame_NewID (id);

  pFrame = ID3Tag_FindFrameWithID (myTag, id);

  if (pFrame != NULL)
    {
      ID3Tag_RemoveFrame (myTag, pFrame);
    }

  conv_str = g_locale_from_utf8 (data, -1, NULL, NULL, NULL);

  ID3Field_SetASCII (ID3Frame_GetField (myFrame, ID3FN_TEXT), conv_str);
  ID3Tag_AttachFrame (myTag, myFrame);

  g_free (conv_str);

  return;
}
Example #3
0
/* Set a field (by pointer) to the requested id3 value */
static void set_field(char** out, ID3Tag *tag, ID3_FieldID id, ID3_FrameID fid)
{
        ID3Frame *frame = NULL;
        ID3Field *field = NULL;
        size_t size;
        char *set;

        frame = ID3Tag_FindFrameWithID(tag, fid);
        if (frame == NULL)
                goto end;

        field = ID3Frame_GetField(frame, id);
        if (field == NULL)
                goto end;

        size = ID3Field_Size(field);
        size += 1;
        set = malloc(size);
        if (!set)
                goto end;
        ID3Field_GetASCII(field, set, size);
        *out = g_strescape(set, NULL);
        free(set);
end:
        if (!frame || !field)
                *out = NULL;
        return;
}
Example #4
0
/* get the field from a frame from a tag. */
static ID3Field *get_id3_field(ID3Tag *id3tag, ID3_FrameID frameid,
			       ID3_FieldID fieldid)
{
  ID3Frame *frame = NULL;
  
  frame = get_id3_frame(id3tag, frameid);
  
  if (frame != NULL) {
    /* ok got the title. now get the TEXT field in it. */
    ID3Field *field = ID3Frame_GetField(frame, fieldid);

    return field;
  }

  return NULL;
}
Example #5
0
/*
 * Read id3v1.x / id3v2 tag and load data into the File_Tag structure using id3lib functions.
 * Returns true on success, else false.
 * If a tag entry exists (ex: title), we allocate memory, else value stays to NULL
 */
static FLAC__bool local__get_tag(const char *filename, FLAC_Plugin__CanonicalTag *tag)
{
	FILE *file;
	ID3Tag *id3_tag = 0; /* Tag defined by id3lib */
	char *string, *string1;

	FLAC__ASSERT(0 != filename);
	FLAC__ASSERT(0 != tag);

	if(0 == (file = fopen(filename, "r"))) {
#ifdef DEBUG
		fprintf(stderr, _("ERROR while opening file: '%s' (%s).\n\a"), filename, strerror(errno));
#endif
		return false;
	}
	fclose(file); /* We close it cause id3lib opens/closes file itself */


	/* Get data from tag */
	if(0 != (id3_tag = ID3Tag_New())) {
		ID3Frame *id3_frame;
		ID3Field *id3_field;
		luint frm_size;
		luint num_chars;
		size_t field_num = 0; /* First field */

		/* Link the file to the tag */
		frm_size = local__ID3Tag_Link_wrapper(id3_tag, filename);

		string = malloc(ID3V2_MAX_STRING_LEN+1);

		/*********
		 * Title *
		 *********/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_TITLE))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				/* Note: if 'num_chars' is equal to 0, then the field is empty or corrupted! */
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					local__strip(string);
					tag->title = strdup(string);
				}
			}
		}


		/************
		 * Composer *
		 ************/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_COMPOSER))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					local__strip(string);
					tag->composer = strdup(string);
				}
			}
		}


		/**********
		 * Artist *
		 **********/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_LEADARTIST))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					local__strip(string);
					tag->performer = strdup(string);
				}
			}
		}


		/*********
		 * Album *
		 *********/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_ALBUM))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					local__strip(string);
					tag->album = strdup(string);
				}
			}
		}


		/********
		 * Year *
		 ********/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_YEAR))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					char *tmp_str;

					local__strip(string);

					/* Fix for id3lib 3.7.x: if the id3v1.x tag was filled with spaces
					 * instead of zeroes, then the year field contains garbages! */
					tmp_str = string;
					while (isdigit(*tmp_str)) tmp_str++;
					*tmp_str = 0;
					/* End of fix for id3lib 3.7.x */

					local__strip(string);
					tag->year_recorded = strdup(string);
					tag->year_performed = strdup(string);
				}
			}
		}


		/*************************
		 * Track and Total Track *
		 *************************/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_TRACKNUM))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					local__strip(string);

					string1 = strchr(string, '/');
					if (NUMBER_TRACK_FORMATED) {
						if (string1) {
							/* Just to have numbers like this : '01', '05', '12', ... */
							tag->tracks_in_album = malloc(64);
							sprintf(tag->tracks_in_album, "%.2d", atoi(string1+1));
							*string1 = '\0';
						}
						/* Just to have numbers like this : '01', '05', '12', ... */
						tag->track_number = malloc(64);
						sprintf(tag->track_number, "%.2d", atoi(string));
					}
					else {
						if (string1) {
							tag->tracks_in_album = strdup(string1+1);
							*string1 = '\0';
						}
						tag->track_number = strdup(string);
					}
				}
			}
		}


		/*********
		 * Genre *
		 *********/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_CONTENTTYPE))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				/*
				 * We manipulate only the name of the genre
				 */
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					char *tmp;

					local__strip(string);

					if((string[0]=='(') && (tmp=strchr(string, ')')) && (strlen((tmp+1))>0)) {
						/* Convert a genre written as '(3)Dance' into 'Dance' */
						tag->genre = strdup(tmp+1);

					}
					else if((string[0]=='(') && (tmp=strchr(string, ')'))) {
						/* Convert a genre written as '(3)' into 'Dance' */
						*tmp = 0;
						tag->genre = strdup(local__genre_to_string((unsigned)atoi(string+1)));

					}
					else {
						/* Genre is already written as 'Dance' */
						tag->genre = strdup(string);
					}
				}
			}
		}


		/***********
		 * Comment *
		 ***********/
		if(0 != (id3_frame = ID3Tag_FindFrameWithID(id3_tag, ID3FID_COMMENT))) {
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_TEXT))) {
				if((num_chars = local__ID3Field_GetASCII_wrapper(id3_field, string, ID3V2_MAX_STRING_LEN, field_num)) > 0 && string != NULL) {
					local__strip(string);
					tag->comment = strdup(string);
				}
			}
#if 0
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_DESCRIPTION))) {
				char *comment1 = calloc(MAX_STRING_LEN+1);
				num_chars = ID3Field_GetASCII(id3_field, comment1, MAX_STRING_LEN, Item_Num);
				free(comment1);
			}
			if(0 != (id3_field = ID3Frame_GetField(id3_frame, ID3FN_LANGUAGE))) {
				char *comment2 = calloc(MAX_STRING_LEN+1);
				num_chars = ID3Field_GetASCII(id3_field, comment2, MAX_STRING_LEN, Item_Num);
				free(comment2);
			}
#endif
		}
		free(string);

		/* Free allocated data */
		ID3Tag_Delete(id3_tag);
	}

	return true;
}
Example #6
0
/* Save the ID3 to the file */
void List_SaveID3(HWND hwndApp, HWND hwndList, char *filename)
{
    LV_ITEM lvi;
    ID3ITEM *pItem1;
    int i, items;
    ID3Tag *tag;
    ID3Frame *frame;
    ID3Field *field;
    
    /* Strip the tag first, before completely rewriting it */
    if ((tag = ID3Tag_New()) != NULL)
    {
        ID3Tag_Link(tag, filename);
        ID3Tag_Strip(tag, ID3TT_ALL);
        ID3Tag_Clear(tag);

        if (SendMessage(GetDlgItem(hwndApp, IDC_ID3V2TAG), BM_GETCHECK, 0, 0) == BST_UNCHECKED)
        {
            /* No frames saved */
            ID3Tag_Delete(tag);
            EnableWindow(GetDlgItem(hwndApp, IDC_ID3V2TAG), FALSE);
            ListView_DeleteAllItems(hwndList);
            return;
        }

        /* First get the number of items */
        items = ListView_GetItemCount(hwndList);

        if (items > 0)
        {
            for (i = 0; i < items; i++)
            {
                lvi.mask = LVIF_PARAM;
                lvi.iItem = i;
                lvi.iSubItem = 0;

                if (ListView_GetItem(hwndList, &lvi) == TRUE)
                {
                    pItem1 = (ID3ITEM*)lvi.lParam;

                    frame = ID3Frame_NewID(pItem1->frameId);

                    switch (pItem1->frameId)
                    {
                    case ID3FID_ALBUM:            case ID3FID_BPM:
                    case ID3FID_COMPOSER:         case ID3FID_CONTENTTYPE:
                    case ID3FID_COPYRIGHT:        case ID3FID_DATE:
                    case ID3FID_PLAYLISTDELAY:    case ID3FID_ENCODEDBY:
                    case ID3FID_LYRICIST:         case ID3FID_FILETYPE:
                    case ID3FID_TIME:             case ID3FID_CONTENTGROUP:
                    case ID3FID_TITLE:            case ID3FID_SUBTITLE:
                    case ID3FID_INITIALKEY:       case ID3FID_LANGUAGE:
                    case ID3FID_SONGLEN:          case ID3FID_MEDIATYPE:
                    case ID3FID_ORIGALBUM:        case ID3FID_ORIGFILENAME:
                    case ID3FID_ORIGLYRICIST:     case ID3FID_ORIGARTIST:
                    case ID3FID_ORIGYEAR:         case ID3FID_FILEOWNER:
                    case ID3FID_LEADARTIST:       case ID3FID_BAND:
                    case ID3FID_CONDUCTOR:        case ID3FID_MIXARTIST:
                    case ID3FID_PARTINSET:        case ID3FID_PUBLISHER:
                    case ID3FID_TRACKNUM:         case ID3FID_RECORDINGDATES:
                    case ID3FID_NETRADIOSTATION:  case ID3FID_NETRADIOOWNER:
                    case ID3FID_SIZE:             case ID3FID_ISRC:
                    case ID3FID_ENCODERSETTINGS:  case ID3FID_YEAR:
                    {
                        field = ID3Frame_GetField(frame, ID3FN_TEXT);
                        ID3Field_SetASCII(field, pItem1->aCols[1]);
                        ID3Tag_AddFrame(tag, frame);
                        break;
                    }
                    case ID3FID_USERTEXT:
                    case ID3FID_COMMENT: /* Can also contain an extra language field (but not used now) */
                    case ID3FID_UNSYNCEDLYRICS: /* Can also contain an extra language field (but not used now) */
                    {
                        field = ID3Frame_GetField(frame, ID3FN_DESCRIPTION);
                        ID3Field_SetASCII(field, pItem1->aCols[0]);
                        field = ID3Frame_GetField(frame, ID3FN_TEXT);
                        ID3Field_SetASCII(field, pItem1->aCols[1]);
                        ID3Tag_AddFrame(tag, frame);
                        break;
                    }
                    case ID3FID_WWWAUDIOFILE:     case ID3FID_WWWARTIST:
                    case ID3FID_WWWAUDIOSOURCE:   case ID3FID_WWWCOMMERCIALINFO:
                    case ID3FID_WWWCOPYRIGHT:     case ID3FID_WWWPUBLISHER:
                    case ID3FID_WWWPAYMENT:       case ID3FID_WWWRADIOPAGE:
                    {
                        field = ID3Frame_GetField(frame, ID3FN_URL);
                        ID3Field_SetASCII(field, pItem1->aCols[1]);
                        ID3Tag_AddFrame(tag, frame);
                        break;
                    }
                    case ID3FID_WWWUSER:
                    {
                        field = ID3Frame_GetField(frame, ID3FN_DESCRIPTION);
                        ID3Field_SetASCII(field, pItem1->aCols[0]);
                        field = ID3Frame_GetField(frame, ID3FN_URL);
                        ID3Field_SetASCII(field, pItem1->aCols[1]);
                        ID3Tag_AddFrame(tag, frame);
                        break;
                    }
                    default:
                        break;
                    }
                }
            }
            ID3Tag_UpdateByTagType(tag, ID3TT_ID3V2);
        }

        ID3Tag_Delete(tag);
    }
}
Example #7
0
void FillID3List(HWND hwndDlg, HWND hwndList, char *filename)
{
    ID3Tag *tag;
    ID3Frame *frame;
    ID3Field *field;
    ID3_FrameID eFrameID;
    char info[1024];
    int numFrames;
    int i;
    int iItem = 0;


    if ((tag = ID3Tag_New()) != NULL)
    {
        ID3Tag_Link(tag, filename);

        numFrames = ID3Tag_NumFrames(tag);

        for (i = 0; i < numFrames; i++)
        {
            iItem++;

            frame = ID3Tag_GetFrameNum(tag, i);
            eFrameID = ID3Frame_GetID(frame);

            switch (eFrameID)
            {
            case ID3FID_ALBUM:            case ID3FID_BPM:
            case ID3FID_COMPOSER:         case ID3FID_CONTENTTYPE:
            case ID3FID_COPYRIGHT:        case ID3FID_DATE:
            case ID3FID_PLAYLISTDELAY:    case ID3FID_ENCODEDBY:
            case ID3FID_LYRICIST:         case ID3FID_FILETYPE:
            case ID3FID_TIME:             case ID3FID_CONTENTGROUP:
            case ID3FID_TITLE:            case ID3FID_SUBTITLE:
            case ID3FID_INITIALKEY:       case ID3FID_LANGUAGE:
            case ID3FID_SONGLEN:          case ID3FID_MEDIATYPE:
            case ID3FID_ORIGALBUM:        case ID3FID_ORIGFILENAME:
            case ID3FID_ORIGLYRICIST:     case ID3FID_ORIGARTIST:
            case ID3FID_ORIGYEAR:         case ID3FID_FILEOWNER:
            case ID3FID_LEADARTIST:       case ID3FID_BAND:
            case ID3FID_CONDUCTOR:        case ID3FID_MIXARTIST:
            case ID3FID_PARTINSET:        case ID3FID_PUBLISHER:
            case ID3FID_TRACKNUM:         case ID3FID_RECORDINGDATES:
            case ID3FID_NETRADIOSTATION:  case ID3FID_NETRADIOOWNER:
            case ID3FID_SIZE:             case ID3FID_ISRC:
            case ID3FID_ENCODERSETTINGS:  case ID3FID_YEAR:
            {
                LV_ITEM lvi;
                ID3ITEM *pItem = LocalAlloc(LPTR, sizeof(ID3ITEM));

                /* Initialize LV_ITEM members that are common to all items. */
                lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
                lvi.state = 0;
                lvi.stateMask = 0;
                lvi.pszText = LPSTR_TEXTCALLBACK;   /* app. maintains text */
                lvi.iImage = 0;
                lvi.iItem = iItem;
                lvi.iSubItem = 0;

                pItem->frameId = eFrameID;
                pItem->aCols[0] = GetFrameDesc(eFrameID);

                field = ID3Frame_GetField(frame, ID3FN_TEXT);
                ID3Field_GetASCII(field, info, 1024, 1);
                if (eFrameID == ID3FID_CONTENTTYPE)
                    pItem->aCols[1] = GetGenre(info);
                else
                    pItem->aCols[1] = DupString(info);

                lvi.lParam = (LPARAM)pItem;    /* item data */

                /* Add the item. */
                ListView_InsertItem(hwndList, &lvi);

                break;
            }
            case ID3FID_USERTEXT:
            case ID3FID_COMMENT: /* Can also contain an extra language field (but not used now) */
            case ID3FID_UNSYNCEDLYRICS: /* Can also contain an extra language field (but not used now) */
            {
                LV_ITEM lvi;
                ID3ITEM *pItem = LocalAlloc(LPTR, sizeof(ID3ITEM));

                /* Initialize LV_ITEM members that are common to all items. */
                lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
                lvi.state = 0;
                lvi.stateMask = 0;
                lvi.pszText = LPSTR_TEXTCALLBACK;   /* app. maintains text */
                lvi.iImage = 0;
                lvi.iItem = iItem;
                lvi.iSubItem = 0;

                pItem->frameId = eFrameID;

                field = ID3Frame_GetField(frame, ID3FN_DESCRIPTION);
                ID3Field_GetASCII(field, info, 1024, 1);
                pItem->aCols[0] = DupString(info);

                field = ID3Frame_GetField(frame, ID3FN_TEXT);
                ID3Field_GetASCII(field, info, 1024, 1);
                pItem->aCols[1] = DupString(info);

                lvi.lParam = (LPARAM)pItem;    /* item data */

                /* Add the item. */
                ListView_InsertItem(hwndList, &lvi);

                break;
            }
            case ID3FID_WWWAUDIOFILE:       case ID3FID_WWWARTIST:
            case ID3FID_WWWAUDIOSOURCE:     case ID3FID_WWWCOMMERCIALINFO:
            case ID3FID_WWWCOPYRIGHT:       case ID3FID_WWWPUBLISHER:
            case ID3FID_WWWPAYMENT:         case ID3FID_WWWRADIOPAGE:
            {
                LV_ITEM lvi;
                ID3ITEM *pItem = LocalAlloc(LPTR, sizeof(ID3ITEM));

                /* Initialize LV_ITEM members that are common to all items. */
                lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
                lvi.state = 0;
                lvi.stateMask = 0;
                lvi.pszText = LPSTR_TEXTCALLBACK;   /* app. maintains text */
                lvi.iImage = 0;
                lvi.iItem = iItem;
                lvi.iSubItem = 0;

                pItem->frameId = eFrameID;

                pItem->aCols[0] = GetFrameDesc(eFrameID);

                field = ID3Frame_GetField(frame, ID3FN_URL);
                ID3Field_GetASCII(field, info, 1024, 1);
                pItem->aCols[1] = DupString(info);

                lvi.lParam = (LPARAM)pItem;    /* item data */

                /* Add the item. */
                ListView_InsertItem(hwndList, &lvi);

                break;
            }
            case ID3FID_WWWUSER:
            {
                LV_ITEM lvi;
                ID3ITEM *pItem = LocalAlloc(LPTR, sizeof(ID3ITEM));

                /* Initialize LV_ITEM members that are common to all items. */
                lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
                lvi.state = 0;
                lvi.stateMask = 0;
                lvi.pszText = LPSTR_TEXTCALLBACK;   /* app. maintains text */
                lvi.iImage = 0;
                lvi.iItem = iItem;
                lvi.iSubItem = 0;

                pItem->frameId = eFrameID;

                field = ID3Frame_GetField(frame, ID3FN_DESCRIPTION);
                ID3Field_GetASCII(field, info, 1024, 1);
                pItem->aCols[0] = DupString(info);

                field = ID3Frame_GetField(frame, ID3FN_URL);
                ID3Field_GetASCII(field, info, 1024, 1);
                pItem->aCols[1] = DupString(info);

                lvi.lParam = (LPARAM)pItem;    /* item data */

                /* Add the item. */
                ListView_InsertItem(hwndList, &lvi);

                break;
            }
            default:
                break;
            }
        }
        ID3Tag_Delete(tag);
    }
}
Example #8
0
/* Get the title from the file */
void GetID3FileTitle(char *filename, char *title, char *format)
{
    ID3Tag *tag;
    ID3Frame *frame;
    ID3Field *field;
    char buffer[255];
    int some_info = 0;
    char *in = format;
    char *out = title;
    char *bound = out + (MAX_PATH - 10 - 1);


    if ((tag = ID3Tag_New()) != NULL)
    {
        ID3Tag_Link(tag, filename);

        while (*in && out < bound)
        {
            switch (*in) {
            case '%':
                ++in;
                break;

            default:
                *out++ = *in++;
                continue;
            }

            /* handle % escape sequence */
            switch (*in++) {
            case '0':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_TRACKNUM)) != NULL) {
                    int size;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    lstrcpy(out, buffer); out += size;
                    some_info = 1;
                }
                break;
            case '1':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_LEADARTIST)) != NULL) {
                    int size;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    lstrcpy(out, buffer); out += size;
                    some_info = 1;
                }
                break;
            case '2':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_TITLE)) != NULL) {
                    int size;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    lstrcpy(out, buffer); out += size;
                    some_info = 1;
                }
                break;
            case '3':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_ALBUM)) != NULL) {
                    int size;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    lstrcpy(out, buffer); out += size;
                    some_info = 1;
                }
                break;
            case '4':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_YEAR)) != NULL) {
                    int size;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    lstrcpy(out, buffer); out += size;
                    some_info = 1;
                }
                break;
            case '5':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_COMMENT)) != NULL) {
                    int size;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    lstrcpy(out, buffer); out += size;
                    some_info = 1;
                }
                break;
            case '6':
                if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_CONTENTTYPE)) != NULL) {
                    int size; char *tmp;
                    field = ID3Frame_GetField(frame, ID3FN_TEXT);
                    size = ID3Field_GetASCII(field, buffer, 255, 1);
                    tmp = GetGenre(buffer);
                    lstrcpy(out, tmp); out += size;
                    some_info = 1;
                }
                break;
            case '7':
            {
                char *p=filename+lstrlen(filename);
                int len = 0;
                while (*p != '\\' && p >= filename) { p--; len++; }
                lstrcpy(out, ++p); out += len;
                some_info = 1;
                break;
            }
            }
        }

        ID3Tag_Delete(tag);
    }

    if (!some_info)
    {
        char *p=filename+lstrlen(filename);
        while (*p != '\\' && p >= filename) p--;
        lstrcpy(title,++p);
    }
}
Example #9
0
int
main( int argc, char *argv[] )
{
  char *filename = NULL;
  ID3Tag *tag;
  
  if (argc != 2)
  {
    printf("*** Usage: %s file\n", argv[0]);
    exit (1);
  }
  filename = argv[1];
  printf("*** Reading %s\n", filename);
  
  if ((tag = ID3Tag_New()) != NULL)
  {
    ID3Frame *frame;

    (void) ID3Tag_Link(tag, filename);
    if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_TITLE)) != NULL)
    {
      ID3Field *field;
      if ((field = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL)
      {
        char title[1024];
        (void) ID3Field_GetASCII(field, title, 1024);
        printf("Title: %s\n", title);
      }
      else
      {
        printf("Didn't get the field\n");
      }
    }
    else
    {
      printf("Didn't get the frame\n");
    }

    if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_LEADARTIST)) != NULL)
    {
      ID3Field *field;
      if ((field = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL)
      {
        char artist[1024];
        (void) ID3Field_GetASCII(field, artist, 1024);
        printf("Artist: %s\n", artist);
      }
      else
      {
        printf("Didn't get the field\n");
      }
    }
    else
    {
      printf("Didn't get the frame\n");
    }

    if ((frame = ID3Tag_FindFrameWithID(tag, ID3FID_ALBUM)) != NULL)
    {
      ID3Field *field;
      if ((field = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL)
      {
        char album[1024];
        (void) ID3Field_GetASCII(field, album, 1024);
        printf("Album: %s\n", album);
      }
      else
      {
        printf("Didn't get the field\n");
      }
    }
    else
    {
      printf("Didn't get the frame\n");
    }
  }
  else
  {
    printf("Didn't get the tag\n");
  }
  exit (0);
}
Example #10
0
int
libapetag_convertID3v2toAPE (const ID3Frame * frame,
                 char **item_, size_t * item_len,
                 char **value_, size_t * value_len,
                 unsigned long *flags)
{
    ID3Field *text;
    ID3Field *desc;
    ID3Field *url;
//      ID3Field *bin;  // will be implemented some day

    char *item = NULL;
    char *value = NULL;
    
    ID3_FrameID frameid = ID3Frame_GetID (frame);
    unsigned int i;
    
    *flags = ITEM_TEXT;
    
    for (i = 0; i < sizeof (convert) / sizeof (struct id3vtwo2ape); i++)
        if (frameid == convert[i].frame)
            break;


    if (convert[i].field_type == ID3FN_TEXT) {
        switch (convert[i].special) {
        case APETAG_TYPE_COMMENT: /* Comments and unsynced lyrics */
            if ((text = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL) {
                ALOCATE(text, value, *value_len);
                ID3Field_GetASCII(text, value, *value_len);
            }
            ALOCATE_ITEM(item, convert[i].APEName, *item_len);
            strncpy(item, convert[i].APEName, *item_len);
            item[*item_len]='\0';
            //break;
            if ((text = ID3Frame_GetField (frame, ID3FN_DESCRIPTION)) != NULL) {
                char *value_ds=NULL;
                int value_len2;
                if (ID3Field_Size(text) != 0) {
                    ALOCATE(text, value_ds, value_len2);
                    ID3Field_GetASCII(text, value_ds, value_len2);
                    if ( strcmp(value_ds, STR_V1_COMMENT_DESC) == 0 ) {
                        value_len2 = 0;
                        value[0]='\0';
                    } else {
                        item = (char *) realloc( item, (*item_len) + value_len2 + 3);
                        item[(*item_len)++]='-'; item[(*item_len)]='\0';
                        strncpy(item + (*item_len),value_ds ,(value_len2 + 1));
                        (*item_len)+=value_len2;
                    }
                    free(value_ds);
                }
            }
            break;
            
        case APETAG_TYPE_USER:  /* User texts */
            if ((text = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL) {
                ALOCATE(text, value, *value_len);
                ID3Field_GetASCII(text, value, *value_len);
            }
            if ((desc = ID3Frame_GetField(frame, ID3FN_DESCRIPTION)) != NULL) {
                ALOCATE(desc, item, *item_len);
                ID3Field_GetASCII(desc, item, *item_len);
            }
            break;
            
        case APETAG_TYPE_GENRE: /* genre */ 
            if ((text = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL) {
                char *p;
                int j;
                ALOCATE(text, value, *value_len);
                ID3Field_GetASCII(text, value, *value_len);
                ALOCATE_ITEM(item, convert[i].APEName, *item_len);
                strncpy(item, convert[i].APEName, *item_len);
                value[*value_len]='\0';
                p = value;
                if (*p == '(') {
                    p++;
                    while (*p && (*p >= '0' && *p <= '9'))
                        p++;
                    if (*p && *p == ')') {
                        p++;
                    } else {
                        p = value;
                    }
                    *value_len -= (p-value); // corect lenght of frame
                    if (*p != '\0') { // copy in place
                        for (j = 0; *p != '\0'; j++) {
                            value[j] = *p;
                            p++;
                        }
                        value[j] = '\0';
                    }
                }
            }
            break;
            
        default:    /* normal text tags */
            if ((text = ID3Frame_GetField(frame, ID3FN_TEXT)) != NULL) {
                ALOCATE(text, value, *value_len);
                ID3Field_GetASCII(text, value, *value_len);
                ALOCATE_ITEM(item, convert[i].APEName, *item_len);
                strncpy(item, convert[i].APEName, *item_len);
            }
            break;
            
        } /* <- switch( convert[i].special ) */
        
        item[*item_len]='\0';
        value[*value_len]='\0';
    } else 
    if (convert[i].field_type == ID3FN_URL) {
        *flags = ITEM_URL;
        /* TODO: set ape_tag_URL in flag */
        /* user url */
        if (convert[i].special == APETAG_TYPE_USER) {
            if ((url = ID3Frame_GetField(frame, ID3FN_URL)) != NULL) {
                ALOCATE(url, value, *value_len);
                ID3Field_GetASCII(url, value, *value_len);
            }
            if ((desc = ID3Frame_GetField(frame, ID3FN_DESCRIPTION)) != NULL) {
                ALOCATE(desc, item, *item_len);
                ID3Field_GetASCII(desc, item, *item_len);
            }
            /* normal url */
        } else {
            if ((url = ID3Frame_GetField (frame, ID3FN_URL)) != NULL) {
                ALOCATE(url, value, *value_len);
                ID3Field_GetASCII(url, value, *value_len);
                ALOCATE_ITEM(item, convert[i].APEName, *item_len);
                strncpy(item, convert[i].APEName, *item_len);
            }
        }
        
        item[*item_len]='\0';
        value[*value_len]='\0';
    } else {        //convert[i].field_type
        item = NULL;
        value = NULL;
        PRINT_D (">id3v2_read>other\n");
    }
    *item_ = item;
    *value_ = value;
    
    if (!(value==NULL || (*value_len)==0) && value[(*value_len)-1]=='\0')
        (*value_len)--;

    return 0;
}