Correct the type
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
index 86c9473..a4bed31 100644 (file)
@@ -3,8 +3,6 @@
  *
  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 
 #include <unistd.h>
 #include <stdlib.h>
-#ifndef __USE_XOPEN
-#define DEF_XOPEN
-#define __USE_XOPEN /* needed for strptime */
-#endif
-#include <time.h>
-#ifdef DEF_XOPEN
-#undef __USE_XOPEN
-#endif
 #include <string.h>
-#include <system_info.h>
-#include <sys/vfs.h>
-#include <glib/gstdio.h>
+#include <fcntl.h>
 #include <sys/stat.h>
-#include <dirent.h>
+#include <sys/vfs.h>
 #include <ctype.h>
 #include <aul/aul.h>
 #include <mm_file.h>
 #include <libexif/exif-data.h>
-#include <media-util.h>
 #include <uuid/uuid.h>
-#include <mm_util_magick.h>
-#include "media-util-err.h"
+#include <media-thumbnail.h>
+#include <media-util-user.h>
 #include "media-svc-util.h"
 #include "media-svc-db-utils.h"
 #include "media-svc-debug.h"
 #include "media-svc-env.h"
-#include "media-svc-hash.h"
 #include "media-svc-album.h"
-#include "media-svc-localize_ch.h"
-
-#define MEDIA_SVC_FILE_EXT_LEN_MAX                             6                       /**< Maximum file ext lenth*/
-
-/* Define data structures for media type and mime type */
-#define MEDIA_SVC_CATEGORY_UNKNOWN     0x00000000      /**< Default */
-#define MEDIA_SVC_CATEGORY_ETC         0x00000001      /**< ETC category */
-#define MEDIA_SVC_CATEGORY_IMAGE       0x00000002      /**< Image category */
-#define MEDIA_SVC_CATEGORY_VIDEO       0x00000004      /**< Video category */
-#define MEDIA_SVC_CATEGORY_MUSIC       0x00000008      /**< Music category */
-#define MEDIA_SVC_CATEGORY_SOUND       0x00000010      /**< Sound category */
-#define MEDIA_SVC_CATEGORY_PVR 0x00000020      /**< PVR category */
-#define MEDIA_SVC_CATEGORY_UHD 0x00000040      /**< UHD category */
-#define MEDIA_SVC_CATEGORY_SCSA        0x00000080      /**< SCSA category */
-
-#define CONTENT_TYPE_NUM 5
+/*For ebook metadata */
+#include <zip.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/HTMLparser.h>
+#include <dlfcn.h>
+
+#define MEDIA_SVC_FILE_EXT_LEN_MAX 6
+
 #define MUSIC_MIME_NUM 29
-#define SOUND_MIME_NUM 1
-#define MIME_TYPE_LENGTH 255
+#define SOUND_MIME_NUM 2
 #define MIME_LENGTH 50
-#define _3GP_FILE ".3gp"
-#define _MP4_FILE ".mp4"
-#define _ASF_FILE ".asf"
-#define MEDIA_SVC_ARTWORK_SIZE 2000
-#define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
-
-#define MEDIA_SVC_DEFAULT_GPS_VALUE                    -200                    /**< Default GPS Value*/
-
-static int media_svc_pinyin_support = -1;
-
-typedef struct {
-       char content_type[15];
-       int category_by_mime;
-} _media_svc_content_table_s;
-
-static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
-       {"audio", MEDIA_SVC_CATEGORY_SOUND},
-       {"image", MEDIA_SVC_CATEGORY_IMAGE},
-       {"video", MEDIA_SVC_CATEGORY_VIDEO},
-       {"application", MEDIA_SVC_CATEGORY_ETC},
-       {"text", MEDIA_SVC_CATEGORY_ETC},
+#define IMAGE_PREFIX "image/"
+#define AUDIO_PREFIX "audio/"
+#define VIDEO_PREFIX "video/"
+#define PREFIX_LEN 6
+
+#define MEDIA_SVC_PDF_TAG_TAIL_LEN 12
+#define MEDIA_SVC_PDF_BUF_SIZE 256
+
+#define MEDIA_SVC_THUMB_WIDTH 320
+#define MEDIA_SVC_THUMB_HEIGHT 240
+
+#define PATH_PLUGIN_LIB                                PATH_LIBDIR"/libmedia-ebook-plugin.so"
+
+enum Exif_Orientation {
+       NOT_AVAILABLE = 0,
+       NORMAL = 1,
+       HFLIP = 2,
+       ROT_180 = 3,
+       VFLIP = 4,
+       TRANSPOSE = 5,
+       ROT_90 = 6,
+       TRANSVERSE = 7,
+       ROT_270 = 8
 };
 
 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
@@ -99,7 +79,6 @@ static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
        "x-ms-wma",
        "x-flac",
        "mp4",
-       /* known mime types of drm files*/
        "mp3",
        "x-mp3", /*alias of audio/mpeg*/
        "x-mpeg", /*alias of audio/mpeg*/
@@ -118,7 +97,6 @@ static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
        "x-ape",
        "x-ms-asx",
        "vnd.rn-realaudio",
-
        "x-vorbis", /*alias of audio/x-vorbis+ogg*/
        "vorbis", /*alias of audio/x-vorbis+ogg*/
        "x-oggflac",
@@ -129,13 +107,14 @@ static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
 };
 
 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
-       "x-smaf",
+       "application/x-smaf",
+       "text/x-iMelody"
 };
 
-char *_media_info_generate_uuid(void)
+static char *__media_info_generate_uuid(void)
 {
        uuid_t uuid_value;
-       static char uuid_unparsed[37];
+       char uuid_unparsed[37];
 
 RETRY_GEN:
        uuid_generate(uuid_value);
@@ -146,318 +125,129 @@ RETRY_GEN:
                goto RETRY_GEN;
        }
 
-       return uuid_unparsed;
-}
-
-static int __media_svc_split_to_double(char *input, double *arr)
-{
-       char tmp_arr[255] = {0, };
-       int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
-
-       if (!STRING_VALID(input)) {
-               media_svc_error("Invalid parameter");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-       memset(tmp_arr, 0x0, sizeof(tmp_arr));
-
-       /*media_svc_debug("input: [%s]", input); */
-
-       len = strlen(input);
-
-       for (idx = 0; idx < (len + 1); idx++) {
-               if (input[idx] == ' ') {
-                       continue;
-               } else if ((input[idx] == ',') || (idx == len)) {
-                       arr[arr_idx] = atof(tmp_arr);
-                       arr_idx++;
-                       str_idx = 0;
-                       /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
-                       memset(tmp_arr, 0x0, sizeof(tmp_arr));
-               } else {
-                       tmp_arr[str_idx] = input[idx];
-                       str_idx++;
-               }
-       }
-
-       if (arr_idx != 3) {
-               media_svc_debug("Error when parsing GPS [%d]", arr_idx);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       return MS_MEDIA_ERR_NONE;
+       return g_strdup(uuid_unparsed);
 }
 
-static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
+static char * __media_svc_get_exif_datetaken(ExifData *ed)
 {
        ExifEntry *entry;
-       ExifTag tag;
-
-       if (ed == NULL)
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
+       char tmp[MEDIA_SVC_METADATA_LEN_MAX + 1] = { 0, };
 
-       tag = tagtype;
+       media_svc_retv_if(!ed, NULL);
 
-       entry = exif_data_get_entry(ed, tag);
+       entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME_ORIGINAL);
        if (entry) {
-               /* Get the contents of the tag in human-readable form */
-               if (tag == EXIF_TAG_ORIENTATION ||
-                       tag == EXIF_TAG_PIXEL_X_DIMENSION ||
-                       tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
-                       tag == EXIF_TAG_ISO_SPEED_RATINGS) {
-
-                       if (i_value == NULL) {
-                               media_svc_debug("i_value is NULL");
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-
-                       ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
-                       short exif_value = exif_get_short(entry->data, mByteOrder);
-                       *i_value = (int)exif_value;
-
-               } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
-
-                       if (d_value == NULL) {
-                               media_svc_debug("d_value is NULL");
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-
-                       /* Get the contents of the tag in human-readable form */
-                       char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
-                       exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
-                       gps_buf[strlen(gps_buf)] = '\0';
-                       int ret = MS_MEDIA_ERR_NONE;
-
-                       double tmp_arr[3] = { 0.0, 0.0, 0.0 };
-
-                       ret = __media_svc_split_to_double(gps_buf, tmp_arr);
-                       media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-                       *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
-               } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
-
-                       if (buf == NULL) {
-                               media_svc_debug("buf is NULL");
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-
-                       ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
-                       ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
-                       long numerator = mRational.numerator;
-                       long denominator = mRational.denominator;
-                       snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
-
-               } else if (tag == EXIF_TAG_FNUMBER) {
-
-                       if (d_value == NULL) {
-                               media_svc_debug("d_value is NULL");
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
-
-                       ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
-                       ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
-                       long numerator = mRational.numerator;
-                       long denominator = mRational.denominator;
-
-                       *d_value = ((numerator*1.0)/(denominator*1.0));
-
-               } else {
-
-                       if (buf == NULL) {
-                               media_svc_debug("buf is NULL");
-                               return MS_MEDIA_ERR_INVALID_PARAMETER;
-                       }
+               exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
+               if (strlen(tmp) > 0)
+                       return g_strdup(tmp);
+       }
 
-                       exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
-                       buf[strlen(buf)] = '\0';
-               }
+       entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME);
+       if (entry) {
+               exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
+               if (strlen(tmp) > 0)
+                       return g_strdup(tmp);
        }
 
-       return MS_MEDIA_ERR_NONE;
+       return NULL;
 }
 
-time_t __media_svc_get_timeline_from_str(const char *timstr)
+static bool __media_svc_get_exif_short(ExifData *ed, ExifTag tagtype, unsigned short *value)
 {
-       struct tm t;
-       time_t modified_t = 0;
-       time_t rawtime;
-       struct tm timeinfo;
-
-       if (!STRING_VALID(timstr)) {
-               media_svc_error("Invalid Parameter");
-               return 0;
-       }
+       ExifEntry *entry;
 
-       /*Exif Format : %Y:%m:%d %H:%M:%S
-       Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
-       memset(&t, 0x00, sizeof(struct tm));
-
-       tzset();
-       time(&rawtime);
-       localtime_r(&rawtime, &timeinfo);
-
-       if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
-               t.tm_isdst = timeinfo.tm_isdst;
-               if (t.tm_isdst != 0)
-                       media_svc_debug("DST %d", t.tm_isdst);
-
-               /* If time string has timezone */
-               if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
-                       GTimeVal timeval;
-                       char tim_tmp_str[255] = { 0, };
-
-                       /* ISO8601 Time string format */
-                       strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
-                       g_time_val_from_iso8601(tim_tmp_str, &timeval);
-                       modified_t = timeval.tv_sec;
-                       media_svc_debug("Calibrated timeval : [%lu][%s]", modified_t, tim_tmp_str);
-               } else {
-                       /* Just localtime */
-                       modified_t = mktime(&t);
-               }
+       media_svc_retv_if(!ed, false);
+       media_svc_retvm_if(!value, false, "value is NULL");
 
-               if (modified_t > 0)
-                       return modified_t;
-               else
-                       media_svc_debug("Failed to get timeline : [%s] [%d:%d:%d: %d:%d:%d]", timstr, t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
-       } else {
-               media_svc_error("Failed to get timeline : [%s]", timstr);
-       }
+       entry = exif_data_get_entry(ed, tagtype);
+       media_svc_retv_if(!entry, false);
+       *value = exif_get_short(entry->data, exif_data_get_byte_order(ed));
 
-       return 0;
+       return true;
 }
 
-static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
+static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
 {
        int idx = 0;
+       int audio = 0;
+       int video = 0;
 
-       media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
-       media_svc_retvm_if(mimetype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mimetype is null");
-       media_svc_retvm_if(category == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "category is null");
-
-       *category = MEDIA_SVC_CATEGORY_UNKNOWN;
+       media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
+       media_svc_retvm_if(!mime_type, MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is null");
+       media_svc_retvm_if(!media_type, MS_MEDIA_ERR_INVALID_PARAMETER, "media_type is null");
 
-       /*categorize from mimetype */
-       for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
-               if (strncmp(mimetype, content_category[idx].content_type, strlen(content_category[idx].content_type)) == 0) {
-                       *category = (*category | content_category[idx].category_by_mime);
-                       break;
-               }
+       /* Image */
+       if (strncmp(mime_type, IMAGE_PREFIX, PREFIX_LEN) == 0) {
+               *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
+               return MS_MEDIA_ERR_NONE;
        }
 
-       /*in application type, exitst sound file ex) x-smafs, asf */
-       if (*category & MEDIA_SVC_CATEGORY_ETC) {
-               int prefix_len = strlen(content_category[3].content_type) + 1;
-               char *ext = NULL;
+       /* Audio */
+       if (strncmp(mime_type, AUDIO_PREFIX, PREFIX_LEN) == 0) {
+               *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
 
-               for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
-                       if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
-                               *category ^= MEDIA_SVC_CATEGORY_ETC;
-                               *category |= MEDIA_SVC_CATEGORY_SOUND;
+               for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
+                       if (strcmp(mime_type + PREFIX_LEN, music_mime_table[idx]) == 0) {
+                               *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
                                break;
                        }
                }
 
-               if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
-                       *category ^= MEDIA_SVC_CATEGORY_ETC;
-                       *category |= MEDIA_SVC_CATEGORY_SOUND;
-               }
+               /* audio/x-mpegurl : .m3u file (playlist file) */
+               if (strcmp(mime_type + PREFIX_LEN, "x-mpegurl") == 0)
+                       *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
 
-               /*"asf" must check video stream and then categorize in directly. */
-               ext = strrchr(path, '.');
-               if (ext != NULL) {
-                       if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
-                               int audio = 0;
-                               int video = 0;
-                               int err = 0;
-
-                               err = mm_file_get_stream_info(path, &audio, &video);
-                               if (err == 0) {
-                                       if (audio > 0 && video == 0) {
-                                               *category ^= MEDIA_SVC_CATEGORY_ETC;
-                                               *category |= MEDIA_SVC_CATEGORY_MUSIC;
-                                       } else {
-                                               *category ^= MEDIA_SVC_CATEGORY_ETC;
-                                               *category |= MEDIA_SVC_CATEGORY_VIDEO;
-                                       }
-                               }
-                       }
-               }
+               return MS_MEDIA_ERR_NONE;
        }
 
-       /*check music file in sound files. */
-       if (*category & MEDIA_SVC_CATEGORY_SOUND) {
-               int prefix_len = strlen(content_category[0].content_type) + 1;
-
-               for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
-                       if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
-                               *category ^= MEDIA_SVC_CATEGORY_SOUND;
-                               *category |= MEDIA_SVC_CATEGORY_MUSIC;
-                               break;
-                       }
-               }
+       /* Video */
+       if (strncmp(mime_type, VIDEO_PREFIX, PREFIX_LEN) == 0) {
+               *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
 
-               /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
-               if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
-                       *category ^= MEDIA_SVC_CATEGORY_SOUND;
-                       *category |= MEDIA_SVC_CATEGORY_ETC;
-               }
-       } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
                /*some video files don't have video stream. in this case it is categorize as music. */
-               char *ext = NULL;
-               /*"3gp" and "mp4" must check video stream and then categorize in directly. */
-               ext = strrchr(path, '.');
-               if (ext != NULL) {
-                       if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
-                               int audio = 0;
-                               int video = 0;
-                               int err = 0;
-
-                               err = mm_file_get_stream_info(path, &audio, &video);
-                               if (err == 0) {
-                                       if (audio > 0 && video == 0) {
-                                               *category ^= MEDIA_SVC_CATEGORY_VIDEO;
-                                               *category |= MEDIA_SVC_CATEGORY_MUSIC;
-                                       }
-                               }
-                               /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
+               if (strcmp(mime_type + PREFIX_LEN, "3gpp") == 0 ||
+                       strcmp(mime_type + PREFIX_LEN, "mp4") == 0) {
+                       if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
+                               if (audio > 0 && video == 0)
+                                       *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
                        }
                }
-       }
 
-       return MS_MEDIA_ERR_NONE;
-}
+               return MS_MEDIA_ERR_NONE;
+       }
 
-static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       int category = 0;
+       /* ETC */
+       *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
 
-       media_svc_media_type_e type;
+       for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
+               if (strcmp(mime_type, sound_mime_table[idx]) == 0) {
+                       *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+                       return MS_MEDIA_ERR_NONE;
+               }
+       }
 
-       ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
-       if (ret != MS_MEDIA_ERR_NONE)
-               media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
+       /*"asf" must check video stream and then categorize in directly. */
+       if (strcmp(mime_type, "application/vnd.ms-asf") == 0) {
+               if (mm_file_get_stream_info(path, &audio, &video) == FILEINFO_ERROR_NONE) {
+                       if (audio > 0 && video == 0)
+                               *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+                       else
+                               *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+               }
 
-       if (category & MEDIA_SVC_CATEGORY_SOUND)                type = MEDIA_SVC_MEDIA_TYPE_SOUND;
-       else if (category & MEDIA_SVC_CATEGORY_MUSIC)   type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
-       else if (category & MEDIA_SVC_CATEGORY_IMAGE)   type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
-       else if (category & MEDIA_SVC_CATEGORY_VIDEO)   type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
-       else    type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+               return MS_MEDIA_ERR_NONE;
+       }
 
-       *media_type = type;
+       if (strcmp(mime_type, "application/epub+zip") == 0 || strcmp(mime_type, "application/pdf") == 0)
+               *media_type = MEDIA_SVC_MEDIA_TYPE_BOOK;
 
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
-/*
-drm_contentifo is not NULL, if the file is OMA DRM.
-If the file is not OMA DRM, drm_contentinfo must be NULL.
-*/
 static int __media_svc_get_mime_type(const char *path, char *mimetype)
 {
        media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
 
-       /*in case of normal files or failure to get mime in drm */
        if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
                media_svc_error("aul_get_mime_from_file fail");
                return MS_MEDIA_ERR_INTERNAL;
@@ -472,7 +262,7 @@ static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
 
        for (i = strlen(file_path); i >= 0; i--) {
                if (file_path[i] == '.') {
-                       SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
+                       g_strlcpy(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
                        return true;
                }
 
@@ -482,156 +272,50 @@ static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
        return false;
 }
 
-static int __media_svc_resize_artwork(const char *path, const char *img_format)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       unsigned int width = 0;
-       unsigned int height = 0;
-       unsigned int resized_width = 0;
-       unsigned int resized_height = 0;
-       mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
-
-       if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
-               media_svc_debug("type [jpeg]");
-
-               mm_util_extract_image_info(path, &img_type, &width, &height);
-
-               if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
-                       media_svc_debug("No need resizing");
-                       return MS_MEDIA_ERR_NONE;
-               }
-
-               /* resizing */
-               if (width > height) {
-                       resized_height = MEDIA_SVC_ARTWORK_SIZE;
-                       resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
-               } else {
-                       resized_width = MEDIA_SVC_ARTWORK_SIZE;
-                       resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
-               }
-
-               ret = mm_util_resize_P_P(path, resized_width, resized_height, path);
-
-       } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
-               media_svc_debug("type [png]");
-       } else {
-               media_svc_debug("Not proper img format");
-       }
-
-       return ret;
-}
-
-static int __media_svc_safe_atoi(char *buffer, int *si)
-{
-       char *end = NULL;
-       errno = 0;
-       media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
-
-       const long sl = strtol(buffer, &end, 10);
-
-       media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
-       media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
-       media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
-       media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
-       media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
-
-       *si = (int)sl;
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-
-       media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
-
-       if (!image) {
-               media_svc_error("invalid image..");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
        struct statfs fs;
        char *thumb_path = NULL;
-       ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
-       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
-
-       if (-1 == statfs(thumb_path, &fs)) {
-               media_svc_error("error in statfs");
-               SAFE_FREE(thumb_path);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       SAFE_FREE(thumb_path);
+       long bsize_kbytes = 0;
+       GError *error = NULL;
 
-       long bsize_kbytes = fs.f_bsize >> 10;
+       media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
+       media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
 
-       if ((bsize_kbytes * fs.f_bavail) < 1024) {
-               media_svc_error("not enought space...");
-               return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
-       }
+       ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
 
-       FILE *fp = NULL;
-       int nwrite = -1;
-       if (image != NULL && size > 0) {
-               fp = fopen(image_path, "w");
+       ret = statfs(thumb_path, &fs);
+       g_free(thumb_path);
+       media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
 
-               if (fp == NULL) {
-                       media_svc_error("failed to open file");
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
+       bsize_kbytes = fs.f_bsize >> 10;
+       media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
 
-               nwrite = fwrite(image, 1, size, fp);
-               if (nwrite != size) {
-                       media_svc_error("failed to write thumbnail");
-                       fclose(fp);
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-               fclose(fp);
+       if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
+               media_svc_error("g_file_set_contents faild:%s", error->message);
+               g_error_free(error);
+               return MS_MEDIA_ERR_INTERNAL;
        }
 
        return MS_MEDIA_ERR_NONE;
 }
 
-static char *__media_svc_get_title_from_filepath(const char *path)
+static char *__media_svc_get_title_from_filename(const char *filename)
 {
-       char *filename = NULL;
        char *title = NULL;
-       char    *ext = NULL;
-       int filename_len = -1;
-       int new_title_len = -1;
-
-       if (!path) {
-               media_svc_error("path is NULL");
-               return NULL;
-       }
-
-       filename = g_path_get_basename(path);
-       if (!STRING_VALID(filename)) {
-               media_svc_error("wrong file name");
-               SAFE_FREE(filename);
-               return NULL;
-       }
-
-       filename_len = strlen(filename);
+       char *last_dot = NULL;
 
-       ext = g_strrstr(filename, ".");
-       if (!ext) {
-               media_svc_error("there is no file extention");
-               return filename;
-       }
+       media_svc_retvm_if(!STRING_VALID(filename), g_strdup(MEDIA_SVC_TAG_UNKNOWN), "Invalid path");
 
-       new_title_len = filename_len - strlen(ext);
-       if (new_title_len < 1) {
-               media_svc_error("title length is zero");
-               SAFE_FREE(filename);
-               return NULL;
+       last_dot = strrchr(filename, '.');
+       if (last_dot) {
+               title = g_strndup(filename, last_dot - filename);
+       } else {
+               title = g_strdup(filename);
        }
 
-       title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
-
-       SAFE_FREE(filename);
-
        media_svc_debug("extract title is [%s]", title);
 
        return title;
@@ -646,53 +330,32 @@ void _media_svc_remove_file(const char *path)
                media_svc_stderror("fail to remove file result");
 }
 
-int _media_svc_get_thumbnail_path(media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
+static int __media_svc_get_thumbnail_path(char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
-       char hash[255 + 1] = {0, };
-       char *thumb_dir = NULL;
-       char *thumbfile_ext = NULL;
+       g_autofree gchar *hash = NULL;
+       g_autofree gchar *thumb_dir = NULL;
 
        ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
-       if (!STRING_VALID(thumb_dir)) {
-               media_svc_error("ms_user_get_root_thumb_store_path failed");
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
-               media_svc_error("Wrong path[%s]", thumb_dir);
-               SAFE_FREE(thumb_dir);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       media_svc_retvm_if(!STRING_VALID(thumb_dir), ret, "ms_user_get_root_thumb_store_path failed");
+       media_svc_retvm_if(!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INTERNAL, "Not a directory");
 
        memset(file_ext, 0, sizeof(file_ext));
        if (!__media_svc_get_file_ext(pathname, file_ext))
                media_svc_error("get file ext fail");
 
-       ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
-       if (ret != MS_MEDIA_ERR_NONE) {
-               media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
-               SAFE_FREE(thumb_dir);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       hash = g_compute_checksum_for_string(G_CHECKSUM_MD5, pathname, -1);
+       media_svc_retvm_if(!hash, MS_MEDIA_ERR_INTERNAL, "Failed to create hashname");
 
-       if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
-               if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
-                       thumbfile_ext = (char *)"jpg";
-               } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
-                       thumbfile_ext = (char *)"png";
-               } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
-                       thumbfile_ext = (char *)"gif";
-               } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
-                       thumbfile_ext = (char *)"bmp";
-               } else {
+       if (img_format) {
+               /* 'img_format' is mime-type */
+               if (!g_str_has_prefix(img_format, IMAGE_PREFIX) || strlen(img_format) == PREFIX_LEN) {
                        media_svc_error("Not proper img format");
-                       SAFE_FREE(thumb_dir);
                        return MS_MEDIA_ERR_INTERNAL;
                }
 
-               snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
+               snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, img_format + PREFIX_LEN);
        } else {
                if (strcasecmp(file_ext, "PNG") == 0)
                        snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
@@ -700,111 +363,40 @@ int _media_svc_get_thumbnail_path(media_svc_media_type_e media_type, char *thumb
                        snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
        }
 
-       SAFE_FREE(thumb_dir);
-
        return MS_MEDIA_ERR_NONE;
 }
 
 int _media_svc_get_file_time(const char *full_path)
 {
-       struct stat statbuf;
-       int fd = 0;
+       struct stat statbuf = { 0, };
 
-       memset(&statbuf, 0, sizeof(struct stat));
-       fd = stat(full_path, &statbuf);
-       if (fd == -1) {
-               media_svc_sec_error("stat(%s) fails.", full_path);
-               return MS_MEDIA_ERR_INTERNAL;
+       if (stat(full_path, &statbuf) == -1) {
+               media_svc_stderror("stat fails.");
+               return 0;
        }
 
        return statbuf.st_mtime;
 }
 
-int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
-{
-       /* Set default GPS value before extracting meta information */
-       content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
-       content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
-       content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
-
-       /* Set filename to title for all media */
-       char *title = NULL;
-       title = __media_svc_get_title_from_filepath(content_info->path);
-       if (title) {
-               content_info->media_meta.title = g_strdup(title);
-               SAFE_FREE(title);
-               media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-       } else {
-               media_svc_error("Can't extract title");
-               content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-               media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-       }
-
-       /* Set default value before extracting meta information */
-       content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       if (refresh) {
-               media_svc_debug("refresh");
-               return MS_MEDIA_ERR_NONE;
-       }
-
-       content_info->favourate = 0;
-       content_info->media_meta.rating = 0;
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, bool refresh)
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, const char *path, bool refresh)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       char * media_uuid = NULL;
-       bool drm_type = false;
        char mime_type[256] = {0, };
        media_svc_media_type_e media_type;
+       struct stat st = { 0, };
 
-       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
        media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
 
        content_info->path = g_strdup(path);
-       media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
+       content_info->file_name = g_path_get_basename(path);
 
-       struct stat st;
-       memset(&st, 0, sizeof(struct stat));
        if (stat(path, &st) == 0) {
                content_info->modified_time = st.st_mtime;
-               content_info->timeline = content_info->modified_time;
                content_info->size = st.st_size;
        } else {
                media_svc_stderror("stat failed");
        }
 
-       _media_svc_set_default_value(content_info, refresh);
-
        /* refresh is TRUE when file modified. so only modified_time and size are changed*/
        if (refresh) {
                media_svc_debug("refresh");
@@ -814,28 +406,13 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char
        content_info->storage_uuid = g_strdup(storage_id);
        media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
 
-       content_info->storage_type = storage_type;
-       time(&content_info->added_time);
-
-       media_uuid = _media_info_generate_uuid();
-       if (media_uuid == NULL) {
-               _media_svc_destroy_content_info(content_info);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       content_info->media_uuid = g_strdup(media_uuid);
+       content_info->media_uuid = __media_info_generate_uuid();
        media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
 
-       content_info->file_name = g_path_get_basename(path);
-       media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
-
-       /* if the file is DRM file, drm_type value is DRM_TRUE(1).
-       if drm_contentinfo is not NULL, the file is OMA DRM.*/
        ret = __media_svc_get_mime_type(path, mime_type);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
 
        media_svc_debug("mime [%s]", mime_type);
-       content_info->is_drm = drm_type;
 
        ret = __media_svc_get_media_type(path, mime_type, &media_type);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
@@ -843,1072 +420,763 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char
        content_info->mime_type = g_strdup(mime_type);
        media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
 
-       media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
+       media_svc_sec_debug("path[%s], media_type[%d]", content_info->path, media_type);
 
        content_info->media_type = media_type;
 
        return MS_MEDIA_ERR_NONE;
 }
 
-int image_360_check(char *path)
+static char * __media_svc_get_title(MMHandleType tag, const char *filename)
 {
-       FILE *fp = NULL;
-       long app1_size = 0;
-       int size = 1;
-       unsigned char exif_header[4] = {0, };
-       unsigned char exif_app1[2] = {0, };
-       unsigned char exif_app1_xmp[2] = {0, };
-       long exif_app1_xmp_size = 0;
-       unsigned char exif_app1_xmp_t[2] = {0, };
-       char *xmp_data = NULL;
-       int size1 = 0;
-       int size2 = 0;
-       int fdata = 0;
-       int temp = 0;
-
-       memset(exif_header, 0x00, sizeof(exif_header));
-       memset(exif_app1, 0x00, sizeof(exif_app1));
-       memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
-       memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
-
-       fp = fopen(path, "rb");
-       if (fp == NULL)
-               goto ERROR;
-
-       size = fread(exif_header, 1, sizeof(exif_header), fp);
-       if (size <= 0)
-               goto ERROR;
-
-       if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
-               size = fread(exif_app1, 1, sizeof(exif_app1), fp);
-               if (size <= 0)
-                       goto ERROR;
-
-               size1 = exif_app1[0];
-               size2 = exif_app1[1];
-
-               app1_size = size1 * 256 + size2 - 2;
-
-               if (fseek(fp, app1_size, SEEK_CUR) != 0)
-                       goto ERROR;
-
-               size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
-               if (size <= 0)
-                       goto ERROR;
-
-               if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
-                       int result = 0;
-                       char *ptr = NULL;
-                       size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
-                       if (size <= 0)
-                               goto ERROR;
-
-                       size1 = exif_app1_xmp_t[0];
-                       size2 = exif_app1_xmp_t[1];
-
-                       exif_app1_xmp_size = size1 * 256 + size2 - 2;
-
-                       if (exif_app1_xmp_size > 0) {
-                               xmp_data = (char *)malloc(exif_app1_xmp_size);
-                               memset(xmp_data, 0x0, exif_app1_xmp_size);
-
-                               ptr = xmp_data;
-
-                               while (exif_app1_xmp_size >= 0) {
-                                       exif_app1_xmp_size--;
-                                       fdata = fgetc(fp);
-                                       if (fdata == EOF)
-                                               continue;
-                                       if (fdata == '\0')
-                                               continue;
-                                       *ptr = (char)fdata;
-                                       ptr++;
-                                       temp++;
-                               }
-                               ptr = ptr - temp;
-
-                               if (strstr(ptr, "UsePanoramaViewer")
-                               && strstr(ptr, "True")
-                               && strstr(ptr, "ProjectionType")
-                               && strstr(ptr, "equirectangular"))
-                                       result = 1;
+       int ret = FILEINFO_ERROR_NONE;
+       char *p = NULL;
+       int size = 0;
 
-                               SAFE_FREE(xmp_data);
-                       } else {
-                               media_svc_error("invalid exif_app1_xmp_size [%ld]", exif_app1_xmp_size);
-                       }
+       if (tag) {
+               ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
+               if (ret == FILEINFO_ERROR_NONE && size > 0) {
+                       while(p && isspace(*p))
+                               p++;
 
-                       if (fp) {
-                               fclose(fp);
-                               fp = NULL;
-                       }
-                       return result;
-               } else {
-                       goto ERROR;
+                       return g_strdup(p);
                }
-       } else {
-               goto ERROR;
        }
-ERROR:
-       if (fp) {
-               fclose(fp);
-               fp = NULL;
-       }
-       return 0;
+
+       return __media_svc_get_title_from_filename(filename);
+}
+
+char * _media_svc_get_title_from_filename(const char *filename)
+{
+       return __media_svc_get_title_from_filename(filename);
 }
 
 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
 {
-       double value = 0.0;
-       int orient_value = 0;
-       int exif_width = 0;
-       int exif_height = 0;
+       unsigned short orient_value = 0;
+       unsigned short exif_width = 0;
+       unsigned short exif_height = 0;
        ExifData *ed = NULL;
-       bool has_datetaken = false;
-       double fnumber = 0.0;
-       int iso = 0;
-       char *path = NULL;
-
-       char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
 
        media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
-       media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type [%d]", content_info->media_type);
+       media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type");
        media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
 
-       path = content_info->path;
+       content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
 
        /* Load an ExifData object from an EXIF file */
-       ed = exif_data_new_from_file(path);
-
+       ed = exif_data_new_from_file(content_info->path);
        if (!ed) {
-               media_svc_sec_debug("There is no exif data in [ %s ]", path);
+               media_svc_sec_debug("There is no exif data in [ %s ]", content_info->path);
                goto GET_WIDTH_HEIGHT;
        }
 
-       content_info->media_meta.is_360 = image_360_check(path);
-
-       content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
-       content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
-       content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       content_info->media_meta.fnumber = 0.0;
-       content_info->media_meta.iso = 0;
-       content_info->media_meta.orientation = 0;
-       content_info->media_meta.width = 0;
-       content_info->media_meta.height = 0;
-
-       memset(buf, 0x00, sizeof(buf));
-       if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
-               if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
-                       if (strlen(buf) > 0) {
-                               if (strcmp(buf, "S") == 0)
-                                       value = -1 * value;
-                       }
-                       content_info->media_meta.latitude = value;
-               }
-       }
+       content_info->media_meta.datetaken = __media_svc_get_exif_datetaken(ed);
 
-       memset(buf, 0x00, sizeof(buf));
-       if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
-               if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
-                       if (strlen(buf) > 0) {
-                               if (strcmp(buf, "W") == 0)
-                                       value = -1 * value;
-                       }
-                       content_info->media_meta.longitude = value;
-               }
+       if (__media_svc_get_exif_short(ed, EXIF_TAG_ORIENTATION, &orient_value)) {
+               if (orient_value <= ROT_270)
+                       content_info->media_meta.orientation = orient_value;
        }
 
-       memset(buf, 0x00, sizeof(buf));
-       if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0) {
-                       SAFE_FREE(content_info->media_meta.description);
-                       content_info->media_meta.description = g_strdup(buf);
-               }
-       }
+       if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_X_DIMENSION, &exif_width))
+               content_info->media_meta.width = (unsigned int)exif_width;
 
-       memset(buf, 0x00, sizeof(buf));
-       if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0) {
-                       has_datetaken = true;
-                       content_info->media_meta.datetaken = g_strdup(buf);
+       if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_Y_DIMENSION, &exif_height))
+               content_info->media_meta.height = (unsigned int)exif_height;
 
-                       /* This is same as recorded_date */
-                       content_info->media_meta.recorded_date = g_strdup(buf);
-               }
-       }
+       exif_data_unref(ed);
 
-       memset(buf, 0x00, sizeof(buf));
-       if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0) {
-                       has_datetaken = true;
-                       content_info->media_meta.datetaken = g_strdup(buf);
+GET_WIDTH_HEIGHT:
+       if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
+               /*Get image width, height*/
+               unsigned int img_width = 0;
+               unsigned int img_height = 0;
 
-                       /* This is same as recorded_date */
-                       content_info->media_meta.recorded_date =  g_strdup(buf);
-               }
-       }
+               if (get_image_info(content_info->path, &img_width, &img_height) != THUMB_OK)
+                       return MS_MEDIA_ERR_NONE;
 
-       if (has_datetaken) {
-               content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
-               if (content_info->timeline == 0)
-                       content_info->timeline = content_info->modified_time;
-               else
-                       media_svc_debug("Timeline : %ld", content_info->timeline);
-       }
+               if (content_info->media_meta.width == 0)
+                       content_info->media_meta.width = img_width;
 
-       memset(buf, 0x00, sizeof(buf));
-       /* Get exposure_time value from exif. */
-       if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0)
-                       content_info->media_meta.exposure_time = g_strdup(buf);
+               if (content_info->media_meta.height == 0)
+                       content_info->media_meta.height = img_height;
        }
 
-       /* Get fnumber value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
-               if (fnumber > 0.0)
-                       content_info->media_meta.fnumber = fnumber;
-       }
+       return MS_MEDIA_ERR_NONE;
+}
 
-       /* Get iso value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
-               if (iso > 0)
-                       content_info->media_meta.iso = iso;
-       }
-
-       memset(buf, 0x00, sizeof(buf));
-       /* Get model value from exif. */
-       if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0)
-                       content_info->media_meta.model = g_strdup(buf);
-       }
-
-       /* Get orientation value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
-               if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
-                       content_info->media_meta.orientation = orient_value;
-       }
+static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
+{
+       int ret = FILEINFO_ERROR_NONE;
+       char *p = NULL;
+       int size = 0;
 
-       /* Get width value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
-               if (exif_width > 0)
-                       content_info->media_meta.width = exif_width;
-       }
+       ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
+       if (ret == FILEINFO_ERROR_NONE && size > 0)
+               return g_strdup(p);
 
-       /* Get height value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
-               if (exif_height > 0)
-                       content_info->media_meta.height = exif_height;
-       }
+       return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+}
 
-       if (ed != NULL) exif_data_unref(ed);
+static char * __media_svc_extract_albumart(MMHandleType tag, const char *path, uid_t uid)
+{
+       int ret = FILEINFO_ERROR_NONE;
+       unsigned char *image = NULL;
+       unsigned int size = 0;
+       char *mimetype = NULL;
+       char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = { 0, };
+       unsigned int mime_size = 0;
 
-GET_WIDTH_HEIGHT:
+       ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
+       media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag artwork[%d]", ret);
+       media_svc_retvm_if(!image || size == 0, NULL, "Invalid artwork");
 
-       if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
-               /*Get image width, height*/
-               unsigned int img_width = 0;
-               unsigned int img_height = 0;
-               mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
+       ret = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &mimetype, &mime_size, NULL);
+       media_svc_retvm_if(ret != FILEINFO_ERROR_NONE, NULL, "Failed to get tag mime[%d]", ret);
+       media_svc_retvm_if(mime_size == 0, NULL, "Invalid mimetype");
 
-               mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
-               if (content_info->media_meta.width == 0)
-                       content_info->media_meta.width = img_width;
+       ret = __media_svc_get_thumbnail_path(thumb_path, path, mimetype, uid);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Failed to get thumbnail path");
 
-               if (content_info->media_meta.height == 0)
-                       content_info->media_meta.height = img_height;
-       }
+       ret = __media_svc_save_image(image, size, thumb_path, uid);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, NULL, "Fail to save thumbnail");
 
-       return MS_MEDIA_ERR_NONE;
+       return g_strdup(thumb_path);
 }
 
-int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *path)
+void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
 {
        MMHandleType tag = 0;
        char *p = NULL;
-       int size = -1;
+       unsigned int size = 0;
        int mmf_error = FILEINFO_ERROR_NONE;
+       int album_id = 0;
+       int ret = MS_MEDIA_ERR_NONE;
+       bool support_albumart = ms_user_thumb_support(uid, content_info->path);
 
-       content_info->path = g_strdup(path);
-
-       mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
-       if (mmf_error != FILEINFO_ERROR_NONE)
-               return MS_MEDIA_ERR_INTERNAL;
+       /*Get Content Tag attribute ===========*/
+       if (support_albumart)
+               mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
+       else
+               mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
 
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.album = g_strdup(p);
-
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTIST, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.artist = g_strdup(p);
-
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.album_artist = g_strdup(p);
-
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_GENRE, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.genre = g_strdup(p);
-
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
-               if (!isspace(*p)) {
-                       content_info->media_meta.title = g_strdup(p);
-               } else {
-                       int idx = 0;
-
-                       for (idx = 0; idx < size; idx++) {
-                               if (isspace(*p)) {
-                                       media_svc_debug("SPACE [%s]", p);
-                                       p++;
-                                       continue;
-                               } else {
-                                       media_svc_debug("Not SPACE [%s]", p);
-                                       content_info->media_meta.title = g_strdup(p);
-                                       break;
-                               }
-                       }
-               }
+       if (mmf_error != FILEINFO_ERROR_NONE) {
+               content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+               content_info->album_id = 0;
+               return;
        }
 
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.description = g_strdup(p);
+       content_info->media_meta.title = __media_svc_get_title(tag, content_info->file_name);
+       content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
+       content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
+       content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
+       content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
+       content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
 
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.composer = g_strdup(p);
+       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
+       if (mmf_error == FILEINFO_ERROR_NONE && size == 4)
+               content_info->media_meta.year = g_strdup(p);
+       else
+               content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
 
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
-       if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-               content_info->media_meta.copyright = g_strdup(p);
+       /*Do not extract artwork for the USB Storage content*/
+       if (support_albumart)
+               content_info->thumbnail_path = __media_svc_extract_albumart(tag, content_info->path, uid);
 
-       mmf_error = mm_file_destroy_tag_attrs(tag);
-       if (mmf_error != FILEINFO_ERROR_NONE)
-               media_svc_error("fail to free tag attr - err(%x)", mmf_error);
+       ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
+       if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+               media_svc_debug("album does not exist. So start to make album art");
+               if (strlen(content_info->media_meta.album) > 0 && strlen(content_info->media_meta.artist) > 0)
+                       ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
+               else
+                       ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
+       }
+       content_info->album_id = album_id;
 
-       return MS_MEDIA_ERR_NONE;
+       if (mm_file_destroy_tag_attrs(tag) != FILEINFO_ERROR_NONE)
+               media_svc_error("destroy failed");
 }
 
-int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
+void _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
 {
-       MMHandleType content = 0;
-       MMHandleType tag = 0;
-       char *p = NULL;
-       unsigned char *image = NULL;
-       unsigned int size = 0;
-       int mmf_error = FILEINFO_ERROR_NONE;
-       int album_id = 0;
-       int ret = MS_MEDIA_ERR_NONE;
-       int cdis_value = 0;
+       /* All metadata fields must be empty strings until media_video is deleted */
+       content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+       content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->album_id = 0;
+}
 
-       /*Get Content Tag attribute ===========*/
-       mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
+static gchar * __media_svc_get_zipfile_string(zip_t *z, const char *fname)
+{
+       int err = 0;
+       zip_int64_t index_num = 0;
+       zip_file_t *file = NULL;
+       zip_stat_t sb = {0, };
+       gchar *buf = NULL;
 
-       if (mmf_error == FILEINFO_ERROR_NONE) {
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.album = g_strdup(p);
+       media_svc_retvm_if(!z, NULL, "z is NULL");
+       media_svc_retvm_if(!fname, NULL, "fname is NULL");
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTIST, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.artist = g_strdup(p);
+       index_num = zip_name_locate(z, fname, ZIP_FL_NOCASE);
+       media_svc_retvm_if(index_num == -1, NULL, "fname is not exists [%s]", fname);
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.album_artist = g_strdup(p);
+       err = zip_stat_index(z, index_num, ZIP_STAT_SIZE, &sb);
+       media_svc_retvm_if(err == -1, NULL, "zip_stat_index failed");
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_GENRE, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.genre = g_strdup(p);
+       file = zip_fopen_index(z, index_num, ZIP_FL_UNCHANGED);
+       media_svc_retvm_if(!file, NULL, "zip_fopen_index failed");
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
-                       while(p && isspace(*p))
-                               p++;
+       buf = g_malloc0(sb.size + 1);
 
-                       content_info->media_meta.title = g_strdup(p);
-               }
+       err = zip_fread(file, buf, sb.size);
+       zip_fclose(file);
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.description = g_strdup(p);
-
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
-
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
-               if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
-                       char mime_type[255] = {0, };
-                       ret = __media_svc_get_mime_type(content_info->path, mime_type);
-                       /*if 3gp that audio only, media_type is music */
-                       if ((ret == MS_MEDIA_ERR_NONE) &&
-                               ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
-                               (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
-                               (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
-                               (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
-                               /*Creation time format is 2013-01-01 00:00:00 +0000. change it to 2013:01:01 00:00:00 like exif time format*/
-                               char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
-                               char *p_value = p;
-                               char *time_value = time_info;
-                               if (time_info != NULL) {
-                                       while (*p_value != '\0') {
-                                               if (*p_value == '-')
-                                                       *time_value = ':';
-                                               else
-                                                       *time_value = *p_value;
-                                               time_value++;
-                                               p_value++;
-                                       }
-                                       content_info->media_meta.recorded_date = g_strdup(time_info);
-                                       SAFE_FREE(time_info);
-                               } else {
-                                       media_svc_error("memory allocation error");
-                               }
-                       } else {
-                               content_info->media_meta.recorded_date = g_strdup(p);
-                       }
+       if (err == -1) {
+               g_free(buf);
+               buf = NULL;
+       }
 
-                       if (STRING_VALID(content_info->media_meta.recorded_date)) {
-                               content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
-                               if (content_info->timeline == 0)
-                                       content_info->timeline = content_info->modified_time;
-
-                               /* This is same as datetaken */
-                               /* Remove compensation string */
-                               if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
-                                       content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
-                                       g_free(content_info->media_meta.recorded_date);
-                                       content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
-                               } else {
-                                       content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
-                               }
-                       }
-               }
+       return buf;
+}
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.composer = g_strdup(p);
+static xmlNodePtr __media_svc_find_node(xmlNodePtr node, const char *key)
+{
+       xmlNodePtr tmp = NULL;
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.copyright = g_strdup(p);
+       media_svc_retvm_if(!node, NULL, "node is NULL");
+       media_svc_retvm_if(!key, NULL, "key is NULL");
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
-                       content_info->media_meta.track_num = g_strdup(p);
+       for (tmp = node->children; tmp; tmp = tmp->next) {
+               if (xmlIsBlankNode(tmp))
+                       continue;
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
-                       int year = 0;
-                       if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
-                               content_info->media_meta.year = g_strdup(p);
-                       else
-                               media_svc_debug("Wrong Year Information [%s]", p);
-               }
+               if (g_str_has_suffix((gchar *)tmp->name, key))
+                       return tmp;
+       }
 
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RATING, &p, &size, NULL);
-               if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
-                       int rate = 0;
-                       if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
-                               content_info->media_meta.rating = rate;
-               } else {
-                       content_info->media_meta.rating = 0;
-               }
+       return NULL;
+}
 
-               /*Do not extract artwork for the USB Storage content*/
-               if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
-                       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("artwork size1 [%d]", size); */
-                       }
+static char * __media_svc_remove_escape_c(const char *value)
+{
+       int start = -1;
+       int end = 0;
+       int len, i;
 
-                       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_error("fail to get artwork size - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("artwork size2 [%d]", size); */
-                       }
+       media_svc_retv_if(!value, NULL);
 
-                       if (image != NULL && size > 0) {
-                               char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
-                               int artwork_mime_size = -1;
-
-                               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
-                               if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
-                                       ret = _media_svc_get_thumbnail_path(content_info->media_type, thumb_path, content_info->path, p, uid);
-                                       if (ret != MS_MEDIA_ERR_NONE)
-                                               media_svc_error("Fail to Get Thumbnail Path");
-
-                                       if (strlen(thumb_path) > 0) {
-                                               ret = __media_svc_save_image(image, size, thumb_path, uid);
-                                               if (ret != MS_MEDIA_ERR_NONE) {
-                                                       media_svc_error("Fail to Save Image");
-                                               } else {
-                                                       /* albumart resizing */
-                                                       ret = __media_svc_resize_artwork(thumb_path, p);
-                                                       if (ret != MS_MEDIA_ERR_NONE) {
-                                                               media_svc_error("Fail to Make Thumbnail Image");
-                                                               _media_svc_remove_file(thumb_path);
-
-                                                       } else {
-                                                               content_info->thumbnail_path = g_strdup(thumb_path);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
+       len = strlen(value);
 
-               /*Initialize album_id to 0. below code will set the album_id*/
-               content_info->album_id = album_id;
-               ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
-                               media_svc_debug("album does not exist. So start to make album art");
-                               if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
-                                       (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
-                                       ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
-                               else
-                                       ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
-
-                               content_info->album_id = album_id;
-                       }
-               } else {
-                       content_info->album_id = album_id;
+       for (i = 0; i < len; i++) {
+               if (value[i] != 10 && value[i] != 32) { // 10='\n' 32=' '
+                       if (start == -1)
+                               start = i;
+
+                       end = i;
                }
+       }
 
-               if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
-                       double longitude = 0.0;
-                       double latitude = 0.0;
-                       double altitude = 0.0;
+       end = end - start + 1;
 
-                       mm_file_get_attrs(tag, MM_FILE_TAG_LONGITUDE, &longitude,
-                               MM_FILE_TAG_LATIDUE, &latitude,
-                               MM_FILE_TAG_ALTIDUE, &altitude,
-                               NULL);
+       return g_strndup(value + start, end);
+}
 
-                       content_info->media_meta.longitude = (longitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : longitude;
-                       content_info->media_meta.latitude = (latitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : latitude;
-                       content_info->media_meta.altitude = (altitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : altitude;
+static char * __media_svc_find_and_get_value(xmlNodePtr node, const char *key)
+{
+       xmlNodePtr tmp = NULL;
+       char *tmp_res = NULL;
+       char *res = NULL;
 
-                       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE)
-                               cdis_value = 0;
+       media_svc_retvm_if(!node, NULL, "node is NULL");
+       media_svc_retvm_if(!key, NULL, "key is NULL");
 
-                       media_svc_debug("CDIS : %d", cdis_value);
+       for (tmp = node->children; tmp; tmp = tmp->next) {
+               if (xmlIsBlankNode(tmp))
+                       continue;
 
-                       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
-                       if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
-                               content_info->media_meta.orientation = atoi(p);
-                       } else {
-                               content_info->media_meta.orientation = 0;
-                               media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
+               if (tmp->children) {
+                       tmp_res = __media_svc_find_and_get_value(tmp, key);
+                       if (tmp_res) {
+                               res = __media_svc_remove_escape_c(tmp_res);
+                               xmlFree(tmp_res);
+                               return res;
                        }
                }
 
-               mmf_error = mm_file_destroy_tag_attrs(tag);
-               if (mmf_error != FILEINFO_ERROR_NONE)
-                       media_svc_error("fail to free tag attr - err(%x)", mmf_error);
-       }       else {
-               content_info->album_id = album_id;
+               if (g_str_has_suffix((gchar *)tmp->name, key))
+                       return (char *)xmlNodeGetContent(tmp);
        }
 
-       /*Get Content attribute ===========*/
-       if (cdis_value == 1)
-               mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
-       else
-               mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
-
-       if (mmf_error == FILEINFO_ERROR_NONE) {
-               /*Common attribute*/
-               mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
-               if (mmf_error != FILEINFO_ERROR_NONE) {
-                       media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
-               } else {
-                       /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
-               }
+       return NULL;
+}
 
-               /*Sound/Music attribute*/
-               if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+static gboolean __media_svc_get_epub_root_file(zip_t *z, char **opf_file)
+{
+       gchar *buf = NULL;
+       gchar *tmp_buf = NULL;
+       xmlDocPtr doc = NULL;
+       xmlNodePtr node = NULL;
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
-                       }
+       media_svc_retvm_if(!z, FALSE, "z is NULL");
+       media_svc_retvm_if(!opf_file, FALSE, "opf_file is NULL");
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
-                       }
+       buf = __media_svc_get_zipfile_string(z, "META-INF/container.xml");
+       media_svc_retvm_if(!buf, FALSE, "buf is NULL");
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
-                       }
+       tmp_buf = g_strrstr(buf, ">");
+       if (tmp_buf)
+               *(tmp_buf + 1) = '\0';
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
-                       } else {
-                               media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
-                       }
-               } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)      {       /*Video attribute*/
-                       int audio_bitrate = 0;
-                       int video_bitrate = 0;
-
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
-                       }
+       doc = xmlParseDoc((const xmlChar *)buf);
+       g_free(buf);
+       media_svc_retvm_if(!doc, FALSE, "doc is NULL");
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("video bit rate : %d", video_bitrate); */
-                       }
+       node = xmlDocGetRootElement(doc);
+       node = __media_svc_find_node(node, "rootfiles");
+       node = __media_svc_find_node(node, "rootfile");
 
-                       content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
+       *opf_file = (char *)xmlGetProp(node, (const xmlChar *)"full-path");
+       media_svc_sec_debug("OPF [%s]", *opf_file);
+       xmlFreeDoc(doc);
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("width : %d", content_info->media_meta.width); */
-                       }
+       return TRUE;
+}
 
-                       mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
-                       if (mmf_error != FILEINFO_ERROR_NONE) {
-                               media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
-                       } else {
-                               /*media_svc_debug("height : %d", content_info->media_meta.height); */
-                       }
-               } else {
-                       media_svc_error("Not support type");
-                       mmf_error = mm_file_destroy_content_attrs(content);
-                       if (mmf_error != FILEINFO_ERROR_NONE)
-                               media_svc_error("fail to free content attr - err(%x)", mmf_error);
+static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_pdf, media_svc_content_info_s *content_info)
+{
+       xmlDocPtr doc = NULL;
+       xmlNodePtr root = NULL;
 
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
+       media_svc_retvm_if(!buffer, FALSE, "buffer is NULL");
+       media_svc_retvm_if(!content_info, FALSE, "content_info is NULL");
 
-               mmf_error = mm_file_destroy_content_attrs(content);
-               if (mmf_error != FILEINFO_ERROR_NONE)
-                       media_svc_error("fail to free content attr - err(%x)", mmf_error);
-       } else {
-               media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
+       doc = xmlParseDoc(buffer);
+       media_svc_retv_if(!doc, FALSE);
+
+       root = xmlDocGetRootElement(doc);
+       if (!root) {
+               xmlFreeDoc(doc);
+               return FALSE;
        }
 
-       return MS_MEDIA_ERR_NONE;
-}
+       content_info->media_meta.title = __media_svc_find_and_get_value(root, "title");
+       /* In the case of PDF, if there is no title, it may not be a metadata block. Search for the next xml block*/
+       if (is_pdf && !content_info->media_meta.title) {
+               xmlFreeDoc(doc);
+               return FALSE;
+       }
 
-void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
-{
-       media_svc_retm_if(content_info == NULL, "content info is NULL");
+       content_info->media_meta.artist = __media_svc_find_and_get_value(root, "creator");
+       if (!content_info->media_meta.artist)
+               content_info->media_meta.artist = __media_svc_find_and_get_value(root, "author");
+       content_info->media_meta.genre = __media_svc_find_and_get_value(root, "subject");
 
-       /* Delete media_svc_content_info_s */
-       SAFE_FREE(content_info->media_uuid);
-       SAFE_FREE(content_info->path);
-       SAFE_FREE(content_info->file_name);
-       SAFE_FREE(content_info->mime_type);
-       SAFE_FREE(content_info->folder_uuid);
-       SAFE_FREE(content_info->thumbnail_path);
-       SAFE_FREE(content_info->storage_uuid);
+       xmlFreeDoc(doc);
 
-       /* Delete media_svc_content_meta_s */
-       SAFE_FREE(content_info->media_meta.title);
-       SAFE_FREE(content_info->media_meta.album);
-       SAFE_FREE(content_info->media_meta.artist);
-       SAFE_FREE(content_info->media_meta.album_artist);
-       SAFE_FREE(content_info->media_meta.genre);
-       SAFE_FREE(content_info->media_meta.composer);
-       SAFE_FREE(content_info->media_meta.year);
-       SAFE_FREE(content_info->media_meta.recorded_date);
-       SAFE_FREE(content_info->media_meta.copyright);
-       SAFE_FREE(content_info->media_meta.track_num);
-       SAFE_FREE(content_info->media_meta.description);
-       SAFE_FREE(content_info->media_meta.datetaken);
-       SAFE_FREE(content_info->media_meta.exposure_time);
-       SAFE_FREE(content_info->media_meta.model);
-
-       SAFE_FREE(content_info->media_meta.title_pinyin);
-       SAFE_FREE(content_info->media_meta.album_pinyin);
-       SAFE_FREE(content_info->media_meta.artist_pinyin);
-       SAFE_FREE(content_info->media_meta.album_artist_pinyin);
-       SAFE_FREE(content_info->media_meta.genre_pinyin);
-       SAFE_FREE(content_info->media_meta.composer_pinyin);
-       SAFE_FREE(content_info->media_meta.copyright_pinyin);
-       SAFE_FREE(content_info->media_meta.description_pinyin);
+       return TRUE;
 }
 
-static void __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
+static int __media_svc_get_epub_metadata(media_svc_content_info_s *content_info)
 {
-       bool portrait = false;
-       double ratio = 0.0;
-
-       media_svc_retm_if(!orig_w, "Invalid orig_w");
-       media_svc_retm_if(!orig_h, "Invalid orig_h");
-       media_svc_retm_if(!thumb_w, "Invalid thumb_w");
-       media_svc_retm_if(!thumb_h, "Invalid thumb_h");
-
-       if (orig_w < orig_h)
-               portrait = true;
-
-       /* Set smaller length to default size */
-       if (portrait) {
-               if (orig_w < *thumb_w)
-                       *thumb_w = orig_w;
-               ratio = (double)orig_h / (double)orig_w;
-               *thumb_h = *thumb_w * ratio;
-       } else {
-               if (orig_h < *thumb_h)
-                       *thumb_h = orig_h;
-               ratio = (double)orig_w / (double)orig_h;
-               *thumb_w = *thumb_h * ratio;
-       }
+       int err = 0;
+       zip_t *z = NULL;
+       gchar *buf = NULL;
+       char *opf_path = NULL;
 
-       media_svc_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
-
-       return;
-}
+       media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
 
-static void __get_rotation_and_cdis(const char *origin_path, mm_util_magick_rotate_type *rot_type, int *cdis_value)
-{
-       int err = MS_MEDIA_ERR_NONE;
-       MMHandleType tag = (MMHandleType) NULL;
-       char *p = NULL;
-       int size = 0;
-       int _cdis_value = 0;
-       mm_util_magick_rotate_type _rot_type = MM_UTIL_ROTATE_NUM;
-
-       /* Get Content Tag attribute for orientation */
-       err = mm_file_create_tag_attrs(&tag, origin_path);
-       if (err != FILEINFO_ERROR_NONE) {
-               *rot_type = MM_UTIL_ROTATE_0;
-               *cdis_value = 0;
-               return;
-       }
+       //1. open epub
+       z = zip_open(content_info->path, ZIP_RDONLY, &err);
+       media_svc_retvm_if(err == -1, MS_MEDIA_ERR_INTERNAL, "zip_open failed");
 
-       err = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
-       if (err == FILEINFO_ERROR_NONE && size >= 0) {
-               if (p == NULL) {
-                       _rot_type = MM_UTIL_ROTATE_0;
-               } else {
-                       if (strncmp(p, "90", size) == 0)
-                               _rot_type = MM_UTIL_ROTATE_90;
-                       else if (strncmp(p, "180", size) == 0)
-                               _rot_type = MM_UTIL_ROTATE_180;
-                       else if (strncmp(p, "270", size) == 0)
-                               _rot_type = MM_UTIL_ROTATE_270;
-                       else
-                               _rot_type = MM_UTIL_ROTATE_0;
-               }
-               media_svc_debug("There is tag rotate : %d", _rot_type);
-       } else {
-               media_svc_debug("There is NOT tag rotate");
-               _rot_type = MM_UTIL_ROTATE_0;
+       //2. find and read opf file
+       if (!__media_svc_get_epub_root_file(z, &opf_path)) {
+               media_svc_error("__media_svc_get_epub_root_file failed");
+               zip_close(z);
+               return MS_MEDIA_ERR_INTERNAL;
        }
 
-       err = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &_cdis_value, NULL);
-       if (err != FILEINFO_ERROR_NONE)
-               _cdis_value = 0;
+       //3. get metadata
+       buf = __media_svc_get_zipfile_string(z, opf_path);
+       xmlFree(opf_path);
+       zip_close(z);
+       media_svc_retvm_if(!buf, MS_MEDIA_ERR_INTERNAL, "__media_svc_get_zipfile_string failed");
 
-       *rot_type = _rot_type;
-       *cdis_value = _cdis_value;
+       if (!__media_svc_get_xml_metadata((const xmlChar *)buf, FALSE, content_info))
+               media_svc_error("__media_svc_get_xml_metadata failed");
 
-       err = mm_file_destroy_tag_attrs(tag);
-       if (err != FILEINFO_ERROR_NONE) {
-               media_svc_error("fail to free tag attr - err(%x)", err);
-       }
+       g_free(buf);
 
-       return;
+       return MS_MEDIA_ERR_NONE;
 }
 
-static int __get_video_info(int cdis_value, const char *origin_path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *size)
+static int __media_svc_get_pdf_metadata(media_svc_content_info_s *content_info)
 {
-       int err = MS_MEDIA_ERR_NONE;
-       MMHandleType content = (MMHandleType) NULL;
-       int _video_track_num = 0;
-       int _width = 0;
-       int _height = 0;
-       size_t _size = 0;
-       void *_frame = NULL;
-
-       if (cdis_value == 1) {
-               media_svc_debug("This is CDIS vlaue 1");
-               err = mm_file_create_content_attrs_safe(&content, origin_path);
-       } else {
-               err = mm_file_create_content_attrs(&content, origin_path);
-       }
+    int fd = 0;
+    int start_pos = 0;
+    int end_pos = 0;
+    int cur_pos = 0;
+    int search_limit = 0;
+    char tmp[MEDIA_SVC_PDF_BUF_SIZE + 1] = {0, };
+    gchar *meta_buf = NULL;
+    char *found = NULL;
 
-       if (err != FILEINFO_ERROR_NONE) {
-               media_svc_error("mm_file_create_content_attrs fails : %d", err);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       err = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &_video_track_num, NULL);
-       if (err != FILEINFO_ERROR_NONE) {
-               media_svc_error("mm_file_get_attrs fails : %d", err);
-               mm_file_destroy_content_attrs(content);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content_info is NULL");
+       media_svc_retvm_if(content_info->size < 256, MS_MEDIA_ERR_INTERNAL, "open failed");
 
-       *video_track_num = _video_track_num;
+       fd = open(content_info->path, O_RDONLY);
+       media_svc_retvm_if(fd < 0, MS_MEDIA_ERR_INTERNAL, "open failed");
 
-       if (_video_track_num == 0) {
-               mm_file_destroy_content_attrs(content);
-               return MS_MEDIA_ERR_NONE;
-       }
+       search_limit = content_info->size - MEDIA_SVC_PDF_TAG_TAIL_LEN;
 
-       err = mm_file_get_attrs(content,
-                               MM_FILE_CONTENT_VIDEO_WIDTH,
-                               &_width,
-                               MM_FILE_CONTENT_VIDEO_HEIGHT,
-                               &_height,
-                               MM_FILE_CONTENT_VIDEO_THUMBNAIL, &_frame, /* raw image is RGB888 format */
-                               &_size, NULL);
-
-       if (err != FILEINFO_ERROR_NONE) {
-               media_svc_error("mm_file_get_attrs fails : %d", err);
-               mm_file_destroy_content_attrs(content);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       while (cur_pos <= search_limit) {
+               if (lseek(fd, cur_pos, SEEK_SET) == -1)
+                       break;
 
-       media_svc_debug("W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _size, _frame);
-       if (!_frame || !_width || !_height) {
-               mm_file_destroy_content_attrs(content);
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+               memset(&tmp, 0x00, MEDIA_SVC_PDF_BUF_SIZE + 1);
 
+               if (read(fd, &tmp, MEDIA_SVC_PDF_BUF_SIZE) != MEDIA_SVC_PDF_BUF_SIZE) {
+                       media_svc_error("read failed");
+                       break;
+               }
 
-       *width = _width;
-       *height = _height;
-       *size = _size;
-       *frame = calloc(1, _size);
-       memcpy(*frame, _frame, _size);
+               //1.Find <x:xmpmeta .. </x:xmpmeta> block
+               if (start_pos == 0 && (found = strstr(tmp, "<x:xmpmeta"))) {
+                       start_pos = cur_pos + (found - tmp);
+//                     media_svc_error("FIND START_POS[%d]", start_pos);
+                       found = NULL;
+               }
 
-       mm_file_destroy_content_attrs(content);
 
-       return MS_MEDIA_ERR_NONE;
-}
+               if (start_pos != 0 && (found = strstr(tmp, "</x:xmpmeta>"))) {
+                       end_pos = cur_pos + (found - tmp) + MEDIA_SVC_PDF_TAG_TAIL_LEN;
+//                     media_svc_error("FIND END_POS[%d]", end_pos);
+                       found = NULL;
+               }
 
-static int __get_video_thumb(int width, int height, void *frame, size_t size, mm_util_magick_rotate_type rot_type, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height)
-{
-       int err = MS_MEDIA_ERR_NONE;
-       mm_util_image_h img = NULL;
-       mm_util_image_h resize_img = NULL;
-
-       media_svc_retvm_if(!STRING_VALID(thumb_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
-       __media_svc_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
-       if (thumb_width <= 0 || thumb_height <= 0) {
-               media_svc_error("Failed to get thumb size");
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+               //2.get metadata using xml parser
+               if (start_pos && end_pos) {
+                       if (lseek(fd, start_pos, SEEK_SET) == -1)
+                               break;
 
-       media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height);
+                       meta_buf = g_malloc0(end_pos - start_pos + 1);
 
-       err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, size, &img);
-       media_svc_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err);
+                       if (read(fd, meta_buf, end_pos - start_pos) == end_pos - start_pos) {
+                               if (__media_svc_get_xml_metadata((const xmlChar *)meta_buf, TRUE, content_info)) {
+                                       g_free(meta_buf);
+                                       break;
+                               }
+                       }
 
-       if (width > thumb_width || height > thumb_height) {
-               if (rot_type != MM_UTIL_ROTATE_0) {
-                       err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
-                       if (err != MM_UTIL_ERROR_NONE)
-                               goto ERROR;
+                       g_free(meta_buf);
 
-                       err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
-               } else {
-                       err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path);
+                       start_pos = 0;
+                       end_pos = 0;
                }
-       } else {
-               if (rot_type != MM_UTIL_ROTATE_0)
-                       err = mm_util_rotate_B_P(img, rot_type, thumb_path);
-               else
-                       err = mm_util_resize_B_P(img, width, height, thumb_path);
+
+               cur_pos += 240;
+
        }
 
-ERROR:
-       mm_image_destroy_image(img);
-       mm_image_destroy_image(resize_img);
-       if (err != MS_MEDIA_ERR_NONE)
-               return MS_MEDIA_ERR_INTERNAL;
+       close(fd);
 
        return MS_MEDIA_ERR_NONE;
 }
 
-static int __create_video_thumbnail(const char *path, char *thumb_path)
+int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       int cdis_value = 0;
-       unsigned int width = 0;
-       unsigned int height = 0;
-       void *frame = NULL;
-       int video_track_num = 0;
-       size_t size = 0;
-       mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
 
-       __get_rotation_and_cdis(path, &rot_type, &cdis_value);
-       ret = __get_video_info(cdis_value, path, &video_track_num, &width, &height, &frame, &size);
-       media_svc_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to __get_video_info [%d]", ret);
-       media_svc_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track");
+       media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content info is NULL");
 
-       ret = __get_video_thumb(width, height, frame, size, rot_type, thumb_path, THUMB_WIDTH, THUMB_HEIGHT);
+       if (g_str_has_suffix(content_info->mime_type, "epub+zip"))
+               ret = __media_svc_get_epub_metadata(content_info);
+       else
+               ret = __media_svc_get_pdf_metadata(content_info);
 
-       SAFE_FREE(frame);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "failed to extract metadata");
+       if (!content_info->media_meta.title || strlen(content_info->media_meta.title) == 0) {
+               g_free(content_info->media_meta.title);
+               content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
+       }
 
-       return ret;
+       return MS_MEDIA_ERR_NONE;
+}
+
+void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
+{
+       media_svc_retm_if(!content_info, "content info is NULL");
+
+       /* Delete media_svc_content_info_s */
+       g_free(content_info->media_uuid);
+       g_free(content_info->path);
+       g_free(content_info->file_name);
+       g_free(content_info->mime_type);
+       g_free(content_info->thumbnail_path);
+       g_free(content_info->storage_uuid);
+
+       /* Delete media_svc_content_meta_s */
+       g_free(content_info->media_meta.title);
+       g_free(content_info->media_meta.album);
+       g_free(content_info->media_meta.artist);
+       g_free(content_info->media_meta.album_artist);
+       g_free(content_info->media_meta.genre);
+       g_free(content_info->media_meta.year);
+       g_free(content_info->media_meta.track_num);
+       g_free(content_info->media_meta.datetaken);
 }
 
 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       unsigned int origin_w = 0;
-       unsigned int origin_h = 0;
-       unsigned int thumb_w = THUMB_WIDTH;
-       unsigned int thumb_h = THUMB_HEIGHT;
-       mm_util_img_codec_type image_type = IMG_CODEC_UNKNOWN_TYPE;
-
-       if (path == NULL || thumb_path == NULL) {
-               media_svc_error("Invalid parameter");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
-                       media_svc_error("Original path(%s) doesn't exist.", path);
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
 
-       ms_user_storage_type_e store_type = -1;
-       ret = ms_user_get_storage_type(uid, path, &store_type);
+       media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+       media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
+       media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
 
-       if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
-               media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
+       if (!ms_user_thumb_support(uid, path)) {
+               media_svc_sec_error("origin path(%s) is invalid", path);
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
        media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
 
-       //1. make hash path
-       ret = _media_svc_get_thumbnail_path(media_type, thumb_path, path, THUMB_EXT, uid);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
-               SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
-               return ret;
-       }
+       //1. make thumb path
+       ret = __media_svc_get_thumbnail_path(thumb_path, path, NULL, uid);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Failed to create thumbnail path[%d]", ret);
 
        //2. save thumbnail
-       if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
-               ret = mm_util_extract_image_info(path, &image_type, &origin_w, &origin_h);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       media_svc_error("Getting image info is failed err: %d", ret);
-                       SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
+       if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
+               ret = create_image_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
+       else
+               ret = create_video_thumbnail_to_file(path, MEDIA_SVC_THUMB_WIDTH, MEDIA_SVC_THUMB_HEIGHT, thumb_path, true);
 
-               if (image_type == IMG_CODEC_UNKNOWN_TYPE) {
-                       media_svc_error("Unsupported image codec");
-                       return MS_MEDIA_ERR_UNSUPPORTED_CONTENT;
-               }
+       return (ret == THUMB_OK) ? MS_MEDIA_ERR_NONE : MS_MEDIA_ERR_INTERNAL;
+}
 
-               if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM)) {
-                       media_svc_error("This original image is too big");
-                       SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
-                       return MS_MEDIA_ERR_THUMB_TOO_BIG;
-               }
+int _media_svc_get_media_type(const char *path, int *mediatype)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       char mime_type[256] = {0};
+       media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
 
-               __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
-               ret = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path);
-               if (ret != MM_UTIL_ERROR_NONE) {
-                       media_svc_error("mm_util_resize_P_P err: %d", ret);
-                       SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
-                       return MS_MEDIA_ERR_INTERNAL;
-               }
-       } else {
-               return __create_video_thumbnail(path, thumb_path);
-       }
+       media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
+
+       ret = __media_svc_get_mime_type(path, mime_type);
+       if (ret == MS_MEDIA_ERR_NONE)
+               __media_svc_get_media_type(path, mime_type, &media_type);
+       else
+               media_svc_error("__media_svc_get_mime_type failed");
+
+       *mediatype = media_type;
 
        return ret;
 }
 
-int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
+bool _media_svc_is_keyword_included(const char *path, const char *keyword)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-       int size = 0;
-       pinyin_name_s *pinyinname = NULL;
+       bool ret = false;
+       void *handle = NULL;
+       bool (*svc_search) (const char *, const char *);
 
-       media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
-       media_svc_retvm_if(pinyin_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "pinyin_str is NULL");
+       media_svc_retvm_if(!path, false, "Invalid path");
+       media_svc_retvm_if(!keyword, false, "Invalid keyword");
 
-       *pinyin_str = NULL;
+       handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
+       media_svc_retvm_if(!handle, false, "dlopen failed");
 
-       ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
-       if (ret == MS_MEDIA_ERR_NONE) {
-               if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
-                       *pinyin_str = strdup(pinyinname[0].pinyin_name);
-               else
-                       *pinyin_str = strdup(src_str);  /* Return Original Non China Character */
+       if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
+               svc_search = dlsym(handle, "media_svc_epub_is_keyword_included");
+       else
+               svc_search = dlsym(handle, "media_svc_pdf_is_keyword_included");
+
+       if (!svc_search) {
+               media_svc_error("dlsym failed - %s", dlerror());
+               dlclose(handle);
+               return false;
        }
 
-       _media_svc_pinyin_free(pinyinname, size);
+       ret = svc_search(path, keyword);
+       dlclose(handle);
 
        return ret;
 }
 
-bool _media_svc_check_pinyin_support(void)
+static int __media_svc_create_wordbook_db(const char *path, sqlite3 **handle)
 {
-       int ret = SYSTEM_INFO_ERROR_NONE;
-       bool is_supported = false;
+       int ret = SQLITE_OK;
+       sqlite3 *db_handle = NULL;
+       char *err = NULL;
 
-       if (media_svc_pinyin_support == -1) {
-               ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
-               if (ret != SYSTEM_INFO_ERROR_NONE) {
-                       media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
-                       return false;
-               }
+       ret = sqlite3_open_v2(path, &db_handle, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
+       media_svc_retvm_if(ret != SQLITE_OK, ret, "sqlite3_open_v2 failed : %d", ret);
+
+       ret = sqlite3_exec(db_handle, "PRAGMA journal_mode = OFF;", NULL, NULL, &err);
+       if (ret != SQLITE_OK)
+               goto ERROR;
+
+       ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS files(id integer primary key autoincrement, path text unique, validity integer default 1);", NULL, NULL, &err);
+       if (ret != SQLITE_OK)
+               goto ERROR;
+
+       ret = sqlite3_exec(db_handle, "CREATE TABLE IF NOT EXISTS words(file_id integer, word text, frequency integer default 1, unique(file_id, word));", NULL, NULL, &err);
+       if (ret != SQLITE_OK)
+               goto ERROR;
+
+       ret = sqlite3_exec(db_handle, "CREATE TRIGGER IF NOT EXISTS TR_files_words DELETE ON files BEGIN DELETE FROM words WHERE file_id = old.id;END;", NULL, NULL, &err);
+       if (ret != SQLITE_OK)
+               goto ERROR;
+
+       *handle = db_handle;
+
+       return SQLITE_OK;
+
+ERROR:
+       media_svc_error("sqlite3_exec failed : %s", err);
+       SQLITE3_SAFE_FREE(err);
+       sqlite3_close_v2(db_handle);
+
+       return ret;
+}
+
+static bool __media_svc_get_wordbook_handle(uid_t uid, sqlite3 **handle)
+{
+       int ret = SQLITE_OK;
+       char *db_path = NULL;
+
+       ms_user_get_wordbook_db_path(uid, &db_path);
+       if (!db_path)
+               return false;
 
-               media_svc_pinyin_support = is_supported;
+       ret = sqlite3_open_v2(db_path, handle, SQLITE_OPEN_READWRITE, NULL);
+       if (ret != SQLITE_OK) {
+               ret = __media_svc_create_wordbook_db(db_path, handle);
+               free(db_path);
+               media_svc_retvm_if(ret != SQLITE_OK, false, "__media_svc_create_wordbook_db failed : %d", ret);
+       } else {
+               ret = sqlite3_exec(*handle, "PRAGMA journal_mode = OFF;", NULL, NULL, NULL);
+               if (ret != SQLITE_OK)
+                       media_svc_error("Failed to change journal mode [%d]", ret);
        }
 
-       return media_svc_pinyin_support;
+       return true;
 }
 
-int _media_svc_get_media_type(const char *path, int *mediatype)
+static bool __media_svc_is_exist_in_wordbook(sqlite3 *db_handle, const char *path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-       char mime_type[256] = {0};
-       media_svc_media_type_e media_type =  MEDIA_SVC_MEDIA_TYPE_OTHER;
+       int ret = SQLITE_OK;
+       char *err = NULL;
+       char *query = NULL;
 
-       media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
+       query = sqlite3_mprintf("UPDATE files SET validity=1 WHERE path = %Q", path);
 
-       ret = __media_svc_get_mime_type(path, mime_type);
-       if (ret == MS_MEDIA_ERR_NONE)
-               __media_svc_get_media_type(path, mime_type, &media_type);
+       ret = sqlite3_exec(db_handle, query, NULL, NULL, &err);
+       SQLITE3_SAFE_FREE(query);
+       if (ret != SQLITE_OK) {
+               media_svc_error("Query failed. [%s]", err);
+               SQLITE3_SAFE_FREE(err);
+               return false;
+       }
+
+       return sqlite3_changes(db_handle) > 0 ? true : false;
+}
+
+static void __media_svc_insert_to_wordbook(sqlite3 *db_handle, const char *path)
+{
+       void *handle = NULL;
+       void (*svc_update) (sqlite3 *, const char *);
+       char *query = NULL;
+
+       query = sqlite3_mprintf("INSERT INTO files(path) VALUES(%Q);", path);
+       sqlite3_exec(db_handle, query, NULL, NULL, NULL);
+       sqlite3_free(query);
+
+       handle = dlopen(PATH_PLUGIN_LIB, RTLD_LAZY);
+       if (!handle) {
+               media_svc_error("dlopen failed");
+               return;
+       }
+
+       if (g_str_has_suffix(path, "epub") || g_str_has_suffix(path, "EPUB"))
+               svc_update = dlsym(handle, "media_svc_epub_insert_to_db");
        else
-               media_svc_error("__media_svc_get_mime_type failed");
+               svc_update = dlsym(handle, "media_svc_pdf_insert_to_db");
 
-       *mediatype = media_type;
+       if (!svc_update) {
+               media_svc_error("dlsym failed - %s", dlerror());
+               dlclose(handle);
+               return;
+       }
 
-       return ret;
+       svc_update(db_handle, path);
+       dlclose(handle);
+}
+
+void _media_svc_update_wordbook(const char *path, uid_t uid)
+{
+       sqlite3 *db_handle = NULL;
+
+       if (!path) {
+               media_svc_error("Invalid path");
+               return;
+       }
+
+       // check db..
+       if (!__media_svc_get_wordbook_handle(uid, &db_handle))
+               return;
+
+       if (__media_svc_is_exist_in_wordbook(db_handle, path)) {
+               sqlite3_close_v2(db_handle);
+               return;
+       }
+
+       // if no item, insert to db..
+       __media_svc_insert_to_wordbook(db_handle, path);
+       sqlite3_close_v2(db_handle);
 }
 
-bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
+void _media_svc_clean_wordbook(uid_t uid)
 {
-       if ((storage_type != MS_USER_STORAGE_INTERNAL)
-               && (storage_type != MS_USER_STORAGE_EXTERNAL)
-               && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
-               media_svc_error("storage type is incorrect[%d]", storage_type);
+       sqlite3 *db_handle = NULL;
+
+       if (!__media_svc_get_wordbook_handle(uid, &db_handle))
+               return;
+
+       sqlite3_exec(db_handle, "DELETE FROM files where validity = 0;", NULL, NULL, NULL);
+       sqlite3_exec(db_handle, "UPDATE files SET validity = 0;", NULL, NULL, NULL);
+       sqlite3_close_v2(db_handle);
+}
+
+bool _media_svc_get_matched_list(const char *keyword, uid_t uid, GList **list)
+{
+       int ret = SQLITE_OK;
+       sqlite3 *handle = NULL;
+       sqlite3_stmt *stmt = NULL;
+       char *query = NULL;
+
+       media_svc_retvm_if(!list, false, "list is NULL");
+       media_svc_retvm_if(!keyword, false, "keyword is NULL");
+       media_svc_retvm_if(!__media_svc_get_wordbook_handle(uid, &handle), false, "Failed to get handle");
+
+       query = sqlite3_mprintf("SELECT files.path FROM files JOIN (SELECT file_id, sum(frequency) AS freq_sum FROM words WHERE word LIKE '%q%%' GROUP BY file_id ORDER BY freq_sum DESC) w ON files.id = w.file_id;", keyword);
+       ret = sqlite3_prepare_v2(handle, query, -1, &stmt, NULL);
+       SQLITE3_SAFE_FREE(query);
+
+       if (ret != SQLITE_OK) {
+               media_svc_error("Query failed[%d]", ret);
+               sqlite3_close_v2(handle);
                return false;
        }
 
+       while (sqlite3_step(stmt) == SQLITE_ROW)
+               *list = g_list_append(*list, g_strdup((char *)sqlite3_column_text(stmt, 0)));
+
+       sqlite3_finalize(stmt);
+       sqlite3_close_v2(handle);
+
        return true;
 }