summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-10-01 16:38:49 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-10-05 20:13:15 -0700
commit47593c4e5a71a95fb5ee9824e7bef8bf31d4f41f (patch)
tree6e3f3954b8aa8ed2ac9b3fe1c3973b4bd2ba9c4f
parentaa7bfb7a49ef4e2b9e7334330650c9550eb3892a (diff)
binding: mediascanner: add media metadata to JSON output
Add metadata of the tracks artist, title, album and genre to the JSON output for media results. Bug-AGL: SPEC-924 Change-Id: I240481b3b36909cb2de6ff7ba5c0a168d7973dc2 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
-rw-r--r--binding/media-api.c34
-rw-r--r--binding/media-manager.c27
-rw-r--r--binding/media-manager.h21
3 files changed, 76 insertions, 6 deletions
diff --git a/binding/media-api.c b/binding/media-api.c
index 8f7503d..4a5b5f6 100644
--- a/binding/media-api.c
+++ b/binding/media-api.c
@@ -82,8 +82,38 @@ static json_object *new_json_object_from_device(GList *list)
for (l = list; l; l = l->next)
{
- jstring = json_object_new_string(l->data);
- json_object_array_add(jarray, jstring);
+ struct Media_Item *item = l->data;
+ json_object *jdict = json_object_new_object();
+
+ jstring = json_object_new_string(item->path);
+ json_object_object_add(jdict, "path", jstring);
+
+ if (item->metadata.title) {
+ jstring = json_object_new_string(item->metadata.title);
+ json_object_object_add(jdict, "title", jstring);
+ }
+
+ if (item->metadata.artist) {
+ jstring = json_object_new_string(item->metadata.artist);
+ json_object_object_add(jdict, "artist", jstring);
+ }
+
+ if (item->metadata.album) {
+ jstring = json_object_new_string(item->metadata.album);
+ json_object_object_add(jdict, "album", jstring);
+ }
+
+ if (item->metadata.genre) {
+ jstring = json_object_new_string(item->metadata.genre);
+ json_object_object_add(jdict, "genre", jstring);
+ }
+
+ if (item->metadata.duration) {
+ json_object *jint = json_object_new_int(item->metadata.duration);
+ json_object_object_add(jdict, "duration", jint);
+ }
+
+ json_object_array_add(jarray, jdict);
}
if (jstring == NULL)
diff --git a/binding/media-manager.c b/binding/media-manager.c
index 342df47..d451b3d 100644
--- a/binding/media-manager.c
+++ b/binding/media-manager.c
@@ -98,7 +98,9 @@ GList* media_local_scan(GList *list)
while ((tmp = (gchar *) g_dir_read_name(dir)) != NULL)
{
- list = g_list_append(list, g_strdup_printf("file://%s/%s", path, tmp));
+ struct Media_Item *item = g_malloc0(sizeof(*item));
+ item->path = g_strdup_printf("file://%s", path);
+ list = g_list_append(list, item);
}
g_free(path);
@@ -132,18 +134,37 @@ GList* media_lightmediascanner_scan(void)
while (sqlite3_step(res) == SQLITE_ROW) {
struct stat buf;
+ struct Media_Item *item;
const char *path = (const char *) sqlite3_column_text(res, 0);
ret = stat(path, &buf);
if (ret)
continue;
- list = g_list_append(list, g_strdup_printf("file://%s", path));
+ item = g_malloc0(sizeof(*item));
+ item->path = g_strdup_printf("file://%s", path);
+ item->metadata.title = g_strdup((gchar *) sqlite3_column_text(res, 1));
+ item->metadata.artist = g_strdup((gchar *) sqlite3_column_text(res, 2));
+ item->metadata.album = g_strdup((gchar *) sqlite3_column_text(res, 3));
+ item->metadata.genre = g_strdup((gchar *) sqlite3_column_text(res, 4));
+ item->metadata.duration = sqlite3_column_int(res, 5) * 1000;
+ list = g_list_append(list, item);
}
return list;
}
+static void free_media_item(void *data)
+{
+ struct Media_Item *item = data;
+
+ g_free(item->metadata.title);
+ g_free(item->metadata.artist);
+ g_free(item->metadata.album);
+ g_free(item->metadata.genre);
+ g_free(item->path);
+ g_free(item);
+}
static void
on_interface_proxy_properties_changed (GDBusProxy *proxy,
@@ -183,7 +204,7 @@ on_interface_proxy_properties_changed (GDBusProxy *proxy,
if (list != NULL && g_RegisterCallback.binding_device_added)
g_RegisterCallback.binding_device_added(list);
- g_list_free_full(list, g_free);
+ g_list_free_full(list, free_media_item);
ListUnlock();
}
diff --git a/binding/media-manager.h b/binding/media-manager.h
index 34d87e1..f1f177e 100644
--- a/binding/media-manager.h
+++ b/binding/media-manager.h
@@ -74,7 +74,15 @@ void DebugTraceSendMsg(int level, gchar* message);
#define FREEDESKTOP_PROPERTIES "org.freedesktop.DBus.Properties"
//sqlite
-#define SQL_QUERY "SELECT files.path FROM files LEFT JOIN audios " \
+#define SQL_QUERY "SELECT files.path, audios.title, audio_artists.name, " \
+ "audio_albums.name, audio_genres.name, audios.length " \
+ "FROM files LEFT JOIN audios " \
+ "LEFT JOIN audio_artists " \
+ "ON audio_artists.id = audios.artist_id " \
+ "LEFT JOIN audio_albums " \
+ "ON audio_albums.id = audios.album_id " \
+ "LEFT JOIN audio_genres " \
+ "ON audio_genres.id = audios.genre_id " \
"WHERE audios.id = files.id ORDER BY " \
"audios.artist_id, audios.album_id, audios.trackno"
@@ -100,4 +108,15 @@ void ListUnlock();
GList* media_lightmediascanner_scan(void);
GList* media_local_scan(GList *list);
+struct Media_Item {
+ gchar *path;
+ struct {
+ gchar *title;
+ gchar *artist;
+ gchar *album;
+ gchar *genre;
+ gint duration;
+ } metadata;
+};
+
#endif