[ACR-1618] Add API to get media handle by path
[platform/core/api/media-content.git] / src / media_info.c
index 6d8ba72..94d5342 100644 (file)
@@ -1303,6 +1303,43 @@ int media_info_get_media_from_db(const char *media_id, media_info_h *media)
        return ret;
 }
 
+int media_info_get_media_from_db_by_path(const char *path, media_info_h *media)
+{
+       int ret = MEDIA_CONTENT_ERROR_NONE;
+       media_info_s *_media = NULL;
+
+       content_retip_if_fail(STRING_VALID(path));
+       content_retip_if_fail(media);
+       ret = _media_util_check_file_exist(path);
+       content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_util_check_file_exist failed : %d", ret);
+
+#ifdef _USE_TVPD_MODE
+       char storage_id[MEDIA_CONTENT_UUID_SIZE + 1] = {0, };
+
+       ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
+       if (ret != MS_MEDIA_ERR_NONE) {
+               content_error("media_svc_get_storage_id failed : %d", ret);
+               return _content_error_capi(ret);
+       }
+#endif
+
+       _media = g_new0(media_info_s, 1);
+
+#ifdef _USE_TVPD_MODE
+       ret = _media_info_get_media_info_from_db(path, STRING_VALID(storage_id) ? storage_id : DB_TABLE_MEDIA, (media_info_h)_media);
+#else
+       ret = _media_info_get_media_info_from_db(path, (media_info_h)_media);
+#endif
+       if (ret != MEDIA_CONTENT_ERROR_NONE) {
+               g_free(_media);
+               _media = NULL;
+       }
+
+       *media = (media_info_h)_media;
+
+       return ret;
+}
+
 int media_info_set_favorite(media_info_h media, bool favorite)
 {
        media_info_s *_media = (media_info_s*)media;
@@ -1380,6 +1417,9 @@ int media_info_move_to_db(media_info_h media, const char* dst_path)
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char repl_path[MAX_PATH_LEN] = {0, };
        media_info_s *_info = NULL;
+#ifdef _USE_TVPD_MODE
+       char storage_id[MEDIA_CONTENT_UUID_SIZE + 1] = {0, };
+#endif
 
        content_retip_if_fail(media);
        content_retip_if_fail(STRING_VALID(dst_path));
@@ -1410,7 +1450,14 @@ int media_info_move_to_db(media_info_h media, const char* dst_path)
        /* Update media_info handle */
        _info = g_new0(media_info_s, 1);
 
+#ifdef _USE_TVPD_MODE
+       ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
+       content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+       ret = _media_info_get_media_info_from_db(repl_path, storage_id, (media_info_h)_info);
+#else
        ret = _media_info_get_media_info_from_db(repl_path, (media_info_h)_info);
+#endif
 
        SAFE_FREE(_media->display_name);
        _media->display_name = g_strdup(_info->display_name);