[FFmpeg-devel] [PATCH 2/4] id3v2: merge TYER/TDAT/TIME to date tag
Anton Khirnov
anton
Fri Oct 15 21:20:59 CEST 2010
---
libavformat/id3v2.c | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index fbcb8f8..d66509f 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -162,6 +162,42 @@ static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const c
av_metadata_set2(&s->metadata, key, val, 0);
}
+static int is_number(const char *p)
+{
+ while (*p)
+ if (!isdigit(*p++))
+ return 0;
+ return 1;
+}
+
+static void merge_date(AVMetadata **m)
+{
+ AVMetadataTag *t;
+ char date[17] = {0}; // YYYY-MM-DD hh:mm
+
+ if (!(t = av_metadata_get(*m, "TYER", NULL, AV_METADATA_MATCH_CASE)) ||
+ strlen(t->value) != 4 || !is_number(t->value))
+ return;
+ snprintf(date, sizeof(date), "%04d", atoi(t->value));
+ av_metadata_set2(m, "TYER", NULL, 0);
+
+ if (!(t = av_metadata_get(*m, "TDAT", NULL, AV_METADATA_MATCH_CASE)) ||
+ strlen(t->value) != 4 || !is_number(t->value))
+ goto finish;
+ snprintf(date + 4, sizeof(date) - 4, "-%.2s-%.2s", t->value + 2, t->value);
+ av_metadata_set2(m, "TDAT", NULL, 0);
+
+ if (!(t = av_metadata_get(*m, "TIME", NULL, AV_METADATA_MATCH_CASE)) ||
+ strlen(t->value) != 4 || !is_number(t->value))
+ goto finish;
+ snprintf(date + 10, sizeof(date) - 10, " %.2s:%.2s", t->value, t->value + 2);
+ av_metadata_set2(m, "TIME", NULL, 0);
+
+finish:
+ if (date[0])
+ av_metadata_set2(m, "date", date, 0);
+}
+
void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
{
int isv34, tlen, unsync;
@@ -251,6 +287,7 @@ void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags)
url_fseek(s->pb, next, SEEK_SET);
}
metadata_conv(&s->metadata, NULL, ff_id3v2_metadata_conv);
+ merge_date(&s->metadata);
if (len > 0) {
/* Skip padding */
--
1.7.1
More information about the ffmpeg-devel
mailing list