[libgdata] Bug 588052 – Parse the yt:aspectratio tag
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgdata] Bug 588052 – Parse the yt:aspectratio tag
- Date: Mon, 13 Jul 2009 20:26:09 +0000 (UTC)
commit 533ad2afe4cb37307dcec180759f0741a5cf39f0
Author: VÃctor Manuel Jáquez Leal <vjaquez igalia com>
Date: Fri Jul 10 14:55:47 2009 +0200
Bug 588052 â?? Parse the yt:aspectratio tag
Add support for aspect ratios to YouTube videos. Patch by VÃctor Manuel
Jáquez Leal. Closes bgo#588052.
gdata/gdata.symbols | 3 +
gdata/services/youtube/gdata-youtube-group.c | 45 +++++++++++++++++++
gdata/services/youtube/gdata-youtube-group.h | 3 +
gdata/services/youtube/gdata-youtube-video.c | 61 +++++++++++++++++++++++++-
gdata/services/youtube/gdata-youtube-video.h | 18 ++++++++
gdata/tests/youtube.c | 1 -
6 files changed, 129 insertions(+), 2 deletions(-)
---
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 180ee44..3bab83b 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -141,11 +141,14 @@ gdata_youtube_video_get_state
gdata_youtube_video_get_recorded
gdata_youtube_video_set_recorded
gdata_youtube_video_get_video_id_from_uri
+gdata_youtube_video_get_aspect_ratio
+gdata_youtube_video_set_aspect_ratio
gdata_youtube_format_get_type
gdata_youtube_safe_search_get_type
gdata_youtube_sort_order_get_type
gdata_youtube_age_get_type
gdata_youtube_uploader_get_type
+gdata_youtube_aspect_ratio_get_type
gdata_youtube_query_get_type
gdata_youtube_query_new
gdata_youtube_query_get_format
diff --git a/gdata/services/youtube/gdata-youtube-group.c b/gdata/services/youtube/gdata-youtube-group.c
index 8b6d700..4a6d73b 100644
--- a/gdata/services/youtube/gdata-youtube-group.c
+++ b/gdata/services/youtube/gdata-youtube-group.c
@@ -49,6 +49,7 @@ struct _GDataYouTubeGroupPrivate {
gboolean is_private;
GTimeVal uploaded;
gchar *video_id;
+ GDataYouTubeAspectRatio aspect_ratio;
};
G_DEFINE_TYPE (GDataYouTubeGroup, gdata_youtube_group, GDATA_TYPE_MEDIA_GROUP)
@@ -146,6 +147,17 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
return gdata_parser_error_duplicate_element (node, error);
}
self->priv->video_id = (gchar*) video_id;
+ } else if (xmlStrcmp (node->name, (xmlChar*) "aspectRatio") == 0) {
+ /* yt:aspectRatio */
+ xmlChar *aspect_ratio = xmlNodeGetContent (node);
+ if (xmlStrcmp (aspect_ratio, (xmlChar*) "widescreen") == 0) {
+ gdata_youtube_group_set_aspect_ratio (self, GDATA_YOUTUBE_ASPECT_RATIO_WIDESCREEN);
+ } else {
+ gdata_parser_error_unknown_content (node, (const gchar*) aspect_ratio, error);
+ xmlFree (aspect_ratio);
+ return FALSE;
+ }
+ xmlFree (aspect_ratio);
} else if (GDATA_PARSABLE_CLASS (gdata_youtube_group_parent_class)->parse_xml (parsable, doc, node, user_data, error) == FALSE) {
/* Error! */
return FALSE;
@@ -248,3 +260,36 @@ gdata_youtube_group_get_video_id (GDataYouTubeGroup *self)
g_return_val_if_fail (GDATA_IS_YOUTUBE_GROUP (self), NULL);
return self->priv->video_id;
}
+
+/**
+ * gdata_youtube_group_get_aspect_ratio:
+ * @self: a #GDataYouTubeGroup
+ *
+ * Gets the #GDataYouTubeGroup:aspect-ratio property.
+ *
+ * Return value: the aspect ratio property
+ *
+ * Since: 0.4.0
+ **/
+GDataYouTubeAspectRatio
+gdata_youtube_group_get_aspect_ratio (GDataYouTubeGroup *self)
+{
+ g_return_val_if_fail (GDATA_IS_YOUTUBE_GROUP (self), GDATA_YOUTUBE_ASPECT_RATIO_UNKNOWN);
+ return self->priv->aspect_ratio;
+}
+
+/**
+ * gdata_youtube_group_set_aspect_ratio:
+ * @self: a #GDataYouTubeGroup
+ * @aspect_ratio: the aspect ratio property
+ *
+ * Sets the #GDataYouTubeGroup:aspect-ratio property to decide the video aspect ratio.
+ *
+ * Since: 0.4.0
+ **/
+void
+gdata_youtube_group_set_aspect_ratio (GDataYouTubeGroup *self, GDataYouTubeAspectRatio aspect_ratio)
+{
+ g_return_if_fail (GDATA_IS_YOUTUBE_GROUP (self));
+ self->priv->aspect_ratio = aspect_ratio;
+}
diff --git a/gdata/services/youtube/gdata-youtube-group.h b/gdata/services/youtube/gdata-youtube-group.h
index a2d135d..d731c1c 100644
--- a/gdata/services/youtube/gdata-youtube-group.h
+++ b/gdata/services/youtube/gdata-youtube-group.h
@@ -25,6 +25,7 @@
#include <gdata/gdata-parsable.h>
#include <gdata/media/gdata-media-group.h>
+#include <gdata/services/youtube/gdata-youtube-video.h>
G_BEGIN_DECLS
@@ -66,6 +67,8 @@ gboolean gdata_youtube_group_is_private (GDataYouTubeGroup *self);
void gdata_youtube_group_set_is_private (GDataYouTubeGroup *self, gboolean is_private);
void gdata_youtube_group_get_uploaded (GDataYouTubeGroup *self, GTimeVal *uploaded);
const gchar *gdata_youtube_group_get_video_id (GDataYouTubeGroup *self);
+GDataYouTubeAspectRatio gdata_youtube_group_get_aspect_ratio (GDataYouTubeGroup *self);
+void gdata_youtube_group_set_aspect_ratio (GDataYouTubeGroup *self, GDataYouTubeAspectRatio aspect_ratio);
G_END_DECLS
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index 651b5bf..ed92851 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -44,6 +44,7 @@
#include "gdata-youtube-group.h"
#include "gdata-types.h"
#include "gdata-youtube-control.h"
+#include "gdata-youtube-enums.h"
static void gdata_youtube_video_dispose (GObject *object);
static void gdata_youtube_video_finalize (GObject *object);
@@ -97,7 +98,8 @@ enum {
PROP_VIDEO_ID,
PROP_IS_DRAFT,
PROP_STATE,
- PROP_RECORDED
+ PROP_RECORDED,
+ PROP_ASPECT_RATIO
};
G_DEFINE_TYPE (GDataYouTubeVideo, gdata_youtube_video, GDATA_TYPE_ENTRY)
@@ -418,6 +420,23 @@ gdata_youtube_video_class_init (GDataYouTubeVideoClass *klass)
"Recorded", "Specifies the time the video was originally recorded.",
GDATA_TYPE_G_TIME_VAL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * GDataYouTubeVideo:aspect-ratio:
+ *
+ * The aspect ratio of the video.
+ *
+ * For more information see the <ulink type="http"
+ * url="http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:aspectratio">online documentation</ulink>.
+ *
+ * Since: 0.4.0
+ **/
+ g_object_class_install_property (gobject_class, PROP_ASPECT_RATIO,
+ g_param_spec_enum ("aspect-ratio",
+ "Aspect Ratio", "The aspect ratio of the video.",
+ GDATA_TYPE_YOUTUBE_ASPECT_RATIO,
+ GDATA_YOUTUBE_ASPECT_RATIO_UNKNOWN,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
static void
@@ -525,6 +544,9 @@ gdata_youtube_video_get_property (GObject *object, guint property_id, GValue *va
case PROP_RECORDED:
g_value_set_boxed (value, &(priv->recorded));
break;
+ case PROP_ASPECT_RATIO:
+ g_value_set_enum (value, gdata_youtube_group_get_aspect_ratio (GDATA_YOUTUBE_GROUP (priv->media_group)));
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -565,6 +587,9 @@ gdata_youtube_video_set_property (GObject *object, guint property_id, const GVal
case PROP_RECORDED:
gdata_youtube_video_set_recorded (self, g_value_get_boxed (value));
break;
+ case PROP_ASPECT_RATIO:
+ gdata_youtube_video_set_aspect_ratio (self, g_value_get_enum (value));
+ break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -1351,3 +1376,37 @@ gdata_youtube_video_get_video_id_from_uri (const gchar *video_uri)
return video_id;
}
+
+/**
+ * gdata_youtube_video_get_aspect_ratio:
+ * @self: a #GDataYouTubeVideo
+ *
+ * Gets the #GDataYouTubeVideo:aspect-ratio property.
+ *
+ * Return value: the aspect ratio property
+ *
+ * Since: 0.4.0
+ **/
+GDataYouTubeAspectRatio
+gdata_youtube_video_get_aspect_ratio (GDataYouTubeVideo *self)
+{
+ g_return_val_if_fail (GDATA_IS_YOUTUBE_VIDEO (self), FALSE);
+ return gdata_youtube_group_get_aspect_ratio (GDATA_YOUTUBE_GROUP (self->priv->media_group));
+}
+
+/**
+ * gdata_youtube_video_set_aspect_ratio:
+ * @self: a #GDataYouTubeVideo
+ * @aspect_ratio: the aspect ratio property
+ *
+ * Sets the #GDataYouTubeVideo:aspect-ratio property to specify the video's aspect ratio.
+ *
+ * Since: 0.4.0
+ **/
+void
+gdata_youtube_video_set_aspect_ratio (GDataYouTubeVideo *self, GDataYouTubeAspectRatio aspect_ratio)
+{
+ g_return_if_fail (GDATA_IS_YOUTUBE_VIDEO (self));
+ gdata_youtube_group_set_aspect_ratio (GDATA_YOUTUBE_GROUP (self->priv->media_group), aspect_ratio);
+ g_object_notify (G_OBJECT (self), "aspect-ratio");
+}
diff --git a/gdata/services/youtube/gdata-youtube-video.h b/gdata/services/youtube/gdata-youtube-video.h
index d377b87..0bfd51e 100644
--- a/gdata/services/youtube/gdata-youtube-video.h
+++ b/gdata/services/youtube/gdata-youtube-video.h
@@ -31,6 +31,22 @@
G_BEGIN_DECLS
+/**
+ * GDataYouTubeAspectRatio:
+ * @GDATA_YOUTUBE_ASPECT_RATIO_UNKNOWN: unknown aspect ratio
+ * @GDATA_YOUTUBE_ASPECT_RATIO_WIDESCREEN: widescreen (16:9) video
+ *
+ * The aspect ratio of a video. See the
+ * <ulink type="http" url="http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:aspectratio">online documentation</ulink>
+ * for more information.
+ *
+ * Since: 0.4.0
+ **/
+typedef enum {
+ GDATA_YOUTUBE_ASPECT_RATIO_UNKNOWN = 0,
+ GDATA_YOUTUBE_ASPECT_RATIO_WIDESCREEN
+} GDataYouTubeAspectRatio;
+
#define GDATA_TYPE_YOUTUBE_VIDEO (gdata_youtube_video_get_type ())
#define GDATA_YOUTUBE_VIDEO(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_YOUTUBE_VIDEO, GDataYouTubeVideo))
#define GDATA_YOUTUBE_VIDEO_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_YOUTUBE_VIDEO, GDataYouTubeVideoClass))
@@ -94,6 +110,8 @@ void gdata_youtube_video_set_is_draft (GDataYouTubeVideo *self, gboolean is_draf
GDataYouTubeState *gdata_youtube_video_get_state (GDataYouTubeVideo *self);
void gdata_youtube_video_get_recorded (GDataYouTubeVideo *self, GTimeVal *recorded);
void gdata_youtube_video_set_recorded (GDataYouTubeVideo *self, GTimeVal *recorded);
+GDataYouTubeAspectRatio gdata_youtube_video_get_aspect_ratio (GDataYouTubeVideo *self);
+void gdata_youtube_video_set_aspect_ratio (GDataYouTubeVideo *self, GDataYouTubeAspectRatio aspect_ratio);
gchar *gdata_youtube_video_get_video_id_from_uri (const gchar *video_uri);
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index c68b891..38a4672 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -674,7 +674,6 @@ main (int argc, char *argv[])
/*g_test_add_func ("/youtube/parsing/comments/feedLink", test_parsing_comments_feed_link);*/
g_test_add_data_func ("/youtube/parsing/yt:recorded", service, test_parsing_yt_recorded);
g_test_add_data_func ("/youtube/query/uri", service, test_query_uri);
- g_test_add_data_func ("/youtube/query/uri", service, test_query_uri);
g_test_add_data_func ("/youtube/query/single", service, test_query_single);
if (g_test_slow () == TRUE)
g_test_add_data_func ("/youtube/query/single_async", service, test_query_single_async);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]