summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2014-04-13 05:01:55 -0700
committerwm4 <wm4@nowhere>2014-04-13 18:03:01 +0200
commitbc79ded75a63ae79a1119f5ca578d41fca04b283 (patch)
treec6d04bd0d0b090373f154b351fb7fabfd9ab529f /common
parent47972a0077892636fb922a3600d66779636b7ee7 (diff)
downloadmpv-bc79ded75a63ae79a1119f5ca578d41fca04b283.tar.bz2
mpv-bc79ded75a63ae79a1119f5ca578d41fca04b283.tar.xz
mp_tags: move generic mp_tags stuff into its own .c/.h files in common/
rename add_metadata to the more genera/descriptive mp_tags_copy_items_from_av_dictionary Signed-off-by: wm4 <wm4@nowhere>
Diffstat (limited to 'common')
-rw-r--r--common/tags.c70
-rw-r--r--common/tags.h21
2 files changed, 91 insertions, 0 deletions
diff --git a/common/tags.c b/common/tags.c
new file mode 100644
index 0000000000..f709cf0d5a
--- /dev/null
+++ b/common/tags.c
@@ -0,0 +1,70 @@
+/*
+ * This file is part of mpv.
+ *
+ * mpv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * mpv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with mpv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libavutil/dict.h>
+#include "tags.h"
+#include "bstr/bstr.h"
+
+void mp_tags_set_str(struct mp_tags *tags, const char *key, const char *value)
+{
+ mp_tags_set_bstr(tags, bstr0(key), bstr0(value));
+}
+
+void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value)
+{
+ for (int n = 0; n < tags->num_keys; n++) {
+ if (bstrcasecmp0(key, tags->keys[n]) == 0) {
+ talloc_free(tags->values[n]);
+ tags->values[n] = talloc_strndup(tags, value.start, value.len);
+ return;
+ }
+ }
+
+ MP_RESIZE_ARRAY(tags, tags->keys, tags->num_keys + 1);
+ MP_RESIZE_ARRAY(tags, tags->values, tags->num_keys + 1);
+ tags->keys[tags->num_keys] = talloc_strndup(tags, key.start, key.len);
+ tags->values[tags->num_keys] = talloc_strndup(tags, value.start, value.len);
+ tags->num_keys++;
+}
+
+char *mp_tags_get_str(struct mp_tags *tags, const char *key)
+{
+ return mp_tags_get_bstr(tags, bstr0(key));
+}
+
+char *mp_tags_get_bstr(struct mp_tags *tags, bstr key)
+{
+ for (int n = 0; n < tags->num_keys; n++) {
+ if (bstrcasecmp0(key, tags->keys[n]) == 0)
+ return tags->values[n];
+ }
+ return NULL;
+}
+
+void mp_tags_clear(struct mp_tags *tags)
+{
+ *tags = (struct mp_tags){0};
+ talloc_free_children(tags);
+}
+
+void mp_tags_copy_from_av_dictionary(struct mp_tags *tags,
+ struct AVDictionary *av_dict)
+{
+ AVDictionaryEntry *entry = NULL;
+ while ((entry = av_dict_get(av_dict, "", entry, AV_DICT_IGNORE_SUFFIX)))
+ mp_tags_set_str(tags, entry->key, entry->value);
+}
diff --git a/common/tags.h b/common/tags.h
new file mode 100644
index 0000000000..3bc0e6984b
--- /dev/null
+++ b/common/tags.h
@@ -0,0 +1,21 @@
+#ifndef MP_TAGS_H
+#define MP_TAGS_H
+
+#include "bstr/bstr.h"
+
+struct mp_tags {
+ char **keys;
+ char **values;
+ int num_keys;
+};
+
+void mp_tags_set_str(struct mp_tags *tags, const char *key, const char *value);
+void mp_tags_set_bstr(struct mp_tags *tags, bstr key, bstr value);
+char *mp_tags_get_str(struct mp_tags *tags, const char *key);
+char *mp_tags_get_bstr(struct mp_tags *tags, bstr key);
+void mp_tags_clear(struct mp_tags *tags);
+struct AVDictionary;
+void mp_tags_copy_from_av_dictionary(struct mp_tags *tags,
+ struct AVDictionary *av_dict);
+
+#endif