=?utf-8?q?=5Blibgdata=5D_Bug_658865_=E2=80=94_Add_support_for_the_license?= =?utf-8?q?_query_parameter?=
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] Bug 658865 â Add support for the license query parameter
- Date: Mon, 10 Oct 2011 20:58:49 +0000 (UTC)
commit efb1e2b8ae8328c82d86ce9fb4c3c00f3ddc6846
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Oct 10 21:57:58 2011 +0100
Bug 658865 â Add support for the license query parameter
Add a GDataYouTubeQuery:license parameter, plus getter and setter, and some
tests.
Closes: bgo#658865
docs/reference/gdata-sections.txt | 4 ++
gdata/gdata.symbols | 2 +
gdata/services/youtube/gdata-youtube-query.c | 74 +++++++++++++++++++++++++-
gdata/services/youtube/gdata-youtube-query.h | 22 ++++++++
gdata/tests/youtube.c | 8 ++-
5 files changed, 107 insertions(+), 3 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index c395fa8..4411ffa 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -226,6 +226,8 @@ GDATA_YOUTUBE_ACTION_COMMENT_VOTE
GDATA_YOUTUBE_ACTION_VIDEO_RESPOND
GDATA_YOUTUBE_ACTION_EMBED
GDATA_YOUTUBE_ACTION_SYNDICATE
+GDATA_YOUTUBE_LICENSE_CC
+GDATA_YOUTUBE_LICENSE_STANDARD
GDATA_YOUTUBE_RATING_TYPE_SIMPLE
GDATA_YOUTUBE_RATING_TYPE_MPAA
GDATA_YOUTUBE_RATING_TYPE_V_CHIP
@@ -633,6 +635,8 @@ gdata_youtube_query_get_format
gdata_youtube_query_set_format
gdata_youtube_query_get_language
gdata_youtube_query_set_language
+gdata_youtube_query_get_license
+gdata_youtube_query_set_license
gdata_youtube_query_get_location
gdata_youtube_query_set_location
gdata_youtube_query_get_order_by
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index a9e75c2..044f41c 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -936,3 +936,5 @@ GDATA_YOUTUBE_RATING_TYPE_MPAA
GDATA_YOUTUBE_RATING_TYPE_V_CHIP
gdata_youtube_video_get_media_rating
gdata_documents_entry_get_resource_id
+gdata_youtube_query_get_license
+gdata_youtube_query_set_license
diff --git a/gdata/services/youtube/gdata-youtube-query.c b/gdata/services/youtube/gdata-youtube-query.c
index 83b5b6e..6e348e5 100644
--- a/gdata/services/youtube/gdata-youtube-query.c
+++ b/gdata/services/youtube/gdata-youtube-query.c
@@ -59,6 +59,7 @@ struct _GDataYouTubeQueryPrivate {
GDataYouTubeSortOrder sort_order;
GDataYouTubeAge age;
GDataYouTubeUploader uploader;
+ gchar *license;
};
enum {
@@ -73,7 +74,8 @@ enum {
PROP_SAFE_SEARCH,
PROP_SORT_ORDER,
PROP_AGE,
- PROP_UPLOADER
+ PROP_UPLOADER,
+ PROP_LICENSE,
};
G_DEFINE_TYPE (GDataYouTubeQuery, gdata_youtube_query, GDATA_TYPE_QUERY)
@@ -299,6 +301,24 @@ gdata_youtube_query_class_init (GDataYouTubeQueryClass *klass)
"Uploader", "Restricts the search to videos from the specified type of uploader.",
GDATA_TYPE_YOUTUBE_UPLOADER, GDATA_YOUTUBE_UPLOADER_ALL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GDataYouTubeQuery:license:
+ *
+ * The content license which should be used to filter search results. If set to, for example, %GDATA_YOUTUBE_LICENSE_CC, only videos which
+ * are Creative Commons licensed will be returned in search results. Set this to %NULL to return videos under any license.
+ *
+ * For more information, see the <ulink type="http"
+ * url="http://code.google.com/apis/youtube/2.0/reference.html#licensesp">online documentation</ulink>.
+ *
+ * Since: 0.11.0
+ */
+ g_object_class_install_property (gobject_class, PROP_LICENSE,
+ g_param_spec_string ("license",
+ "License", "The content license which should be used to filter search results.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
}
static void
@@ -315,6 +335,7 @@ gdata_youtube_query_finalize (GObject *object)
g_free (priv->language);
g_free (priv->order_by);
g_free (priv->restriction);
+ g_free (priv->license);
/* Chain up to the parent class */
G_OBJECT_CLASS (gdata_youtube_query_parent_class)->finalize (object);
@@ -362,6 +383,9 @@ gdata_youtube_query_get_property (GObject *object, guint property_id, GValue *va
case PROP_UPLOADER:
g_value_set_enum (value, priv->uploader);
break;
+ case PROP_LICENSE:
+ g_value_set_string (value, priv->license);
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -411,6 +435,9 @@ gdata_youtube_query_set_property (GObject *object, guint property_id, const GVal
case PROP_UPLOADER:
gdata_youtube_query_set_uploader (self, g_value_get_enum (value));
break;
+ case PROP_LICENSE:
+ gdata_youtube_query_set_license (self, g_value_get_string (value));
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -506,6 +533,11 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
if (priv->uploader != GDATA_YOUTUBE_UPLOADER_ALL)
g_string_append (query_uri, "&uploader=partner");
+
+ if (priv->license != NULL) {
+ g_string_append (query_uri, "&license=");
+ g_string_append_uri_escaped (query_uri, priv->license, NULL, FALSE);
+ }
}
/**
@@ -894,3 +926,43 @@ gdata_youtube_query_set_uploader (GDataYouTubeQuery *self, GDataYouTubeUploader
/* Our current ETag will no longer be relevant */
gdata_query_set_etag (GDATA_QUERY (self), NULL);
}
+
+/**
+ * gdata_youtube_query_get_license:
+ * @self: a #GDataYouTubeQuery
+ *
+ * Gets the #GDataYouTubeQuery:license property.
+ *
+ * Return value: the license property, or %NULL if it is unset
+ *
+ * Since: 0.11.0
+ */
+const gchar *
+gdata_youtube_query_get_license (GDataYouTubeQuery *self)
+{
+ g_return_val_if_fail (GDATA_IS_YOUTUBE_QUERY (self), NULL);
+ return self->priv->license;
+}
+
+/**
+ * gdata_youtube_query_set_license:
+ * @self: a #GDataYouTubeQuery
+ * @license: (allow-none): a new license value, or %NULL
+ *
+ * Sets the #GDataYouTubeQuery:license property of the #GDataYouTubeQuery to the new license value, @license.
+ *
+ * Set @license to %NULL to unset the property in the query URI.
+ *
+ * Since: 0.11.0
+ */
+void
+gdata_youtube_query_set_license (GDataYouTubeQuery *self, const gchar *license)
+{
+ g_return_if_fail (GDATA_IS_YOUTUBE_QUERY (self));
+ g_free (self->priv->license);
+ self->priv->license = g_strdup (license);
+ g_object_notify (G_OBJECT (self), "license");
+
+ /* Our current ETag will no longer be relevant */
+ gdata_query_set_etag (GDATA_QUERY (self), NULL);
+}
diff --git a/gdata/services/youtube/gdata-youtube-query.h b/gdata/services/youtube/gdata-youtube-query.h
index 4d70b0f..255f575 100644
--- a/gdata/services/youtube/gdata-youtube-query.h
+++ b/gdata/services/youtube/gdata-youtube-query.h
@@ -96,6 +96,26 @@ typedef enum {
GDATA_YOUTUBE_UPLOADER_PARTNER
} GDataYouTubeUploader;
+/**
+ * GDATA_YOUTUBE_LICENSE_CC:
+ *
+ * Value for #GDataYouTubeVideo:license to restrict search results to only videos which are Creative Commons licensed. Specifically, the license
+ * is the Creative Commons Attribution 3.0 Unported license; see the
+ * <ulink type="http" url="http://www.google.com/support/youtube/bin/answer.py?hl=en&answer=1284989">YouTube Help</ulink> for more information.
+ *
+ * Since: 0.11.0
+ */
+#define GDATA_YOUTUBE_LICENSE_CC "cc"
+
+/**
+ * GDATA_YOUTUBE_LICENSE_STANDARD:
+ *
+ * Value for #GDataYouTubeVideo:license to restrict search results to only videos which are under the standard YouTube license.
+ *
+ * Since: 0.11.0
+ */
+#define GDATA_YOUTUBE_LICENSE_STANDARD "youtube"
+
#define GDATA_TYPE_YOUTUBE_QUERY (gdata_youtube_query_get_type ())
#define GDATA_YOUTUBE_QUERY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_YOUTUBE_QUERY, GDataYouTubeQuery))
#define GDATA_YOUTUBE_QUERY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_YOUTUBE_QUERY, GDataYouTubeQueryClass))
@@ -151,6 +171,8 @@ GDataYouTubeAge gdata_youtube_query_get_age (GDataYouTubeQuery *self) G_GNUC_PUR
void gdata_youtube_query_set_age (GDataYouTubeQuery *self, GDataYouTubeAge age);
GDataYouTubeUploader gdata_youtube_query_get_uploader (GDataYouTubeQuery *self) G_GNUC_PURE;
void gdata_youtube_query_set_uploader (GDataYouTubeQuery *self, GDataYouTubeUploader uploader);
+const gchar *gdata_youtube_query_get_license (GDataYouTubeQuery *self) G_GNUC_PURE;
+void gdata_youtube_query_set_license (GDataYouTubeQuery *self, const gchar *license);
G_END_DECLS
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index 8ec9710..36ba237 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -1279,14 +1279,17 @@ test_query_uri (void)
gdata_youtube_query_set_uploader (query, GDATA_YOUTUBE_UPLOADER_PARTNER);
g_assert_cmpuint (gdata_youtube_query_get_uploader (query), ==, GDATA_YOUTUBE_UPLOADER_PARTNER);
+ gdata_youtube_query_set_license (query, GDATA_YOUTUBE_LICENSE_CC);
+ g_assert_cmpstr (gdata_youtube_query_get_license (query), ==, GDATA_YOUTUBE_LICENSE_CC);
+
/* Check the built URI with a normal feed URI */
query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com");
- g_assert_cmpstr (query_uri, ==, "http://example.com?q=q&time=this_week&safeSearch=strict&format=1&lr=fr&orderby=relevance_lang_fr&restriction=192.168.0.1&sortorder=ascending&uploader=partner");
+ g_assert_cmpstr (query_uri, ==, "http://example.com?q=q&time=this_week&safeSearch=strict&format=1&lr=fr&orderby=relevance_lang_fr&restriction=192.168.0.1&sortorder=ascending&uploader=partner&license=cc");
g_free (query_uri);
/* âand with a feed URI with pre-existing arguments */
query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com?foobar=shizzle");
- g_assert_cmpstr (query_uri, ==, "http://example.com?foobar=shizzle&q=q&time=this_week&safeSearch=strict&format=1&lr=fr&orderby=relevance_lang_fr&restriction=192.168.0.1&sortorder=ascending&uploader=partner");
+ g_assert_cmpstr (query_uri, ==, "http://example.com?foobar=shizzle&q=q&time=this_week&safeSearch=strict&format=1&lr=fr&orderby=relevance_lang_fr&restriction=192.168.0.1&sortorder=ascending&uploader=partner&license=cc");
g_free (query_uri);
g_object_unref (query);
@@ -1314,6 +1317,7 @@ test_query_etag (void)
CHECK_ETAG (gdata_youtube_query_set_sort_order (query, GDATA_YOUTUBE_SORT_DESCENDING))
CHECK_ETAG (gdata_youtube_query_set_age (query, GDATA_YOUTUBE_AGE_THIS_WEEK))
CHECK_ETAG (gdata_youtube_query_set_uploader (query, GDATA_YOUTUBE_UPLOADER_PARTNER))
+ CHECK_ETAG (gdata_youtube_query_set_license (query, GDATA_YOUTUBE_LICENSE_STANDARD))
#undef CHECK_ETAG
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]