Modify _media_svc_extract_book_metadata() 68/307468/2
authorminje.ahn <minje.ahn@samsung.com>
Mon, 11 Mar 2024 00:31:04 +0000 (09:31 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Mon, 11 Mar 2024 02:11:41 +0000 (11:11 +0900)
Change to extract title inside of function.

Change-Id: Ic0c276dfa73a78d8161f978715407119d0492174
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
src/common/media-svc-util.c
src/common/media-svc.c

index bed0fc3..c9e9b2d 100644 (file)
@@ -466,7 +466,6 @@ static char * __media_svc_get_title(MMHandleType tag, const char *filename)
 
 char * _media_svc_get_title_from_filename(const char *filename)
 {
-       /* No MMHandleType in media-svc.c */
        return __media_svc_get_title_from_filename(filename);
 }
 
@@ -898,6 +897,7 @@ static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_
        }
 
        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;
@@ -1024,12 +1024,22 @@ static int __media_svc_get_pdf_metadata(media_svc_content_info_s *content_info)
 
 int _media_svc_extract_book_metadata(media_svc_content_info_s *content_info)
 {
+       int ret = MS_MEDIA_ERR_NONE;
+
        media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "content info is NULL");
 
        if (g_str_has_suffix(content_info->mime_type, "epub+zip"))
-               return __media_svc_get_epub_metadata(content_info);
+               ret = __media_svc_get_epub_metadata(content_info);
        else
-               return __media_svc_get_pdf_metadata(content_info);
+               ret = __media_svc_get_pdf_metadata(content_info);
+
+       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 MS_MEDIA_ERR_NONE;
 }
 
 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
index 432f2b2..fffe105 100755 (executable)
@@ -214,11 +214,6 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, const ch
                break;
        case MEDIA_SVC_MEDIA_TYPE_BOOK:
                ret = _media_svc_extract_book_metadata(&content_info);
-               /* The 'TITLE' should always be filled in */
-               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);
-               }
                break;
        default:
                /* The 'TITLE' should always be filled in */
@@ -287,11 +282,6 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, c
                break;
        case MEDIA_SVC_MEDIA_TYPE_BOOK:
                ret = _media_svc_extract_book_metadata(&content_info);
-               /* The 'TITLE' should always be filled in */
-               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);
-               }
                break;
        default:
                /* The 'TITLE' should always be filled in */
@@ -500,11 +490,6 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
                break;
        case MEDIA_SVC_MEDIA_TYPE_BOOK:
                ret = _media_svc_extract_book_metadata(&content_info);
-               /* The 'TITLE' should always be filled in */
-               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);
-               }
                break;
        default:
                /* The 'TITLE' should always be filled in */