[grilo] core: merge GrlMediaAudio into GrlMedia



commit 53e9029b3bf7fb65123f060d1782aca698827920
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Tue Dec 15 17:35:06 2015 +0100

    core: merge GrlMediaAudio into GrlMedia
    
    Get rid of GrlMediaAudio and use instead GrlMedia.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755551

 bindings/vala/grilo-0.3.vapi |   77 +++---
 libs/pls/grl-pls.c           |    9 +-
 src/Makefile.am              |    2 -
 src/data/grl-media-audio.c   |  680 ------------------------------------------
 src/data/grl-media-audio.h   |  158 ----------
 src/data/grl-media.c         |  524 +++++++++++++++++++++++++++++++-
 src/data/grl-media.h         |   71 ++++-
 src/grilo.c                  |    1 -
 src/grilo.h                  |    1 -
 tools/grilo-test-ui/main.c   |    4 +-
 10 files changed, 619 insertions(+), 908 deletions(-)
---
diff --git a/bindings/vala/grilo-0.3.vapi b/bindings/vala/grilo-0.3.vapi
index 6c9f012..2b1939d 100644
--- a/bindings/vala/grilo-0.3.vapi
+++ b/bindings/vala/grilo-0.3.vapi
@@ -102,16 +102,26 @@ namespace Grl {
        public class Media : Grl.Data {
                [CCode (has_construct_function = false)]
                public Media ();
+               public void add_artist (string artist);
                public void add_author (string author);
                public void add_external_player (string player);
                public void add_external_url (string url);
+               public void add_genre (string genre);
                public void add_keyword (string keyword);
+               public void add_lyrics (string lyrics);
+               public void add_mb_artist_id (string mb_artist_id);
                public void add_region_data (string region, GLib.DateTime publication_date, string 
certificate);
                public void add_thumbnail (string thumbnail);
                public void add_thumbnail_binary (uint8 thumbnail, size_t size);
-               public void add_url_data (string url, string mime);
+               public void add_url_data (string url, string mime, int bitrate);
+               [CCode (cname = "grl_media_audio_new", has_construct_function = false)]
+               public Media.audio_new ();
+               public unowned string get_album ();
+               public unowned string get_artist ();
+               public unowned string get_artist_nth (uint index);
                public unowned string get_author ();
                public unowned string get_author_nth (uint index);
+               public int get_bitrate ();
                public unowned string get_certificate ();
                public unowned GLib.DateTime get_creation_date ();
                public unowned string get_description ();
@@ -119,12 +129,22 @@ namespace Grl {
                public unowned string get_external_url ();
                public unowned string get_external_url_nth (uint index);
                public bool get_favourite ();
+               public unowned string get_genre ();
+               public unowned string get_genre_nth (uint index);
                public unowned string get_id ();
                public unowned string get_keyword ();
                public unowned string get_keyword_nth (uint index);
                public GLib.DateTime get_last_played ();
                public int get_last_position ();
                public unowned string get_license ();
+               public unowned string get_lyrics ();
+               public unowned string get_lyrics_nth (uint index);
+               public unowned string get_mb_album_id ();
+               public unowned string get_mb_artist_id ();
+               public unowned string get_mb_artist_id_nth (uint index);
+               public unowned string get_mb_recording_id ();
+               public unowned string get_mb_track_id ();
+               public Grl.MediaType get_media_type ();
                public unowned string get_mime ();
                public unowned GLib.DateTime get_modification_date ();
                public int get_play_count ();
@@ -145,11 +165,16 @@ namespace Grl {
                public uint8 get_thumbnail_binary_nth (size_t size, uint index);
                public unowned string get_thumbnail_nth (uint index);
                public unowned string get_title ();
+               public int get_track_number ();
                public unowned string get_url ();
-               public unowned string get_url_data (out unowned string mime);
-               public unowned string get_url_data_nth (uint index, out unowned string mime);
+               public unowned string get_url_data (out unowned string mime, out int bitrate);
+               public unowned string get_url_data_nth (uint index, out unowned string mime, out int bitrate);
+               public bool is_audio ();
                public string serialize ();
+               public void set_album (string album);
+               public void set_artist (string artist);
                public void set_author (string author);
+               public void set_bitrate (int bitrate);
                public void set_certificate (string certificate);
                public void set_creation_date (GLib.DateTime creation_date);
                public void set_description (string description);
@@ -157,11 +182,17 @@ namespace Grl {
                public void set_external_player (string player);
                public void set_external_url (string url);
                public void set_favourite (bool favourite);
+               public void set_genre (string genre);
                public void set_id (string id);
                public void set_keyword (string keyword);
                public void set_last_played (GLib.DateTime last_played);
                public void set_last_position (int last_position);
                public void set_license (string license);
+               public void set_lyrics (string lyrics);
+               public void set_mb_album_id (string mb_album_id);
+               public void set_mb_artist_id (string mb_artist_id);
+               public void set_mb_recording_id (string mb_recording_id);
+               public void set_mb_track_id (string mb_track_id);
                public void set_mime (string mime);
                public void set_modification_date (GLib.DateTime modification_date);
                public void set_play_count (int play_count);
@@ -176,49 +207,13 @@ namespace Grl {
                public void set_thumbnail (string thumbnail);
                public void set_thumbnail_binary (uint8 thumbnail, size_t size);
                public void set_title (string title);
+               public void set_track_number (int track_number);
                public void set_url (string url);
-               public void set_url_data (string url, string mime);
+               public void set_url_data (string url, string mime, int bitrate);
                public static Grl.Media unserialize (string serial);
                [NoAccessorMethod]
                public Grl.MediaType media_type { get; set construct; }
        }
-       [CCode (cheader_filename = "grilo.h", type_id = "grl_media_audio_get_type ()")]
-       public class MediaAudio : Grl.Media {
-               [CCode (has_construct_function = false, type = "GrlMedia*")]
-               public MediaAudio ();
-               public void add_artist (string artist);
-               public void add_genre (string genre);
-               public void add_lyrics (string lyrics);
-               public void add_mb_artist_id (string mb_artist_id);
-               public void add_url_data (string url, string mime, int bitrate);
-               public unowned string get_album ();
-               public unowned string get_artist ();
-               public unowned string get_artist_nth (uint index);
-               public int get_bitrate ();
-               public unowned string get_genre ();
-               public unowned string get_genre_nth (uint index);
-               public unowned string get_lyrics ();
-               public unowned string get_lyrics_nth (uint index);
-               public unowned string get_mb_album_id ();
-               public unowned string get_mb_artist_id ();
-               public unowned string get_mb_artist_id_nth (uint index);
-               public unowned string get_mb_recording_id ();
-               public unowned string get_mb_track_id ();
-               public int get_track_number ();
-               public unowned string get_url_data (out unowned string mime, out int bitrate);
-               public unowned string get_url_data_nth (uint index, out unowned string mime, out int bitrate);
-               public void set_album (string album);
-               public void set_artist (string artist);
-               public void set_bitrate (int bitrate);
-               public void set_genre (string genre);
-               public void set_lyrics (string lyrics);
-               public void set_mb_album_id (string mb_album_id);
-               public void set_mb_artist_id (string mb_artist_id);
-               public void set_mb_recording_id (string mb_recording_id);
-               public void set_mb_track_id (string mb_track_id);
-               public void set_track_number (int track_number);
-               public void set_url_data (string url, string mime, int bitrate);
-       }
        [CCode (cheader_filename = "grilo.h", type_id = "grl_media_box_get_type ()")]
        public class MediaBox : Grl.Media {
                [CCode (has_construct_function = false, type = "GrlMedia*")]
diff --git a/libs/pls/grl-pls.c b/libs/pls/grl-pls.c
index bf395a3..c5aba90 100644
--- a/libs/pls/grl-pls.c
+++ b/libs/pls/grl-pls.c
@@ -559,11 +559,10 @@ grl_media_new_from_pls_entry (const gchar *uri,
   if (audio_track)
     grl_data_set_int (GRL_DATA (media), GRL_METADATA_KEY_AUDIO_TRACK, atoi (audio_track));
 
-  if (GRL_IS_MEDIA_AUDIO(media)) {
-    GrlMediaAudio *audio = GRL_MEDIA_AUDIO(media);
-    grl_media_audio_set_album (audio, g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_ALBUM));
-    grl_media_audio_set_artist (audio, g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_AUTHOR));
-    grl_media_audio_set_genre (audio, g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_GENRE));
+  if (grl_media_is_audio (media)) {
+    grl_media_set_album (media, g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_ALBUM));
+    grl_media_set_artist (media, g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_AUTHOR));
+    grl_media_set_genre (media, g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_GENRE));
   }
 
   return media;
diff --git a/src/Makefile.am b/src/Makefile.am
index c9d5e72..9c6b792 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,7 +72,6 @@ data_c_sources =              \
        data/grl-data.c         \
        data/grl-related-keys.c \
        data/grl-media.c        \
-       data/grl-media-audio.c  \
        data/grl-media-video.c  \
         data/grl-media-image.c \
        data/grl-media-box.c    \
@@ -105,7 +104,6 @@ data_h_headers =            \
        data/grl-related-keys.h \
        data/grl-media.h        \
        data/grl-media-box.h    \
-       data/grl-media-audio.h  \
        data/grl-media-video.h  \
        data/grl-media-image.h  \
        data/grl-config.h
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index ed37ea7..51dfc85 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -149,15 +149,38 @@ grl_media_finalize (GObject *object)
  * Creates a new data media object.
  *
  * Returns: a newly-allocated data media.
- *
- * Since: 0.1.4
  **/
 GrlMedia *
 grl_media_new (void)
 {
   return g_object_new (GRL_TYPE_MEDIA,
                        "media-type", GRL_MEDIA_TYPE_UNKNOWN,
-                      NULL);
+                       NULL);
+}
+
+/**
+ * grl_media_audio_new:
+ *
+ * Creates a new media audio object.
+ *
+ * Returns: a newly-allocated media audio.
+ *
+ * Since: 0.1.4
+ **/
+GrlMedia *
+grl_media_audio_new (void)
+{
+  return g_object_new (GRL_TYPE_MEDIA,
+                       "media-type", GRL_MEDIA_TYPE_AUDIO,
+                       NULL);
+}
+
+gboolean
+grl_media_is_audio (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
+
+  return (media->priv->media_type == GRL_MEDIA_TYPE_AUDIO);
 }
 
 /**
@@ -189,13 +212,15 @@ grl_media_set_rating (GrlMedia *media, gfloat rating, gfloat max)
  * @media: a #GrlMedia
  * @url: the media's URL
  * @mime: the @url mime type
+ * @bitrate: the @url bitrate, or -1 to ignore
  *
- * Set the media's URL and its mime-type.
- *
- * Since: 0.1.10
+ * Set the media's URL and its mime-type and bitrate.
  **/
 void
-grl_media_set_url_data (GrlMedia *media, const gchar *url, const gchar *mime)
+grl_media_set_url_data (GrlMedia *media,
+                        const gchar *url,
+                        const gchar *mime,
+                        gint bitrate)
 {
   GrlRelatedKeys *relkeys;
 
@@ -204,6 +229,9 @@ grl_media_set_url_data (GrlMedia *media, const gchar *url, const gchar *mime)
   relkeys = grl_related_keys_new ();
   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_URL, url);
   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_MIME, mime);
+  if (bitrate >= 0) {
+    grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_BITRATE, bitrate);
+  }
   grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
 }
 
@@ -212,13 +240,15 @@ grl_media_set_url_data (GrlMedia *media, const gchar *url, const gchar *mime)
  * @media: a #GrlMedia
  * @url: a media's URL
  * @mime: th @url mime type
+ * @bitrate: the @url bitrate, or -1 to ignore
  *
- * Adds a new media's URL with its mime-type.
- *
- * Since: 0.1.10
+ * Adds a new media's URL with its mime-type and bitrate.
  **/
 void
-grl_media_add_url_data (GrlMedia *media, const gchar *url, const gchar *mime)
+grl_media_add_url_data (GrlMedia *media,
+                        const gchar *url,
+                        const gchar *mime,
+                        gint bitrate)
 {
   GrlRelatedKeys *relkeys;
 
@@ -227,6 +257,9 @@ grl_media_add_url_data (GrlMedia *media, const gchar *url, const gchar *mime)
   relkeys = grl_related_keys_new ();
   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_URL, url);
   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_MIME, mime);
+  if (bitrate >= 0) {
+    grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_BITRATE, bitrate);
+  }
   grl_data_add_related_keys (GRL_DATA (media), relkeys);
 }
 
@@ -347,6 +380,64 @@ grl_media_add_keyword (GrlMedia *media,
 }
 
 /**
+ * grl_media_add_artist:
+ * @media: the media instance
+ * @artist: an audio's artist
+ *
+ * Adds a new artist to @media.
+ **/
+void
+grl_media_add_artist (GrlMedia *media, const gchar *artist)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST, artist);
+}
+
+/**
+ * grl_media_add_genre:
+ * @media: the media instance
+ * @genre: an audio's genre
+ *
+ * Adds a new genre to @media.
+ **/
+void
+grl_media_add_genre (GrlMedia *media, const gchar *genre)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE, genre);
+}
+
+/**
+ * grl_media_add_lyrics:
+ * @media: the media instance
+ * @lyrics: an audio's lyrics
+ *
+ * Adds a new lyrics to @media.
+ **/
+void
+grl_media_add_lyrics (GrlMedia *media, const gchar *lyrics)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_LYRICS, lyrics);
+}
+
+/**
+ * grl_media_add_mb_artist_id:
+ * @media: the media instance
+ * @mb_artist_id: a MusicBrainz artist identifier
+ *
+ * Adds a new MusicBrainz artist id to @media.
+ **/
+void
+grl_media_add_mb_artist_id (GrlMedia *media,
+                            const gchar *mb_artist_id)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ARTIST_ID,
+                       mb_artist_id);
+}
+
+/**
  * grl_media_serialize:
  * @media: a #GrlMedia
  *
@@ -1296,6 +1387,159 @@ grl_media_set_size (GrlMedia *media, gint64 size)
 }
 
 /**
+ * grl_media_set_track_number:
+ * @media: the media instance
+ * @track_number: the audio's track number
+ *
+ * Set the track number of the media
+ */
+void
+grl_media_set_track_number (GrlMedia *media, gint track_number)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_int (GRL_DATA (media), GRL_METADATA_KEY_TRACK_NUMBER,
+                    track_number);
+}
+
+/**
+ * grl_media_set_bitrate:
+ * @media: the media instance
+ * @bitrate: the audio's bitrate
+ *
+ * Set the bitrate of the media
+ */
+void
+grl_media_set_bitrate (GrlMedia *media, gint bitrate)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_int (GRL_DATA (media), GRL_METADATA_KEY_BITRATE,
+                    bitrate);
+}
+
+/**
+ * grl_media_set_mb_track_id:
+ * @media: the media instance
+ * @mb_track_id: the MusicBrainz track identifier
+ *
+ * Set the MusicBrainz track identifier of the media
+ */
+void
+grl_media_set_mb_track_id (GrlMedia *media, const gchar *mb_track_id)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_TRACK_ID,
+                       mb_track_id);
+}
+
+/**
+ * grl_media_set_mb_recording_id:
+ * @media: the media instance
+ * @mb_recording_id: the MusicBrainz recording identifier
+ *
+ * Set the MusicBrainz recording identifier of the media
+ */
+void
+grl_media_set_mb_recording_id (GrlMedia *media,
+                               const gchar *mb_recording_id)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RECORDING_ID,
+                       mb_recording_id);
+}
+
+/**
+ * grl_media_set_mb_artist_id:
+ * @media: the media instance
+ * @mb_artist_id: the MusicBrainz artist identifier
+ *
+ * Set the MusicBrainz artist identifier of the media
+ */
+void
+grl_media_set_mb_artist_id (GrlMedia *media, const gchar *mb_artist_id)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ARTIST_ID,
+                       mb_artist_id);
+}
+
+/**
+ * grl_media_set_mb_album_id:
+ * @media: the media instance
+ * @mb_album_id: the MusicBrainz album identifier
+ *
+ * Set the MusicBrainz album identifier of the media
+ */
+void
+grl_media_set_mb_album_id (GrlMedia *media, const gchar *mb_album_id)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ALBUM_ID,
+                       mb_album_id);
+}
+
+/**
+ * grl_media_set_lyrics:
+ * @media: the media instance
+ * @lyrics: the audio's lyrics
+ *
+ * Set the lyrics of the media
+ */
+void
+grl_media_set_lyrics (GrlMedia *media, const gchar *lyrics)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_LYRICS,
+                       lyrics);
+}
+
+/**
+ * grl_media_set_genre:
+ * @media: the media instance
+ * @genre: the audio's genre
+ *
+ * Set the genre of the media
+ */
+void
+grl_media_set_genre (GrlMedia *media, const gchar *genre)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE,
+                       genre);
+}
+
+/**
+ * grl_media_set_album:
+ * @media: the media instance
+ * @album: the audio's album
+ *
+ * Set the album of the media
+ */
+void
+grl_media_set_album (GrlMedia *media, const gchar *album)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM,
+                       album);
+}
+
+/**
+ * grl_media_set_artist:
+ * @media: the media instance
+ * @artist: the audio's artist
+ *
+ * Set the artist of the media
+ *
+ * Since: 0.1.4
+ */
+void
+grl_media_set_artist (GrlMedia *media, const gchar *artist)
+{
+  g_return_if_fail (GRL_IS_MEDIA (media));
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST,
+                       artist);
+}
+
+/**
  * grl_media_get_id:
  * @media: the media object
  *
@@ -1331,17 +1575,20 @@ grl_media_get_url (GrlMedia *media)
  * grl_media_get_url_data:
  * @media: the media object
  * @mime: (out) (transfer none): the mime-type, or %NULL to ignore.
+ * @bitrate: (out): the url bitrate, or %NULL to ignore
  *
  * Returns: the media's URL and its mime-type.
  *
  * Since: 0.1.10
  */
 const gchar *
-grl_media_get_url_data (GrlMedia *media, gchar **mime)
+grl_media_get_url_data (GrlMedia *media,
+                        gchar **mime,
+                        gint *bitrate)
 {
   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
 
-  return grl_media_get_url_data_nth (media, 0, mime);
+  return grl_media_get_url_data_nth (media, 0, mime, bitrate);
 }
 
 /**
@@ -1349,13 +1596,17 @@ grl_media_get_url_data (GrlMedia *media, gchar **mime)
  * @media: the media object
  * @index: element to retrieve
  * @mime: (out) (transfer none): the mime-type, or %NULL to ignore.
+ * @bitrate: (out): the url bitrate, or %NULL to ignore
  *
  * Returns: the n-th media's URL and its mime-type.
  *
  * Since: 0.1.10
  */
 const gchar *
-grl_media_get_url_data_nth (GrlMedia *media, guint index, gchar **mime)
+grl_media_get_url_data_nth (GrlMedia *media,
+                            guint index,
+                            gchar **mime,
+                            gint *bitrate)
 {
   GrlRelatedKeys *relkeys;
 
@@ -1372,6 +1623,10 @@ grl_media_get_url_data_nth (GrlMedia *media, guint index, gchar **mime)
                                                    GRL_METADATA_KEY_MIME);
   }
 
+  if (bitrate) {
+    *bitrate = grl_related_keys_get_int (relkeys, GRL_METADATA_KEY_BITRATE);
+  }
+
   return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_URL);
 }
 
@@ -2070,3 +2325,244 @@ grl_media_get_size (GrlMedia *media)
   g_return_val_if_fail (GRL_IS_MEDIA (media), -1);
   return grl_data_get_int64 (GRL_DATA (media), GRL_METADATA_KEY_SIZE);
 }
+
+/**
+ * grl_media_get_track_number:
+ * @media: the media instance
+ *
+ * Returns: the track number of the media
+ */
+gint
+grl_media_get_track_number (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), -1);
+  return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_TRACK_NUMBER);
+}
+
+/**
+ * grl_media_get_bitrate:
+ * @media: the media instance
+ *
+ * Returns: the bitrate of the media
+ */
+gint
+grl_media_get_bitrate (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), -1);
+  return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_BITRATE);
+}
+
+/**
+ * grl_media_get_mb_album_id:
+ * @media: the media instance
+ *
+ * Returns: the MusicBrainz album identifier
+ */
+const gchar *
+grl_media_get_mb_album_id (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ALBUM_ID);
+}
+
+/**
+ * grl_media_get_mb_artist_id:
+ * @media: the media instance
+ *
+ * Returns: the MusicBrainz artist identifier
+ */
+const gchar *
+grl_media_get_mb_artist_id (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ARTIST_ID);
+}
+
+/**
+ * grl_media_get_mb_artist_id_nth:
+ * @media: the media instance
+ * @index: element to retrieve, starting at 0
+ *
+ * Returns: the n-th MusicBrainz artist identifier of the media
+ */
+const gchar *
+grl_media_get_mb_artist_id_nth (GrlMedia *media, guint index)
+{
+  GrlRelatedKeys *relkeys;
+
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+
+  relkeys =
+    grl_data_get_related_keys (GRL_DATA (media),
+                               GRL_METADATA_KEY_MB_ARTIST_ID,
+                               index);
+
+  if (!relkeys) {
+    return NULL;
+  } else {
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_MB_ARTIST_ID);
+  }
+}
+
+/**
+ * grl_media_get_mb_recording_id:
+ * @media: the media instance
+ *
+ * Returns: the MusicBrainz recording identifier
+ */
+const gchar *
+grl_media_get_mb_recording_id (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RECORDING_ID);
+}
+
+/**
+ * grl_media_get_mb_track_id:
+ * @media: the media instance
+ *
+ * Returns: the MusicBrainz track identifier
+ * Since: 0.2.12
+ */
+const gchar *
+grl_media_get_mb_track_id (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_TRACK_ID);
+}
+
+/**
+ * grl_media_get_lyrics:
+ * @media: the media instance
+ *
+ * Returns: the lyrics of the media
+ */
+const gchar *
+grl_media_get_lyrics (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_LYRICS);
+}
+
+/**
+ * grl_media_get_lyrics_nth:
+ * @media: the media instance
+ * @index: element to retrieve, starting at 0
+ *
+ * Returns: the n-th lyrics of the media
+ */
+const gchar *
+grl_media_get_lyrics_nth (GrlMedia *media, guint index)
+{
+  GrlRelatedKeys *relkeys;
+
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+
+  relkeys =
+    grl_data_get_related_keys (GRL_DATA (media),
+                               GRL_METADATA_KEY_LYRICS,
+                               index);
+
+  if (!relkeys) {
+    return NULL;
+  } else {
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_LYRICS);
+  }
+}
+
+/**
+ * grl_media_get_genre:
+ * @media: the media instance
+ *
+ * Returns: the genre of the media
+ */
+const gchar *
+grl_media_get_genre (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE);
+}
+
+/**
+ * grl_media_get_genre_nth:
+ * @media: the media instance
+ * @index: element to retrieve, starting at 0
+ *
+ * Returns: the n-th genre of the media
+ */
+const gchar *
+grl_media_get_genre_nth (GrlMedia *media, guint index)
+{
+  GrlRelatedKeys *relkeys;
+
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+
+  relkeys =
+    grl_data_get_related_keys (GRL_DATA (media), GRL_METADATA_KEY_GENRE, index);
+
+  if (!relkeys) {
+    return NULL;
+  } else {
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_GENRE);
+  }
+}
+
+/**
+ * grl_media_get_album:
+ * @media: the media instance
+ *
+ * Returns: the album of the media
+ */
+const gchar *
+grl_media_get_album (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM);
+}
+
+/**
+ * grl_media_get_artist:
+ * @media: the media instance
+ *
+ * Returns: the artist of the media
+ */
+const gchar *
+grl_media_get_artist (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_MEDIA (media), NULL);
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST);
+}
+
+/**
+ * grl_media_get_artist_nth:
+ * @media: the media instance
+ * @index: element to retrieve, starting at 0
+ *
+ * Returns: the n-th artist of the media
+ */
+const gchar *
+grl_media_get_artist_nth (GrlMedia *media, guint index)
+{
+  GrlRelatedKeys *relkeys;
+
+  g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
+
+  relkeys =
+    grl_data_get_related_keys (GRL_DATA (media),
+                               GRL_METADATA_KEY_ARTIST,
+                               index);
+
+  if (!relkeys) {
+    return NULL;
+  } else {
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_ARTIST);
+  }
+}
+
+GrlMediaType
+grl_media_get_media_type (GrlMedia *media)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA (media), GRL_MEDIA_TYPE_UNKNOWN);
+
+  return media->priv->media_type;
+}
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 7cc4efd..af1d311 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -165,7 +165,7 @@ void grl_media_set_license (GrlMedia *media, const gchar *license);
 
 void grl_media_set_rating (GrlMedia *media, gfloat rating, gfloat max);
 
-void grl_media_set_url_data (GrlMedia *media, const gchar *url, const gchar *mime);
+void grl_media_set_url_data (GrlMedia *media, const gchar *url, const gchar *mime, gint bitrate);
 
 void grl_media_set_favourite (GrlMedia *media, gboolean favourite);
 
@@ -173,7 +173,27 @@ void grl_media_set_keyword (GrlMedia *media, const gchar *keyword);
 
 void grl_media_set_size (GrlMedia *media, gint64 size);
 
-void grl_media_add_url_data (GrlMedia *media, const gchar *url, const gchar *mime);
+void grl_media_set_track_number (GrlMedia *media, gint track_number);
+
+void grl_media_set_bitrate (GrlMedia *media, gint bitrate);
+
+void grl_media_set_mb_track_id (GrlMedia *media, const gchar *mb_track_id);
+
+void grl_media_set_mb_recording_id (GrlMedia *media, const gchar *mb_recording_id);
+
+void grl_media_set_mb_artist_id (GrlMedia *media, const gchar *mb_artist_id);
+
+void grl_media_set_mb_album_id (GrlMedia *media, const gchar *mb_album_id);
+
+void grl_media_set_lyrics (GrlMedia *media, const gchar *lyrics);
+
+void grl_media_set_genre (GrlMedia *media, const gchar *genre);
+
+void grl_media_set_album (GrlMedia *media, const gchar *album);
+
+void grl_media_set_artist (GrlMedia *media, const gchar *artist);
+
+void grl_media_add_url_data (GrlMedia *media, const gchar *url, const gchar *mime, gint bitrate);
 
 void grl_media_add_author (GrlMedia *media, const gchar *author);
 
@@ -187,13 +207,21 @@ void grl_media_add_external_url (GrlMedia *media, const gchar *url);
 
 void grl_media_add_keyword (GrlMedia *media, const gchar *keyword);
 
+void grl_media_add_artist (GrlMedia *media, const gchar *artist);
+
+void grl_media_add_genre (GrlMedia *media, const gchar *genre);
+
+void grl_media_add_lyrics (GrlMedia *media, const gchar *lyrics);
+
+void grl_media_add_mb_artist_id (GrlMedia *media, const gchar *mb_artist_id);
+
 const gchar *grl_media_get_id (GrlMedia *media);
 
 const gchar *grl_media_get_url (GrlMedia *media);
 
-const gchar *grl_media_get_url_data (GrlMedia *media, gchar **mime);
+const gchar *grl_media_get_url_data (GrlMedia *media, gchar **mime, gint *bitrate);
 
-const gchar *grl_media_get_url_data_nth (GrlMedia *media, guint index, gchar **mime);
+const gchar *grl_media_get_url_data_nth (GrlMedia *media, guint index, gchar **mime, gint *bitrate);
 
 const gchar *grl_media_get_author (GrlMedia *media);
 
@@ -268,10 +296,45 @@ const gchar * grl_media_get_keyword_nth (GrlMedia *media, guint index);
 
 gint64 grl_media_get_size (GrlMedia *media);
 
+gint grl_media_get_track_number (GrlMedia *media);
+
+gint grl_media_get_bitrate (GrlMedia *media);
+
+const gchar *grl_media_get_mb_album_id (GrlMedia *media);
+
+const gchar *grl_media_get_mb_artist_id (GrlMedia *media);
+
+const gchar *grl_media_get_mb_artist_id_nth (GrlMedia *media, guint index);
+
+const gchar *grl_media_get_mb_recording_id (GrlMedia *media);
+
+const gchar *grl_media_get_mb_track_id (GrlMedia *media);
+
+const gchar *grl_media_get_lyrics (GrlMedia *media);
+
+const gchar *grl_media_get_lyrics_nth (GrlMedia *media, guint index);
+
+const gchar *grl_media_get_genre (GrlMedia *media);
+
+const gchar *grl_media_get_genre_nth (GrlMedia *media, guint index);
+
+const gchar *grl_media_get_album (GrlMedia *media);
+
+const gchar *grl_media_get_artist (GrlMedia *media);
+
+const gchar *grl_media_get_artist_nth (GrlMedia *media, guint index);
+
+GrlMediaType grl_media_get_media_type (GrlMedia *media);
+
 GType grl_media_get_type (void) G_GNUC_CONST;
 
 GrlMedia *grl_media_new (void);
 
+GrlMedia *grl_media_audio_new (void);
+
+gboolean
+grl_media_is_audio (GrlMedia *media);
+
 gchar *grl_media_serialize (GrlMedia *media);
 
 gchar *grl_media_serialize_extended (GrlMedia *media,
diff --git a/src/grilo.c b/src/grilo.c
index 6ae63ce..de2684d 100644
--- a/src/grilo.c
+++ b/src/grilo.c
@@ -110,7 +110,6 @@ post_parse_hook_cb (GOptionContext  *context,
 
   /* Register GrlMedia in glib typesystem */
   g_type_class_ref (GRL_TYPE_MEDIA_BOX);
-  g_type_class_ref (GRL_TYPE_MEDIA_AUDIO);
   g_type_class_ref (GRL_TYPE_MEDIA_VIDEO);
   g_type_class_ref (GRL_TYPE_MEDIA_IMAGE);
 
diff --git a/src/grilo.h b/src/grilo.h
index 436038b..9f93287 100644
--- a/src/grilo.h
+++ b/src/grilo.h
@@ -34,7 +34,6 @@
 #include <grl-metadata-key.h>
 #include <grl-data.h>
 #include <grl-media.h>
-#include <grl-media-audio.h>
 #include <grl-media-video.h>
 #include <grl-media-image.h>
 #include <grl-media-box.h>
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index 951a70a..4b82ca4 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -345,7 +345,7 @@ get_icon_for_media (GrlMedia *media)
     return g_themed_icon_new ("folder");
   } else if (GRL_IS_MEDIA_VIDEO (media)) {
     return g_themed_icon_new ("gnome-mime-video");
-  } else if (GRL_IS_MEDIA_AUDIO (media)) {
+  } else if (grl_media_is_audio (media)) {
     return g_themed_icon_new ("gnome-mime-audio");
   } else if (GRL_IS_MEDIA_IMAGE (media)) {
     return g_themed_icon_new ("gnome-mime-image");
@@ -616,7 +616,7 @@ resolve_cb (GrlSource *source,
        when the treeview is cleared */
 
     /* Set/unset show button */
-    if ((GRL_IS_MEDIA_AUDIO (media) ||
+    if ((grl_media_is_audio (media) ||
          GRL_IS_MEDIA_VIDEO (media) ||
          GRL_IS_MEDIA_IMAGE (media)) &&
         (ui_state->last_url = grl_media_get_url (media))) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]