[FFmpeg-devel] [PATCH 2/4] id3v2: merge TYER/TDAT/TIME to date tag

Reimar Döffinger Reimar.Doeffinger
Mon Nov 1 07:54:00 CET 2010


On Sun, Oct 31, 2010 at 10:38:11PM +0100, Anton Khirnov wrote:
> On Sun, Oct 31, 2010 at 06:39:58PM +0100, Reimar D?ffinger wrote:
> > > +    for (i = 0; i < sizeof(keys); i++) {
> > > +        AVMetadataTag *t = av_metadata_get(*m, keys[i], NULL, AV_METADATA_MATCH_CASE);
> > > +        if (!t || strlen(t->value) != 4 || !is_number(t->value))
> > > +            break;
> > > +        tags[i] = t;
> > > +    }
> > > +
> > > +    if      (tags[2]) len = sizeof("YYYY-MM-DD HH:MM");
> > > +    else if (tags[1]) len = sizeof("YYYY-MM-DD");
> > > +    else if (tags[0]) len = sizeof("YYYY");
> > > +    else return;
> > > +
> > > +    if (!(date = av_malloc(len)))
> > > +        return;
> > > +    snprintf(date, len, "%.4s-%.2s-%.2s %.2s:%.2s",
> > > +             tags[0] ? tags[0]->value     : "",         // year
> > > +             tags[1] ? tags[1]->value + 2 : "",         // month
> > > +             tags[1] ? tags[1]->value     : "",         // day
> > > +             tags[2] ? tags[2]->value     : "",         // hour
> > > +             tags[2] ? tags[2]->value + 2 : "");        // minute
> > 
> > I suspect this could profit hugely from some restructuring, but at the very
> > least I'd suggest adding some variables and doing
> > year = tags[0] ? tags[0]->value : "";
> > ....
> > 
> i fail to see what that would accomplish other than making it longer

Making it a lot easier to understand what it does?
In particular, get rid of the comments that are likely to be wrong
after the next code change anyway?
It might also be possible to combine them with the if (tags[...])
checks that are already there anyway.



More information about the ffmpeg-devel mailing list