Beispiel #1
0
void LibMadWrapper::buildMetadata() noexcept
{
    // TODO we have to find ID3 tag in the mpeg file, but this should be done while trying decoding mpeg-frame-headers
    // whenever libmad returns lost_sync error, there might be a id3 tag

    struct id3_file *s = id3_file_open(this->Filename.c_str(), ID3_FILE_MODE_READONLY);

    if (s == nullptr)
    {
        return;
    }

    struct id3_tag *t = id3_file_tag(s);
    if (t == nullptr)
    {
        id3_file_close(s);
        return;
    }

    this->Metadata.Title = id3_get_tag(t, ID3_FRAME_TITLE);
    this->Metadata.Artist = id3_get_tag(t, ID3_FRAME_ARTIST);
    this->Metadata.Album = id3_get_tag(t, ID3_FRAME_ALBUM);
    this->Metadata.Year = id3_get_tag(t, ID3_FRAME_YEAR);
    this->Metadata.Genre = id3_get_tag(t, ID3_FRAME_GENRE);
    this->Metadata.Track = id3_get_tag(t, ID3_FRAME_TRACK);
    this->Metadata.Comment = id3_get_tag(t, ID3_FRAME_COMMENT);

    id3_file_close(s);
}
Beispiel #2
0
static int parse_id3( char *names[], const struct id3_tag *tag)
{
	int found, i;

	found = 0;
	/* Get ID3 tag if available, 30 chars except 4 for year */
	for(i=0; i<=5; i++)
	{
		names[i] = NULL;
		names[i] = id3_get_tag(tag, info_id3[i].id, (i==3) ? 4 : 30);
		if( names[i] != NULL && names[i][0] != '\0' )
			found = 1;
	}

	return (found);
}
Beispiel #3
0
/*
    Only shows ID3 tags if at least one of
    TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE
    is present.
*/
static int show_id3(struct id3_tag const *tag)
{
    unsigned int i;
    int print = 0;
    char emptystring[31];
    char *names[6];
    struct {
        int index;
        char const *id;
        char const *name;
    } const info[] = {
        { 0,    ID3_FRAME_TITLE,  "Title  : "   },
        { 1,    ID3_FRAME_ARTIST, "  Artist: "  },
        { 2,    ID3_FRAME_ALBUM,  "Album  : "   },
        { 3,    ID3_FRAME_YEAR,   "  Year  : "  },
        { 4,    ID3_FRAME_COMMENT,"Comment: "   },
        { 5,    ID3_FRAME_GENRE,  "  Genre : "  }
    };

    memset (emptystring, ' ', 30);
    emptystring[30] = '\0';
    /*  Get ID3 tag if available, 30 chars except 4 for year  */
    for (i=0; i<=5; i++)    {
        names[i] = NULL;
        names[i] = id3_get_tag(tag, info[i].id, (i==3) ? 4 : 30);
    }
    for (i=0; i<=5; i++)    {
        if (names[i])   {
            print = 1;
            break;
        }
    }
    if (!print) {
        return 0;
    }

    if (options.opt & MPG321_REMOTE_PLAY)
    {
        printf("@I ID3:");

        for (i=0; i<=5; i++)
        {
            if(!names[i])
            {
                printf(emptystring);
            }
            
            else
            {
                printf("%s", names[i]);
                free(names[i]);
            }
        }
        printf("\n");
    }
    
    else
    {
        /* Emulate mpg123 original behaviour  */
        for (i=0; i<=5; i++)    {
            fprintf (stderr, "%s", info[i].name);
            if (!names[i])  {
                fprintf (stderr, emptystring);
            }   else    {
                fprintf (stderr, "%s", names[i]);
                free (names[i]);
            }
            if (i%2) fprintf (stderr, "\n");
        }
    }

    return 1;
}