Exemplo n.º 1
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);
    }
}
Exemplo n.º 2
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;
}