summaryrefslogtreecommitdiff
path: root/src/core/mp-file-tag-info.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/mp-file-tag-info.c')
-rwxr-xr-xsrc/core/mp-file-tag-info.c250
1 files changed, 250 insertions, 0 deletions
diff --git a/src/core/mp-file-tag-info.c b/src/core/mp-file-tag-info.c
new file mode 100755
index 0000000..af91c70
--- /dev/null
+++ b/src/core/mp-file-tag-info.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2012 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.tizenopensource.org/license
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <glib.h>
+#include <mm_file.h>
+#include <mm_error.h>
+#include "mp-file-tag-info.h"
+#include "mp-player-debug.h"
+#include "mp-define.h"
+
+/* tag_info which must be freed with mp_file_tag_free() after use. */
+int
+mp_file_tag_info_get_all_tag(const char *filename, mp_tag_info_t * tag_info)
+{
+ MMHandleType tag_attrs = 0;
+ MMHandleType content_attrs = 0;
+ int ret = 0;
+
+ if (!filename || !tag_info)
+ {
+ goto CATCH_ERROR;
+ }
+
+ memset(tag_info, 0x00, sizeof(mp_tag_info_t));
+
+ ret = mm_file_create_content_attrs(&content_attrs, filename);
+ if (ret == MM_ERROR_NONE)
+ {
+ char *error = NULL;
+ int dur = 0;
+ int audio_codec = 0;
+ int audio_samplerate = 0;
+ int audio_bitrate = 0;
+ int audio_channel = 0;
+
+ ret = mm_file_get_attrs(content_attrs,
+ &error,
+ MM_FILE_CONTENT_DURATION, &dur,
+ MM_FILE_CONTENT_AUDIO_CODEC, &audio_codec,
+ MM_FILE_CONTENT_AUDIO_SAMPLERATE, &audio_samplerate,
+ MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate,
+ MM_FILE_CONTENT_AUDIO_CHANNELS, &audio_channel, NULL);
+
+ if (ret != MM_ERROR_NONE)
+ {
+ if (error)
+ {
+ ERROR_TRACE("fail to mm_file_get_attrs() - ret(%x), error(%s)", ret, error);
+ free(error);
+ }
+ else
+ {
+ ERROR_TRACE("fail to mm_file_get_attrs() - ret(%x)", ret);
+ }
+ goto CATCH_ERROR;
+ }
+ tag_info->duration = dur;
+ tag_info->audio_codec = audio_codec;
+ tag_info->audio_samplerate = audio_samplerate;
+ tag_info->audio_bitrate = audio_bitrate;
+ tag_info->audio_channel = audio_channel;
+ }
+ else
+ {
+ ERROR_TRACE("fail to mm_file_create_content_attrs() - ret(%x)", ret);
+ goto CATCH_ERROR;
+ }
+
+
+ ret = mm_file_create_tag_attrs(&tag_attrs, filename);
+ if (ret == MM_ERROR_NONE)
+ {
+ char *error = NULL;
+ char *album = NULL;
+ int album_len = 0;
+ char *artist = NULL;
+ int artist_len = 0;
+ char *title = NULL;
+ int title_len = 0;
+ void *albumart = NULL;
+ int albumart_len = 0;
+ int albumart_size = 0;
+ char *genre = NULL;
+ int genre_len = 0;
+ char *copyright = NULL;
+ int copyright_len = 0;
+ char *date = NULL;
+ int date_len = 0;
+ char *desc = NULL;
+ int desc_len = 0;
+ char *author = NULL;
+ int author_len = 0;
+ char *track = NULL;
+ int track_len = 0;
+ char *rating = NULL;
+ int rating_len = 0;
+
+ ret = mm_file_get_attrs(tag_attrs,
+ &error,
+ MM_FILE_TAG_ARTIST, &artist, &artist_len,
+ MM_FILE_TAG_ALBUM, &album, &album_len,
+ MM_FILE_TAG_TITLE, &title, &title_len,
+ MM_FILE_TAG_GENRE, &genre, &genre_len,
+ MM_FILE_TAG_AUTHOR, &author, &author_len,
+ MM_FILE_TAG_COPYRIGHT, &copyright, &copyright_len,
+ MM_FILE_TAG_DATE, &date, &date_len,
+ MM_FILE_TAG_DESCRIPTION, &desc, &desc_len,
+ MM_FILE_TAG_ARTWORK, &albumart, &albumart_len,
+ MM_FILE_TAG_ARTWORK_SIZE, &albumart_size,
+ MM_FILE_TAG_TRACK_NUM, &track, &track_len,
+ MM_FILE_TAG_RATING, &rating, &rating_len, NULL);
+
+ if (ret != MM_ERROR_NONE)
+ {
+ if (error)
+ {
+ ERROR_TRACE("fail to mm_file_get_attrs() - ret(%x), error(%s)", ret, error);
+ free(error);
+ }
+ else
+ {
+ ERROR_TRACE("fail to mm_file_get_attrs() - ret(%x)", ret);
+ }
+ goto CATCH_ERROR;
+ }
+
+ if (albumart)
+ {
+ gchar *path = NULL;
+ int fd = g_file_open_tmp(NULL, &path, NULL);
+
+ if (fd != -1)
+ {
+ FILE *fp = fdopen(fd, "w");
+ if (fp == NULL)
+ {
+ ERROR_TRACE("fail to fdopen()");
+ close(fd);
+ }
+ else
+ {
+ int n = fwrite((unsigned char *)albumart, 1, albumart_size, fp);
+ if (n != albumart_size)
+ {
+ ERROR_TRACE("fail to fwrite()");
+ fclose(fp);
+ close(fd);
+ }
+ else
+ {
+ fflush(fp);
+ fclose(fp);
+ close(fd);
+ }
+ }
+ }
+ tag_info->albumart_path = path;
+ }
+
+ if (album)
+ tag_info->album = strdup(album);
+ if (artist)
+ tag_info->artist = strdup(artist);
+ if (title)
+ tag_info->title = strdup(title);
+ if (genre)
+ tag_info->genre = strdup(genre);
+ if (copyright)
+ tag_info->copyright = strdup(copyright);
+ if (date)
+ tag_info->date = strdup(date);
+ if (desc)
+ tag_info->desc = strdup(desc);
+ if (author)
+ tag_info->author = strdup(author);
+ if (track)
+ tag_info->track = strdup(track);
+ if (rating)
+ tag_info->rating = strdup(rating);
+
+ }
+ else
+ {
+ ERROR_TRACE("fail to mm_file_create_tag_attrs() - ret(%x)", ret);
+ goto CATCH_ERROR;
+ }
+
+ DEBUG_TRACE
+ ("file : %s\n duration: %d \n album: %s\n artist: %s\n title: %s\n genre: %s\n copyright:%s\n date: %s\n desc : %s\n author: %s\n albumart : %s",
+ filename, tag_info->duration, tag_info->album, tag_info->artist, tag_info->title, tag_info->genre,
+ tag_info->copyright, tag_info->date, tag_info->desc, tag_info->author, tag_info->albumart_path);
+
+ if (content_attrs)
+ mm_file_destroy_content_attrs(content_attrs);
+
+ if (tag_attrs)
+ mm_file_destroy_content_attrs(tag_attrs);
+
+ return 0;
+
+ CATCH_ERROR:
+ if (content_attrs)
+ mm_file_destroy_content_attrs(content_attrs);
+
+ if (tag_attrs)
+ mm_file_destroy_content_attrs(tag_attrs);
+
+ return -1;
+}
+
+
+void
+mp_file_tag_free(mp_tag_info_t * tag_info)
+{
+ if (tag_info == NULL)
+ return;
+
+ IF_FREE(tag_info->album);
+ IF_FREE(tag_info->genre);
+ IF_FREE(tag_info->author);
+ IF_FREE(tag_info->artist);
+ IF_FREE(tag_info->title);
+ IF_FREE(tag_info->copyright);
+ IF_FREE(tag_info->date);
+ IF_FREE(tag_info->desc);
+ IF_FREE(tag_info->albumart_path);
+ IF_FREE(tag_info->track);
+ IF_FREE(tag_info->rating);
+ return;
+}