[libgdata/libgdata-0-8] media: Handle media:rating elements which don't provide a country attribute
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata/libgdata-0-8] media: Handle media:rating elements which don't provide a country attribute
- Date: Fri, 15 Apr 2011 17:35:49 +0000 (UTC)
commit d422c55d7f5c742a5d9bc9cebf34cf7e0512e3d3
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Apr 15 17:54:29 2011 +0100
media: Handle media:rating elements which don't provide a country attribute
Includes a test case.
gdata/media/gdata-media-group.c | 22 ++++++++++----
gdata/tests/youtube.c | 60 +++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 7 deletions(-)
---
diff --git a/gdata/media/gdata-media-group.c b/gdata/media/gdata-media-group.c
index c046bb5..94bf01e 100644
--- a/gdata/media/gdata-media-group.c
+++ b/gdata/media/gdata-media-group.c
@@ -195,16 +195,24 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
} else if (xmlStrcmp (node->name, (xmlChar*) "rating") == 0) {
/* media:rating */
xmlChar *countries;
- gchar **country_list, **country;
countries = xmlGetProp (node, (xmlChar*) "country");
- country_list = g_strsplit ((const gchar*) countries, ",", -1);
- xmlFree (countries);
- /* Add all the listed countries to the restricted countries table */
- for (country = country_list; *country != NULL; country++)
- g_hash_table_insert (self->priv->restricted_countries, *country, GUINT_TO_POINTER (TRUE));
- g_free (country_list);
+ if (countries != NULL) {
+ gchar **country_list, **country;
+
+ /* It's either a comma-separated list of countries, or the value "all" */
+ country_list = g_strsplit ((const gchar*) countries, ",", -1);
+ xmlFree (countries);
+
+ /* Add all the listed countries to the restricted countries table */
+ for (country = country_list; *country != NULL; country++)
+ g_hash_table_insert (self->priv->restricted_countries, *country, GUINT_TO_POINTER (TRUE));
+ g_free (country_list);
+ } else {
+ /* Assume it's restricted in all countries */
+ g_hash_table_insert (self->priv->restricted_countries, g_strdup ("all"), GUINT_TO_POINTER (TRUE));
+ }
} else if (xmlStrcmp (node->name, (xmlChar*) "restriction") == 0) {
/* media:restriction */
xmlChar *type, *countries, *relationship;
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index 7dffb7b..7852dd3 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -896,6 +896,65 @@ test_parsing_georss_where (void)
}
static void
+test_parsing_media_group (void)
+{
+ GDataYouTubeVideo *video;
+ GError *error = NULL;
+
+ video = GDATA_YOUTUBE_VIDEO (gdata_parsable_new_from_xml (GDATA_TYPE_YOUTUBE_VIDEO,
+ "<entry xmlns='http://www.w3.org/2005/Atom' "
+ "xmlns:media='http://search.yahoo.com/mrss/' "
+ "xmlns:yt='http://gdata.youtube.com/schemas/2007' "
+ "xmlns:gd='http://schemas.google.com/g/2005'>"
+ "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>"
+ "<published>2006-05-16T14:06:37.000Z</published>"
+ "<updated>2009-03-23T12:46:58.000Z</updated>"
+ "<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>"
+ "<title>Some video somewhere</title>"
+ "<link rel='http://www.iana.org/assignments/relation/alternate' type='text/html' href='http://www.youtube.com/watch?v=JAagedeKdcQ'/>"
+ "<link rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo'/>"
+ "<author>"
+ "<name>Foo</name>"
+ "<uri>http://gdata.youtube.com/feeds/api/users/Foo</uri>"
+ "</author>"
+ "<media:group>"
+ "<media:category label='Shows' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Shows</media:category>"
+ "<media:category scheme='http://gdata.youtube.com/schemas/2007/releasemediums.cat'>6</media:category>"
+ "<media:category scheme='http://gdata.youtube.com/schemas/2007/mediatypes.cat'>3</media:category>"
+ "<media:content url='http://www.youtube.com/v/aklRlKH4R94?f=related&d=ARK7_SyB_5iKQvGvwsk-0D4O88HsQjpE1a8d1GxQnGDm&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='163' yt:format='5'/>"
+ "<media:content url='rtsp://v3.cache6.c.youtube.com/CkYLENy73wIaPQneR_ihlFFJahMYDSANFEgGUgdyZWxhdGVkciEBErv9LIH_mIpC8a_CyT7QPg7zwexCOkTVrx3UbFCcYOYM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='163' yt:format='1'/>"
+ "<media:content url='rtsp://v3.cache3.c.youtube.com/CkYLENy73wIaPQneR_ihlFFJahMYESARFEgGUgdyZWxhdGVkciEBErv9LIH_mIpC8a_CyT7QPg7zwexCOkTVrx3UbFCcYOYM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='163' yt:format='6'/>"
+ "<media:credit role='uploader' scheme='urn:youtube' yt:type='partner'>machinima</media:credit>"
+ "<media:credit role='Producer' scheme='urn:ebu'>Machinima</media:credit>"
+ "<media:credit role='info' scheme='urn:ebu'>season 1 episode 4 air date 08/22/10</media:credit>"
+ "<media:credit role='Producer' scheme='urn:ebu'>Machinima</media:credit>"
+ "<media:credit role='info' scheme='urn:ebu'>season 1 episode 4 air date 08/22/10</media:credit>"
+ "<media:description type='plain'>www.youtube.com Click here to watch If It Were Realistic: Melee If It Were Realistic: Gravity Gun (Half Life 2 Machinima) What if gravity guns were realistic? Created by Renaldoxx from Massive X Productions Directors Channel: www.youtube.com www.youtube.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Follow Machinima on Twitter! Machinima twitter.com Inside Gaming twitter.com Machinima Respawn twitter.com Machinima Entertainment, Technology, Culture twitter.com FOR MORE MACHINIMA, GO TO: www.youtube.com FOR MORE GAMEPLAY, GO TO: www.youtube.com FOR MORE SPORTS GAMEPLAY, GO TO: www.youtube.com FOR MORE TRAILERS, GO TO: www.youtube.com</media:description>"
+ "<media:keywords>Half, Life, If, It, Were, Realistic, Gravity, Gun, Renaldoxx, Sniper, Game, Machinima, Action, Gordon, Freeman, drift0r, Euphorian, Films, Combine, Rebel, Dark, Citizen, Diary, massivex, Productions, Massive, yt:quality=high, Half-Life, [2], HL2, fortress, gmod, left dead, tf2</media:keywords>"
+ "<media:player url='http://www.youtube.com/watch?v=aklRlKH4R94&feature=youtube_gdata_player'/>"
+ "<media:rating scheme='urn:mpaa'>pg</media:rating>"
+ "<media:thumbnail url='http://i.ytimg.com/vi/aklRlKH4R94/default.jpg' height='90' width='120' time='00:01:21.500' yt:name='default'/>"
+ "<media:thumbnail url='http://i.ytimg.com/vi/aklRlKH4R94/hqdefault.jpg' height='360' width='480' yt:name='hqdefault'/>"
+ "<media:thumbnail url='http://i.ytimg.com/vi/aklRlKH4R94/1.jpg' height='90' width='120' time='00:00:40.750' yt:name='start'/>"
+ "<media:thumbnail url='http://i.ytimg.com/vi/aklRlKH4R94/2.jpg' height='90' width='120' time='00:01:21.500' yt:name='middle'/>"
+ "<media:thumbnail url='http://i.ytimg.com/vi/aklRlKH4R94/3.jpg' height='90' width='120' time='00:02:02.250' yt:name='end'/>"
+ "<media:title type='plain'>If It Were Realistic - Gravity Gun (Half Life 2 Machinima)</media:title>"
+ "<yt:aspectRatio>widescreen</yt:aspectRatio>"
+ "<yt:duration seconds='163'/>"
+ "<yt:uploaded>2010-08-22T14:04:18.000Z</yt:uploaded>"
+ "<yt:videoid>aklRlKH4R94</yt:videoid>"
+ "</media:group>"
+ "</entry>", -1, &error));
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_YOUTUBE_VIDEO (video));
+ g_clear_error (&error);
+
+ /* TODO: For the moment, we just check that parsing the XML didn't fail. Later, we might actually support outputting the XML again. */
+
+ g_object_unref (video);
+}
+
+static void
test_video_escaping (void)
{
GDataYouTubeVideo *video;
@@ -1394,6 +1453,7 @@ main (int argc, char *argv[])
g_test_add_func ("/youtube/parsing/yt:category", test_parsing_yt_category);
g_test_add_func ("/youtube/parsing/video_id_from_uri", test_parsing_video_id_from_uri);
g_test_add_func ("/youtube/parsing/georss:where", test_parsing_georss_where);
+ g_test_add_func ("/youtube/parsing/media:group", test_parsing_media_group);
g_test_add_func ("/youtube/video/escaping", test_video_escaping);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]