[grilo] Add region tags for publication and certification



commit ee5513f6303412a0d3e7c4ccf2dcbd43132f8405
Author: Mathias Hasselmann <mathias openismus com>
Date:   Tue Oct 16 20:48:46 2012 +0200

    Add region tags for publication and certification
    
    Both TMDB and IMDB publish region specific information for this metadata.
    
    This fixes https://bugzilla.gnome.org/show_bug.cgi?id=679686

 bindings/vala/grilo-0.2-custom.vala |    2 +
 doc/grilo/grilo-sections.txt        |    7 ++
 src/data/grl-media.c                |  156 ++++++++++++++++++++++++++++++++++-
 src/data/grl-media.h                |   24 ++++++
 src/grl-metadata-key.c              |   16 ++++-
 src/grl-metadata-key.h              |    1 +
 6 files changed, 202 insertions(+), 4 deletions(-)
---
diff --git a/bindings/vala/grilo-0.2-custom.vala b/bindings/vala/grilo-0.2-custom.vala
index 9c93c0e..165eac6 100644
--- a/bindings/vala/grilo-0.2-custom.vala
+++ b/bindings/vala/grilo-0.2-custom.vala
@@ -58,6 +58,8 @@ namespace Grl {
 		public static Grl.KeyID PLAY_COUNT;
 		[CCode (cname ="GRL_METADATA_KEY_RATING")]
 		public static Grl.KeyID RATING;
+		[CCode (cname ="GRL_METADATA_KEY_REGION")]
+		public static Grl.KeyID REGION;
 		[CCode (cname ="GRL_METADATA_KEY_SITE")]
 		public static Grl.KeyID SITE;
 		[CCode (cname ="GRL_METADATA_KEY_SOURCE")]
diff --git a/doc/grilo/grilo-sections.txt b/doc/grilo/grilo-sections.txt
index 16313d2..7a42604 100644
--- a/doc/grilo/grilo-sections.txt
+++ b/doc/grilo/grilo-sections.txt
@@ -329,6 +329,7 @@ grl_media_new
 grl_media_add_author
 grl_media_add_external_player
 grl_media_add_external_url
+grl_media_add_region_data
 grl_media_add_thumbnail
 grl_media_add_thumbnail_binary
 grl_media_add_url_data
@@ -351,6 +352,9 @@ grl_media_get_player
 grl_media_get_player_nth
 grl_media_get_publication_date
 grl_media_get_rating
+grl_media_get_region
+grl_media_get_region_data
+grl_media_get_region_data_nth
 grl_media_get_site
 grl_media_get_source
 grl_media_get_start_time
@@ -381,6 +385,8 @@ grl_media_set_modification_date
 grl_media_set_play_count
 grl_media_set_publication_date
 grl_media_set_rating
+grl_media_set_region
+grl_media_set_region_data
 grl_media_set_site
 grl_media_set_source
 grl_media_set_studio
@@ -611,6 +617,7 @@ GRL_METADATA_KEY_ORIENTATION
 GRL_METADATA_KEY_PLAY_COUNT
 GRL_METADATA_KEY_PUBLICATION_DATE
 GRL_METADATA_KEY_RATING
+GRL_METADATA_KEY_REGION
 GRL_METADATA_KEY_SEASON
 GRL_METADATA_KEY_SHOW
 GRL_METADATA_KEY_SITE
diff --git a/src/data/grl-media.c b/src/data/grl-media.c
index 2155032..b88a70e 100644
--- a/src/data/grl-media.c
+++ b/src/data/grl-media.c
@@ -691,6 +691,82 @@ grl_media_set_publication_date (GrlMedia *media, const GDateTime *date)
 }
 
 /**
+ * grl_media_set_region:
+ * @media: a #GrlMedia
+ * @region: the region's ISO-3166-1 code
+ *
+ * Sets the @region where @media got published.
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_set_region (GrlMedia *media,
+                      const gchar *region)
+{
+  grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_REGION, region);
+}
+
+/**
+ * grl_media_set_region_data:
+ * @media: a #GrlMedia
+ * @region: the region's ISO-3166-1 code
+ * @publication_date: the publication date
+ * @certificate: the age certification
+ *
+ * Sets regional publication and certification information for @region.
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_set_region_data (GrlMedia *media,
+                           const gchar *region,
+                           const GDateTime *publication_date,
+                           const gchar *certificate)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_REGION,
+                               region);
+  grl_related_keys_set_boxed (relkeys,
+                              GRL_METADATA_KEY_PUBLICATION_DATE,
+                              publication_date);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE,
+                               certificate);
+  grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
+}
+
+/**
+ * grl_media_add_region_data:
+ * @media: a #GrlMedia
+ * @region: the region's ISO-3166-1 code
+ * @publication_date: the publication date
+ * @certificate: the age certification
+ *
+ * Adds regional publication and certification information for @region.
+ *
+ * Since: 0.2.3
+ */
+void
+grl_media_add_region_data (GrlMedia *media,
+                           const gchar *region,
+                           const GDateTime *publication_date,
+                           const gchar *certificate)
+{
+  GrlRelatedKeys *relkeys = grl_related_keys_new ();
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_REGION,
+                               region);
+  grl_related_keys_set_boxed (relkeys,
+                              GRL_METADATA_KEY_PUBLICATION_DATE,
+                              publication_date);
+  grl_related_keys_set_string (relkeys,
+                               GRL_METADATA_KEY_CERTIFICATE,
+                               certificate);
+  grl_data_add_related_keys (GRL_DATA (media), relkeys);
+}
+
+/**
   * grl_media_set_creation_date:
   * @media: the media
   * @creation_date: date when media was created
@@ -849,9 +925,9 @@ grl_media_set_studio (GrlMedia *media, const gchar *studio)
 /**
  * grl_media_set_certificate:
  * @media: the media
- * @certificate: The rating certificate of the media
+ * @certificate: The age certificate of the media
  *
- * Set the media certificate
+ * Set the media's age certificatication
  *
  * Since: 0.1.6
  */
@@ -1174,6 +1250,80 @@ grl_media_get_publication_date (GrlMedia *media)
 }
 
 /**
+ * grl_media_get_region:
+ * @media: the media object
+ *
+ * Returns: (transfer none): the ISO-3166-1 of the region where the media got
+ * published (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_region (GrlMedia *media)
+{
+  return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_REGION);
+}
+
+/**
+ * grl_media_get_region_data:
+ * @media: the media object
+ * @publication_date: (out) (transfer none): the publication date, or %NULL to ignore.
+ * @certificate: (out) (transfer none): the age certification, or %NULL to ignore.
+ *
+ * Returns: (transfer none): the ISO-3166-1 of the region where the media got
+ * published (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_region_data (GrlMedia *media,
+                           const GDateTime **publication_date,
+                           const gchar **certificate)
+{
+  return grl_media_get_region_data_nth (media, 0, publication_date,  certificate);
+}
+
+/**
+ * grl_media_get_region_data_nth:
+ * @media: the media object
+ * @index: element to retrieve
+ * @publication_date: (out) (transfer none): the publication date, or %NULL to ignore.
+ * @certificate: (out) (transfer none): the age certification, or %NULL to ignore.
+ *
+ * Returns: (transfer none): the ISO-3166-1 of the region where the media got
+ * published (owned by @media).
+ *
+ * Since: 0.2.3
+ */
+const gchar *
+grl_media_get_region_data_nth (GrlMedia *media,
+                               guint index,
+                               const GDateTime **publication_date,
+                               const gchar **certificate)
+{
+    GrlRelatedKeys *relkeys =
+      grl_data_get_related_keys (GRL_DATA (media),
+                                 GRL_METADATA_KEY_PUBLICATION_DATE,
+                                 index);
+
+    if (!relkeys) {
+      return NULL;
+    }
+
+    if (publication_date) {
+      *publication_date = grl_related_keys_get_boxed
+                (relkeys, GRL_METADATA_KEY_PUBLICATION_DATE);
+    }
+
+    if (certificate) {
+      *certificate = grl_related_keys_get_string
+                (relkeys, GRL_METADATA_KEY_CERTIFICATE);
+    }
+
+    return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_REGION);
+}
+
+/**
  * grl_media_get_creation_date:
  * @media: the media
  *
@@ -1371,7 +1521,7 @@ grl_media_get_studio(GrlMedia *media)
  * grl_media_get_certificate:
  * @media: the media object
  *
- * Returns: the media's certificate
+ * Returns: the media's age certificatification
  *
  * Since: 0.1.6
  */
diff --git a/src/data/grl-media.h b/src/data/grl-media.h
index 246b5f2..10b049a 100644
--- a/src/data/grl-media.h
+++ b/src/data/grl-media.h
@@ -121,6 +121,19 @@ void grl_media_set_duration (GrlMedia *media, gint duration);
 
 void grl_media_set_publication_date (GrlMedia *media, const GDateTime *date);
 
+void grl_media_set_region (GrlMedia *media,
+                           const gchar *region);
+
+void grl_media_set_region_data (GrlMedia *media,
+                                const gchar *region,
+                                const GDateTime *publication_date,
+                                const gchar *certificate);
+
+void grl_media_add_region_data (GrlMedia *media,
+                                const gchar *region,
+                                const GDateTime *publication_date,
+                                const gchar *certificate);
+
 void grl_media_set_creation_date (GrlMedia *media,
                                   const GDateTime *creation_date);
 
@@ -195,6 +208,17 @@ gint grl_media_get_duration (GrlMedia *media);
 
 GDateTime *grl_media_get_publication_date (GrlMedia *media);
 
+const gchar *grl_media_get_region (GrlMedia *media);
+
+const gchar *grl_media_get_region_data(GrlMedia *media,
+                                       const GDateTime **publication_date,
+                                       const gchar **certificate);
+
+const gchar *grl_media_get_region_data_nth(GrlMedia *media,
+                                           guint index,
+                                           const GDateTime **publication_date,
+                                           const gchar **certificate);
+
 GDateTime *grl_media_get_creation_date (GrlMedia *media);
 
 GDateTime *grl_media_get_modification_date (GrlMedia *media);
diff --git a/src/grl-metadata-key.c b/src/grl-metadata-key.c
index 4cf06b9..430e2d5 100644
--- a/src/grl-metadata-key.c
+++ b/src/grl-metadata-key.c
@@ -457,6 +457,15 @@ grl_metadata_key_setup_system_keys (GrlRegistry *registry)
                                            GRL_METADATA_KEY_FAVOURITE,
                                            NULL);
 
+  grl_registry_register_metadata_key_full (registry,
+                                           g_param_spec_string ("region",
+                                                                "Region",
+                                                                "Region in which the media was published",
+                                                                NULL,
+                                                                G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE),
+                                           GRL_METADATA_KEY_REGION,
+                                           NULL);
+
   /* Create the relations */
   grl_registry_register_metadata_key_relation (registry,
                                                GRL_METADATA_KEY_URL,
@@ -476,7 +485,12 @@ grl_metadata_key_setup_system_keys (GrlRegistry *registry)
   grl_registry_register_metadata_key_relation (registry,
                                                GRL_METADATA_KEY_URL,
                                                GRL_METADATA_KEY_START_TIME);
-
+  grl_registry_register_metadata_key_relation (registry,
+                                               GRL_METADATA_KEY_REGION,
+                                               GRL_METADATA_KEY_PUBLICATION_DATE);
+  grl_registry_register_metadata_key_relation (registry,
+                                               GRL_METADATA_KEY_REGION,
+                                               GRL_METADATA_KEY_CERTIFICATE);
 }
 
 /**
diff --git a/src/grl-metadata-key.h b/src/grl-metadata-key.h
index 0109c9b..3009886 100644
--- a/src/grl-metadata-key.h
+++ b/src/grl-metadata-key.h
@@ -90,6 +90,7 @@ typedef guint32 GrlKeyID;
 #define GRL_METADATA_KEY_MODIFICATION_DATE    41
 #define GRL_METADATA_KEY_START_TIME           42
 #define GRL_METADATA_KEY_FAVOURITE            43
+#define GRL_METADATA_KEY_REGION               44
 
 G_BEGIN_DECLS
 



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