1 /*
2  * Copyright (C) 2010, 2011 Igalia S.L.
3  *
4  * Contact: Iago Toral Quiroga <itoral@igalia.com>
5  *
6  * Authors: Juan A. Suarez Romero <jasuarez@igalia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 /**
26  * SECTION:grl-media
27  * @short_description: A multimedia data transfer object
28  * @see_also: #GrlData
29  *
30  * This high level class represents a multimedia item. It has methods to
31  * set and get properties like author, title, description, and so on.
32  */
33 
34 #include "grl-media.h"
35 #include "grl-type-builtins.h"
36 #include <grilo.h>
37 #include <stdlib.h>
38 #include <string.h>
39 
40 #define GRL_LOG_DOMAIN_DEFAULT  media_log_domain
41 GRL_LOG_DOMAIN(media_log_domain);
42 
43 #define RATING_MAX  5.00
44 #define SERIAL_STRING_ALLOC 100
45 
46 enum {
47   PROP_0,
48   PROP_MEDIA_TYPE
49 };
50 
51 struct _GrlMediaPrivate {
52   GrlMediaType media_type;
53 };
54 
55 static void grl_media_finalize (GObject *object);
56 
57 G_DEFINE_TYPE_WITH_PRIVATE (GrlMedia, grl_media, GRL_TYPE_DATA);
58 
59 static void
grl_media_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)60 grl_media_set_property (GObject *object,
61                         guint prop_id,
62                         const GValue *value,
63                         GParamSpec *pspec)
64 {
65   GrlMedia *media = GRL_MEDIA (object);
66 
67   switch (prop_id) {
68   case PROP_MEDIA_TYPE:
69     media->priv->media_type = g_value_get_enum (value);
70     break;
71   default:
72     G_OBJECT_WARN_INVALID_PROPERTY_ID (media, prop_id, pspec);
73     break;
74   }
75 }
76 
77 static void
grl_media_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)78 grl_media_get_property (GObject *object,
79                         guint prop_id,
80                         GValue *value,
81                         GParamSpec *pspec)
82 {
83   GrlMedia *media = GRL_MEDIA (object);
84 
85   switch (prop_id) {
86   case PROP_MEDIA_TYPE:
87     g_value_set_enum (value, media->priv->media_type);
88     break;
89   default:
90     G_OBJECT_WARN_INVALID_PROPERTY_ID (media, prop_id, pspec);
91     break;
92   }
93 }
94 
95 static void
grl_media_class_init(GrlMediaClass * klass)96 grl_media_class_init (GrlMediaClass *klass)
97 {
98   GObjectClass *gobject_class = (GObjectClass *)klass;
99 
100   gobject_class->finalize = grl_media_finalize;
101   gobject_class->set_property = grl_media_set_property;
102   gobject_class->get_property = grl_media_get_property;
103 
104   /**
105    * GrlMedia::media-type
106    *
107    * The type of the media.
108    */
109   g_object_class_install_property (gobject_class,
110                                    PROP_MEDIA_TYPE,
111                                    g_param_spec_enum ("media-type",
112                                                       "Media type",
113                                                       "Type of media",
114                                                       GRL_TYPE_MEDIA_TYPE,
115                                                       GRL_MEDIA_TYPE_UNKNOWN,
116                                                       G_PARAM_READWRITE |
117                                                       G_PARAM_CONSTRUCT |
118                                                       G_PARAM_STATIC_STRINGS));
119 }
120 
121 static void
grl_media_init(GrlMedia * self)122 grl_media_init (GrlMedia *self)
123 {
124   self->priv = grl_media_get_instance_private (self);
125 }
126 
127 static void
grl_media_finalize(GObject * object)128 grl_media_finalize (GObject *object)
129 {
130   GRL_DEBUG ("grl_media_finalize (%s)",
131              grl_data_get_string (GRL_DATA (object),
132                                   GRL_METADATA_KEY_TITLE));
133   g_signal_handlers_destroy (object);
134   G_OBJECT_CLASS (grl_media_parent_class)->finalize (object);
135 }
136 
137 /**
138  * grl_media_new:
139  *
140  * Creates a new data media object.
141  *
142  * Returns: a newly-allocated data media.
143  **/
144 GrlMedia *
grl_media_new(void)145 grl_media_new (void)
146 {
147   return g_object_new (GRL_TYPE_MEDIA,
148                        "media-type", GRL_MEDIA_TYPE_UNKNOWN,
149                        NULL);
150 }
151 
152 /**
153  * grl_media_audio_new:
154  *
155  * Creates a new media audio object.
156  *
157  * Returns: a newly-allocated media audio.
158  *
159  * Since: 0.1.4
160  **/
161 GrlMedia *
grl_media_audio_new(void)162 grl_media_audio_new (void)
163 {
164   return g_object_new (GRL_TYPE_MEDIA,
165                        "media-type", GRL_MEDIA_TYPE_AUDIO,
166                        NULL);
167 }
168 
169 /**
170  * grl_media_video_new:
171  *
172  * Creates a new media video object.
173  *
174  * Returns: a newly-allocated media video.
175  *
176  * Since: 0.1.4
177  */
178 GrlMedia *
grl_media_video_new(void)179 grl_media_video_new (void)
180 {
181   return g_object_new (GRL_TYPE_MEDIA,
182                        "media-type", GRL_MEDIA_TYPE_VIDEO,
183                        NULL);
184 }
185 
186 /**
187  * grl_media_image_new:
188  *
189  * Creates a new media image object.
190  *
191  * Returns: a newly-allocated media image.
192  *
193  * Since: 0.1.4
194  **/
195 GrlMedia *
grl_media_image_new(void)196 grl_media_image_new (void)
197 {
198   return g_object_new (GRL_TYPE_MEDIA,
199                        "media-type", GRL_MEDIA_TYPE_IMAGE,
200                        NULL);
201 }
202 
203 /**
204  * grl_media_container_new:
205  *
206  * Creates a new media container object.
207  *
208  * Returns: a newly-allocated media container.
209  *
210  * Since: 0.3.0
211  **/
212 GrlMedia *
grl_media_container_new(void)213 grl_media_container_new (void)
214 {
215   return g_object_new (GRL_TYPE_MEDIA,
216                        "media-type", GRL_MEDIA_TYPE_CONTAINER,
217                        NULL);
218 }
219 
220 /**
221  * grl_media_is_audio:
222  * @media: a media
223  *
224  * Check if @media is an audio
225  *
226  * Returns: %TRUE if @media is an audio
227  *
228  * Since: 0.3.0
229  **/
230 gboolean
grl_media_is_audio(GrlMedia * media)231 grl_media_is_audio (GrlMedia *media)
232 {
233   g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
234 
235   return (media->priv->media_type == GRL_MEDIA_TYPE_AUDIO);
236 }
237 
238 /**
239  * grl_media_is_video:
240  * @media: a media
241  *
242  * Check if @media is a video
243  *
244  * Returns: %TRUE if @media is a video
245  *
246  * Since: 0.3.0
247  **/
248 gboolean
grl_media_is_video(GrlMedia * media)249 grl_media_is_video (GrlMedia *media)
250 {
251   g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
252 
253   return (media->priv->media_type == GRL_MEDIA_TYPE_VIDEO);
254 }
255 
256 /**
257  * grl_media_is_image:
258  * @media: a media
259  *
260  * Check if @media is an image
261  *
262  * Returns: %TRUE if @media is an image
263  *
264  * Since: 0.3.0
265  **/
266 gboolean
grl_media_is_image(GrlMedia * media)267 grl_media_is_image (GrlMedia *media)
268 {
269   g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
270 
271   return (media->priv->media_type == GRL_MEDIA_TYPE_IMAGE);
272 }
273 
274 /**
275  * grl_media_is_container:
276  * @media: a media
277  *
278  * Check if @media is a container
279  *
280  * Returns: %TRUE if @media is a container
281  *
282  * Since: 0.3.0
283  **/
284 gboolean
grl_media_is_container(GrlMedia * media)285 grl_media_is_container (GrlMedia *media)
286 {
287   g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
288 
289   return (media->priv->media_type == GRL_MEDIA_TYPE_CONTAINER);
290 }
291 
292 /**
293  * grl_media_set_rating:
294  * @media: a media
295  * @rating: a rating value
296  * @max: maximum rating value
297  *
298  * This method receives a rating and its scale and normalizes it on a scale
299  * from 0...5 to match the usual five-star rating.
300  *
301  * Since: 0.1.5
302  */
303 void
grl_media_set_rating(GrlMedia * media,gfloat rating,gfloat max)304 grl_media_set_rating (GrlMedia *media, gfloat rating, gfloat max)
305 {
306   gfloat normalized_value;
307 
308   g_return_if_fail (GRL_IS_MEDIA (media));
309 
310   normalized_value = (rating * RATING_MAX) / max;
311   grl_data_set_float (GRL_DATA (media),
312 		      GRL_METADATA_KEY_RATING,
313 		      normalized_value);
314 }
315 
316 /**
317  * grl_media_set_url_data:
318  * @media: a #GrlMedia
319  * @url: the media's URL
320  * @mime: the @url mime type
321  * @bitrate: the @url bitrate, or -1 to ignore
322  * @framerate: media framerate, or -1 to ignore
323  * @width: media width, or -1 to ignore
324  * @height: media height, or -1 to ignore
325  *
326  * Sets all the keys related with the URL of a media resource in one go.
327  *
328  * Since: 0.3.0
329  **/
330 void
grl_media_set_url_data(GrlMedia * media,const gchar * url,const gchar * mime,gint bitrate,gfloat framerate,gint width,gint height)331 grl_media_set_url_data (GrlMedia *media,
332                         const gchar *url,
333                         const gchar *mime,
334                         gint bitrate,
335                         gfloat framerate,
336                         gint width,
337                         gint height)
338 {
339   GrlRelatedKeys *relkeys;
340 
341   g_return_if_fail (GRL_IS_MEDIA (media));
342 
343   relkeys = grl_related_keys_new ();
344   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_URL, url);
345   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_MIME, mime);
346   if (bitrate >= 0) {
347     grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_BITRATE, bitrate);
348   }
349   if (framerate >= 0) {
350     grl_related_keys_set_float (relkeys, GRL_METADATA_KEY_FRAMERATE, framerate);
351   }
352   if (width >= 0) {
353     grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_WIDTH, width);
354   }
355   if (height >= 0) {
356     grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_HEIGHT, height);
357   }
358   grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
359 }
360 
361 /**
362  * grl_media_add_url_data:
363  * @media: a #GrlMedia
364  * @url: a media's URL
365  * @mime: th @url mime type
366  * @bitrate: the @url bitrate, or -1 to ignore
367  * @framerate: media framerate, or -1 to ignore
368  * @width: media width, or -1 to ignore
369  * @height: media height, or -1 to ignore
370  *
371  * Sets all the keys related with the URL of a media resource and adds it to
372  * @media (useful for resources with more than one URL).
373  *
374  * Since: 0.3.0
375  **/
376 void
grl_media_add_url_data(GrlMedia * media,const gchar * url,const gchar * mime,gint bitrate,gfloat framerate,gint width,gint height)377 grl_media_add_url_data (GrlMedia *media,
378                         const gchar *url,
379                         const gchar *mime,
380                         gint bitrate,
381                         gfloat framerate,
382                         gint width,
383                         gint height)
384 {
385   GrlRelatedKeys *relkeys;
386 
387   g_return_if_fail (GRL_IS_MEDIA (media));
388 
389   relkeys = grl_related_keys_new ();
390   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_URL, url);
391   grl_related_keys_set_string (relkeys, GRL_METADATA_KEY_MIME, mime);
392   if (bitrate >= 0) {
393     grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_BITRATE, bitrate);
394   }
395   if (framerate >= 0) {
396     grl_related_keys_set_float (relkeys, GRL_METADATA_KEY_FRAMERATE, framerate);
397   }
398   if (width >= 0) {
399     grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_WIDTH, width);
400   }
401   if (height >= 0) {
402     grl_related_keys_set_int (relkeys, GRL_METADATA_KEY_HEIGHT, height);
403   }
404   grl_data_add_related_keys (GRL_DATA (media), relkeys);
405 }
406 
407 /**
408  * grl_media_add_author:
409  * @media: a #GrlMedia
410  * @author: an author for @media
411  *
412  * Adds a new author to @media.
413  *
414  * Since: 0.1.10
415  **/
416 void
grl_media_add_author(GrlMedia * media,const gchar * author)417 grl_media_add_author (GrlMedia *media, const gchar *author)
418 {
419   g_return_if_fail (GRL_IS_MEDIA (media));
420 
421   grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_AUTHOR, author);
422 }
423 
424 /**
425  * grl_media_add_thumbnail:
426  * @media: a #GrlMedia
427  * @thumbnail: a thumbnail for @media
428  *
429  * Adds a new thumbnail to @media.
430  *
431  * Since: 0.1.10
432  **/
433 void
grl_media_add_thumbnail(GrlMedia * media,const gchar * thumbnail)434 grl_media_add_thumbnail (GrlMedia *media, const gchar *thumbnail)
435 {
436   g_return_if_fail (GRL_IS_MEDIA (media));
437 
438   grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL, thumbnail);
439 }
440 
441 /**
442  * grl_media_add_thumbnail_binary:
443  * @media: a #GrlMedia
444  * @thumbnail: a buffer containing the thumbnail for @media
445  * @size: size of buffer
446  *
447  * Adds a new thumbnail to @media.
448  *
449  * Since: 0.1.10
450  **/
451 void
grl_media_add_thumbnail_binary(GrlMedia * media,const guint8 * thumbnail,gsize size)452 grl_media_add_thumbnail_binary (GrlMedia *media,
453                                 const guint8 *thumbnail,
454                                 gsize size)
455 {
456   g_return_if_fail (GRL_IS_MEDIA (media));
457   g_return_if_fail (size == 0 || thumbnail != NULL);
458 
459   grl_data_add_binary (GRL_DATA (media),
460                        GRL_METADATA_KEY_THUMBNAIL_BINARY,
461                        thumbnail,
462                        size);
463 }
464 
465 /**
466  * grl_media_add_external_player:
467  * @media: a #GrlMedia
468  * @player: an external player for @media
469  *
470  * Adds a new external player to @media.
471  *
472  * Since: 0.1.10
473  **/
474 void
grl_media_add_external_player(GrlMedia * media,const gchar * player)475 grl_media_add_external_player (GrlMedia *media, const gchar *player)
476 {
477   g_return_if_fail (GRL_IS_MEDIA (media));
478 
479   grl_data_add_string (GRL_DATA (media),
480                        GRL_METADATA_KEY_EXTERNAL_PLAYER,
481                        player);
482 }
483 
484 /**
485  * grl_media_add_external_url:
486  * @media: a #GrlMedia
487  * @url: an external url for @media
488  *
489  * Adds a new external url to @media.
490  *
491  * Since: 0.1.10
492  **/
493 void
grl_media_add_external_url(GrlMedia * media,const gchar * url)494 grl_media_add_external_url (GrlMedia *media, const gchar *url)
495 {
496   g_return_if_fail (GRL_IS_MEDIA (media));
497 
498   grl_data_add_string (GRL_DATA (media),
499                        GRL_METADATA_KEY_EXTERNAL_URL,
500                        url);
501 }
502 
503 /**
504  * grl_media_add_keyword:
505  * @media: a #GrlMedia
506  * @keyword: a keyword describing the media
507  *
508  * Adds the keyword describing the @media.
509  *
510  * Since: 0.2.3
511  */
512 void
grl_media_add_keyword(GrlMedia * media,const gchar * keyword)513 grl_media_add_keyword (GrlMedia *media,
514                        const gchar *keyword)
515 {
516   g_return_if_fail (GRL_IS_MEDIA (media));
517 
518   grl_data_add_string (GRL_DATA (media),
519                        GRL_METADATA_KEY_KEYWORD,
520                        keyword);
521 }
522 
523 /**
524  * grl_media_add_artist:
525  * @media: the media instance
526  * @artist: an audio's artist
527  *
528  * Adds a new artist to @media.
529  *
530  * Since: 0.3.0
531  **/
532 void
grl_media_add_artist(GrlMedia * media,const gchar * artist)533 grl_media_add_artist (GrlMedia *media, const gchar *artist)
534 {
535   g_return_if_fail (GRL_IS_MEDIA (media));
536   grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST, artist);
537 }
538 
539 /**
540  * grl_media_add_genre:
541  * @media: the media instance
542  * @genre: an audio's genre
543  *
544  * Adds a new genre to @media.
545  *
546  * Since: 0.3.0
547  **/
548 void
grl_media_add_genre(GrlMedia * media,const gchar * genre)549 grl_media_add_genre (GrlMedia *media, const gchar *genre)
550 {
551   g_return_if_fail (GRL_IS_MEDIA (media));
552   grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE, genre);
553 }
554 
555 /**
556  * grl_media_add_lyrics:
557  * @media: the media instance
558  * @lyrics: an audio's lyrics
559  *
560  * Adds a new lyrics to @media.
561  *
562  * Since: 0.3.0
563  **/
564 void
grl_media_add_lyrics(GrlMedia * media,const gchar * lyrics)565 grl_media_add_lyrics (GrlMedia *media, const gchar *lyrics)
566 {
567   g_return_if_fail (GRL_IS_MEDIA (media));
568   grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_LYRICS, lyrics);
569 }
570 
571 /**
572  * grl_media_add_mb_artist_id:
573  * @media: the media instance
574  * @mb_artist_id: a MusicBrainz artist identifier
575  *
576  * Adds a new MusicBrainz artist id to @media.
577  *
578  * Since: 0.3.0
579  **/
580 void
grl_media_add_mb_artist_id(GrlMedia * media,const gchar * mb_artist_id)581 grl_media_add_mb_artist_id (GrlMedia *media,
582                             const gchar *mb_artist_id)
583 {
584   g_return_if_fail (GRL_IS_MEDIA (media));
585   grl_data_add_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ARTIST_ID,
586                        mb_artist_id);
587 }
588 
589 /**
590  * grl_media_add_performer:
591  * @media: a #GrlMedia
592  * @performer: an actor performing in the movie
593  *
594  * Adds the actor performing in the movie.
595  *
596  * Since: 0.3.0
597  */
598 void
grl_media_add_performer(GrlMedia * media,const gchar * performer)599 grl_media_add_performer (GrlMedia *media,
600                          const gchar *performer)
601 {
602   g_return_if_fail (GRL_IS_MEDIA (media));
603   grl_data_add_string (GRL_DATA (media),
604                        GRL_METADATA_KEY_PERFORMER,
605                        performer);
606 }
607 
608 /**
609  * grl_media_add_producer:
610  * @media: a #GrlMedia
611  * @producer: producer of the movie
612  *
613  * Adds the producer of the media.
614  *
615  * Since: 0.3.0
616  */
617 void
grl_media_add_producer(GrlMedia * media,const gchar * producer)618 grl_media_add_producer (GrlMedia *media,
619                         const gchar *producer)
620 {
621   g_return_if_fail (GRL_IS_MEDIA (media));
622   grl_data_add_string (GRL_DATA (media),
623                        GRL_METADATA_KEY_PRODUCER,
624                        producer);
625 }
626 
627 /**
628  * grl_media_add_director:
629  * @media: a #GrlMedia
630  * @director: director of the movie
631  *
632  * Adds the director of the media
633  *
634  * Since: 0.3.0
635  */
636 void
grl_media_add_director(GrlMedia * media,const gchar * director)637 grl_media_add_director (GrlMedia *media,
638                         const gchar *director)
639 {
640   g_return_if_fail (GRL_IS_MEDIA (media));
641   grl_data_add_string (GRL_DATA (media),
642                        GRL_METADATA_KEY_DIRECTOR,
643                        director);
644 }
645 
646 /**
647  * grl_media_serialize:
648  * @media: a #GrlMedia
649  *
650  * Serializes a GrlMedia into a string. It does a basic serialization.
651  *
652  * See grl_media_serialize_extended() to get more serialization approaches.
653  *
654  * Returns: serialized media
655  *
656  * Since: 0.1.6
657  **/
658 gchar *
grl_media_serialize(GrlMedia * media)659 grl_media_serialize (GrlMedia *media)
660 {
661   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
662 
663   return grl_media_serialize_extended (media, GRL_MEDIA_SERIALIZE_BASIC);
664 }
665 
666 /**
667  * grl_media_serialize_extended:
668  * @media: a #GrlMedia
669  * @serial_type: type of serialization
670  * @...: media keys to serialize
671  *
672  * Serializes a GrlMedia into a string.
673  *
674  * See grl_media_unserialize() to recover back the GrlMedia from the string.
675  *
676  * If serialization type is @GRL_MEDIA_SERIALIZE_PARTIAL then it requires a
677  * @GList with the properties to consider in serialization (id and source are
678  * always considered).
679  *
680  * Returns: serialized media
681  *
682  * Since: 0.1.6
683  **/
684 gchar *
grl_media_serialize_extended(GrlMedia * media,GrlMediaSerializeType serial_type,...)685 grl_media_serialize_extended (GrlMedia *media,
686                               GrlMediaSerializeType serial_type,
687                               ...)
688 {
689   GByteArray *binary_blob;
690   GList *key;
691   GList *keylist;
692   GString *serial;
693   GrlKeyID grlkey;
694   GrlRegistry *registry;
695   GrlRelatedKeys *relkeys;
696   const GValue *value;
697   const gchar *id;
698   const gchar *source;
699   gchar *base64_blob;
700   gchar *iso8601_datetime;
701   gchar *protocol;
702   gchar *serial_media;
703   gchar separator = '?';
704   guint i;
705   guint num_values;
706   va_list va_serial;
707 
708   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
709   g_return_val_if_fail ((source = grl_media_get_source (media)), NULL);
710 
711   /* Check serialization type */
712   switch (serial_type) {
713   case GRL_MEDIA_SERIALIZE_FULL:
714     registry = grl_registry_get_default ();
715     keylist = grl_registry_get_metadata_keys (registry);
716     serial_media = grl_media_serialize_extended (media,
717                                                  GRL_MEDIA_SERIALIZE_PARTIAL,
718                                                  keylist);
719     g_list_free (keylist);
720     break;
721   case GRL_MEDIA_SERIALIZE_BASIC:
722   case GRL_MEDIA_SERIALIZE_PARTIAL:
723     switch (grl_media_get_media_type (media)) {
724     case GRL_MEDIA_TYPE_AUDIO:
725       protocol = "grlaudio://";
726       break;
727     case GRL_MEDIA_TYPE_VIDEO:
728       protocol = "grlvideo://";
729       break;
730     case GRL_MEDIA_TYPE_IMAGE:
731       protocol = "grlimage://";
732       break;
733     case GRL_MEDIA_TYPE_CONTAINER:
734       protocol = "grlcontainer://";
735       break;
736     default:
737       protocol = "grl";
738     }
739 
740     /* Build serial string with escaped components */
741     serial = g_string_sized_new (SERIAL_STRING_ALLOC);
742     g_string_assign (serial, protocol);
743     g_string_append_uri_escaped (serial, source, NULL, TRUE);
744     id = grl_media_get_id (media);
745     if (id) {
746       g_string_append_c (serial, '/');
747       g_string_append_uri_escaped (serial, id, NULL, TRUE);
748     }
749 
750     /* Include all properties */
751     if (serial_type == GRL_MEDIA_SERIALIZE_PARTIAL) {
752 
753       va_start (va_serial, serial_type);
754       keylist = va_arg (va_serial, GList *);
755       for (key = keylist; key; key = g_list_next (key)) {
756         grlkey = GRLPOINTER_TO_KEYID (key->data);
757         /* Skip id and source keys */
758         if (grlkey == GRL_METADATA_KEY_ID ||
759             grlkey == GRL_METADATA_KEY_SOURCE) {
760           continue;
761         }
762         num_values = grl_data_length (GRL_DATA (media), grlkey);
763         for (i = 0; i < num_values; i++) {
764 
765           g_string_append_c (serial, separator);
766           if (separator == '?') {
767             separator = '&';
768           }
769 
770           g_string_append_printf (serial,
771                                   "%s=",
772                                   GRL_METADATA_KEY_GET_NAME (grlkey));
773 
774           relkeys = grl_data_get_related_keys (GRL_DATA (media), grlkey, i);
775           if (!grl_related_keys_has_key (relkeys, grlkey)) {
776             continue;
777           }
778 
779           value = grl_related_keys_get (relkeys, grlkey);
780 
781           if (G_VALUE_HOLDS_STRING (value)) {
782             g_string_append_uri_escaped (serial,
783                                          g_value_get_string (value),
784                                          NULL,
785                                          TRUE);
786           } else if (G_VALUE_HOLDS_INT (value)) {
787             g_string_append_printf (serial, "%d", g_value_get_int (value));
788           } else if (G_VALUE_HOLDS_FLOAT (value)) {
789             g_string_append_printf (serial, "%f", g_value_get_float (value));
790           } else if (G_VALUE_HOLDS_BOOLEAN (value)) {
791             g_string_append_printf (serial, "%d", g_value_get_boolean (value));
792           } else if (G_VALUE_TYPE (value) == G_TYPE_BYTE_ARRAY) {
793             binary_blob = g_value_get_boxed (value);
794             base64_blob = g_base64_encode (binary_blob->data, binary_blob->len);
795             g_string_append_uri_escaped (serial,
796                                          base64_blob,
797                                          NULL,
798                                          TRUE);
799             g_free (base64_blob);
800           } else if (G_VALUE_TYPE (value) == G_TYPE_DATE_TIME) {
801             iso8601_datetime = g_date_time_format (g_value_get_boxed (value),
802                                                    "%FT%T");
803             g_string_append_uri_escaped (serial,
804                                          iso8601_datetime,
805                                          NULL,
806                                          TRUE);
807             g_free (iso8601_datetime);
808           }
809         }
810       }
811 
812       va_end (va_serial);
813     }
814     serial_media = g_string_free (serial, FALSE);
815     break;
816   default:
817     serial_media = NULL;
818   }
819 
820   return serial_media;
821 }
822 
823 static void
_insert_and_free_related_list(GrlKeyID key,GList * relkeys_list,GrlData * data)824 _insert_and_free_related_list (GrlKeyID key,
825                                GList *relkeys_list,
826                                GrlData *data)
827 {
828   GList *p = relkeys_list;
829 
830   while (p) {
831     grl_data_add_related_keys (data, (GrlRelatedKeys *) p->data);
832     p = g_list_next (p);
833   }
834 
835   g_list_free (relkeys_list);
836 }
837 
838 /**
839  * grl_media_unserialize:
840  * @serial: a serialized media
841  *
842  * Unserializes a GrlMedia.
843  *
844  * Returns: (transfer full): the GrlMedia from the serial
845  *
846  * Since: 0.1.6
847  **/
848 GrlMedia *
grl_media_unserialize(const gchar * serial)849 grl_media_unserialize (const gchar *serial)
850 {
851   GDateTime *datetime;
852   GHashTable *grlkey_related_table;
853   GList *keys;
854   GList *relkeys_list;
855   GMatchInfo *match_info;
856   GRegex *query_regex;
857   GRegex *uri_regex;
858   GType type_grlkey;
859   GrlKeyID grlkey;
860   GrlKeyID grlkey_index;
861   GrlMedia *media;
862   GrlRegistry *registry;
863   GrlRelatedKeys *relkeys;
864   gboolean append;
865   gchar *escaped_value;
866   gchar *keyname;
867   gchar *protocol;
868   gchar *query;
869   gchar *value;
870   gpointer p;
871   gsize blob_size;
872   guchar *blob;
873   guint *grlkey_count;
874 
875   g_return_val_if_fail (serial, NULL);
876 
877   uri_regex =
878     g_regex_new ("^(grl.*):\\/\\/([^\\///?]+)(\\/[^\\?]*)?(?:\\?(.*))?",
879                  G_REGEX_CASELESS,
880                  0,
881                  NULL);
882   if (!g_regex_match (uri_regex, serial, 0, &match_info)) {
883     GRL_WARNING ("Wrong serial %s", serial);
884     g_regex_unref (uri_regex);
885     return NULL;
886   }
887 
888   /* Build the media */
889   protocol = g_match_info_fetch (match_info, 1);
890   if (g_strcmp0 (protocol, "grlaudio") == 0) {
891     media = grl_media_audio_new ();
892   } else if (g_strcmp0 (protocol, "grlvideo") == 0) {
893     media = grl_media_video_new ();
894   } else if (g_strcmp0 (protocol, "grlimage") == 0) {
895     media = grl_media_image_new ();
896   } else if (g_strcmp0 (protocol, "grlcontainer") == 0) {
897     media = grl_media_container_new ();
898   } else if (g_strcmp0 (protocol, "grl") == 0) {
899     media = grl_media_new ();
900   } else {
901     GRL_WARNING ("Unknown type %s", protocol);
902     g_match_info_free (match_info);
903     return NULL;
904   }
905 
906   /* Add source */
907   escaped_value = g_match_info_fetch (match_info, 2);
908   value = g_uri_unescape_string (escaped_value, NULL);
909   grl_media_set_source (media, value);
910   g_free (escaped_value);
911   g_free (value);
912 
913   /* Add id */
914   escaped_value = g_match_info_fetch (match_info, 3);
915   if (escaped_value && escaped_value[0] == '/') {
916     guint len = strlen (escaped_value);
917     if (len > 2 && escaped_value[len - 1] == '/')
918       escaped_value[len - 1] = '\0';
919     value = g_uri_unescape_string (escaped_value + 1, NULL);
920     grl_media_set_id (media, value);
921     g_free (value);
922   }
923   g_free (escaped_value);
924 
925   /* Check if there are more properties */
926   query = g_match_info_fetch (match_info, 4);
927   g_match_info_free (match_info);
928   if (query) {
929     registry = grl_registry_get_default ();
930     keys = grl_registry_get_metadata_keys (registry);
931     /* This is a hack: we do it because we know GrlKeyID are actually integers,
932        and assigned sequentially (0 is for invalid key). This saves us to use a
933        hashtable to store the counter per key */
934     grlkey_count = g_new0 (guint, g_list_length(keys) + 1);
935     g_list_free (keys);
936 
937     /* In this hashtable we enqueue all the GrlRelatedKeys, that will be added
938        at the end; we can not add them directly because could be we have a
939        GrlRelatedKeys with no values because one of the properties will come
940        later; and we can not add empty values in data */
941     grlkey_related_table = g_hash_table_new (g_direct_hash, g_direct_equal);
942 
943     query_regex = g_regex_new ("([^=&]+)=([^=&]*)", 0, 0, NULL);
944     g_regex_match (query_regex, query, 0, &match_info);
945     while (g_match_info_matches (match_info)) {
946       keyname = g_match_info_fetch (match_info, 1);
947       grlkey = grl_registry_lookup_metadata_key (registry, keyname);
948       if (grlkey) {
949         /* Search for the GrlRelatedKeys to insert the key, or create a new one */
950         grlkey_index =
951           GRLPOINTER_TO_KEYID (g_list_nth_data ((GList *) grl_registry_lookup_metadata_key_relation (registry, grlkey), 0));
952         relkeys_list = g_hash_table_lookup (grlkey_related_table,
953                                             GRLKEYID_TO_POINTER (grlkey_index));
954         p = g_list_nth_data (relkeys_list, grlkey_count[grlkey]);
955         if (p) {
956           relkeys = (GrlRelatedKeys *) p;
957           append = FALSE;
958         } else {
959           relkeys = grl_related_keys_new ();
960           append = TRUE;
961         }
962         escaped_value = g_match_info_fetch (match_info, 2);
963         if (escaped_value && escaped_value[0] != '\0') {
964           value = g_uri_unescape_string (escaped_value, NULL);
965           type_grlkey = GRL_METADATA_KEY_GET_TYPE (grlkey);
966           if (type_grlkey == G_TYPE_STRING) {
967             grl_related_keys_set_string (relkeys, grlkey, value);
968           } else if (type_grlkey == G_TYPE_INT) {
969             grl_related_keys_set_int (relkeys, grlkey, atoi (value));
970           } else if (type_grlkey == G_TYPE_FLOAT) {
971             grl_related_keys_set_float (relkeys, grlkey, atof (value));
972           } else if (type_grlkey == G_TYPE_BOOLEAN) {
973             grl_related_keys_set_boolean (relkeys, grlkey, atoi (value) == 0? FALSE: TRUE);
974           } else if (type_grlkey == G_TYPE_BYTE_ARRAY) {
975             blob = g_base64_decode (value, &blob_size);
976             grl_related_keys_set_binary (relkeys, grlkey, blob, blob_size);
977             g_free (blob);
978           } else if (type_grlkey == G_TYPE_DATE_TIME) {
979             datetime = grl_date_time_from_iso8601 (value);
980             grl_related_keys_set_boxed (relkeys, grlkey, datetime);
981             g_date_time_unref (datetime);
982           }
983           g_free (escaped_value);
984           g_free (value);
985         }
986         if (append) {
987           relkeys_list = g_list_append (relkeys_list, relkeys);
988           g_hash_table_insert (grlkey_related_table,
989                                GRLKEYID_TO_POINTER (grlkey_index),
990                                relkeys_list);
991         }
992         grlkey_count[grlkey]++;
993       }
994       g_free (keyname);
995       g_match_info_next (match_info, NULL);
996     }
997     /* Now we can add all the GrlRelatedKeys into media */
998     g_hash_table_foreach (grlkey_related_table,
999                           (GHFunc) _insert_and_free_related_list,
1000                           GRL_DATA (media));
1001     g_hash_table_unref (grlkey_related_table);
1002     g_match_info_free (match_info);
1003     g_free (query);
1004     g_free (grlkey_count);
1005   }
1006 
1007   return media;
1008 }
1009 
1010 /**
1011  * grl_media_set_id:
1012  * @media: the media
1013  * @id: the identifier of the media
1014  *
1015  * Set the media identifier
1016  *
1017  * Since: 0.1.4
1018  */
1019 void
grl_media_set_id(GrlMedia * media,const gchar * id)1020 grl_media_set_id (GrlMedia *media, const gchar *id)
1021 {
1022   g_return_if_fail (GRL_IS_MEDIA (media));
1023 
1024   grl_data_set_string (GRL_DATA (media),
1025                        GRL_METADATA_KEY_ID,
1026                        id);
1027 }
1028 
1029 /**
1030  * grl_media_set_url:
1031  * @media: the media
1032  * @url: the media's URL
1033  *
1034  * Set the media's URL
1035  *
1036  * Since: 0.1.4
1037  */
1038 void
grl_media_set_url(GrlMedia * media,const gchar * url)1039 grl_media_set_url (GrlMedia *media, const gchar *url)
1040 {
1041   g_return_if_fail (GRL_IS_MEDIA (media));
1042 
1043   grl_data_set_string (GRL_DATA (media),
1044                        GRL_METADATA_KEY_URL,
1045                        url);
1046 }
1047 
1048 /**
1049  * grl_media_set_author:
1050  * @media: the media
1051  * @author: the media's author
1052  *
1053  * Set the media's author
1054  *
1055  * Since: 0.1.4
1056  */
1057 void
grl_media_set_author(GrlMedia * media,const gchar * author)1058 grl_media_set_author (GrlMedia *media, const gchar *author)
1059 {
1060   g_return_if_fail (GRL_IS_MEDIA (media));
1061 
1062   grl_data_set_string (GRL_DATA (media),
1063                        GRL_METADATA_KEY_AUTHOR,
1064                        author);
1065 }
1066 
1067 /**
1068  * grl_media_set_title:
1069  * @media: the media
1070  * @title: the title
1071  *
1072  * Set the media's title
1073  *
1074  * Since: 0.1.4
1075  */
1076 void
grl_media_set_title(GrlMedia * media,const gchar * title)1077 grl_media_set_title (GrlMedia *media, const gchar *title)
1078 {
1079   g_return_if_fail (GRL_IS_MEDIA (media));
1080 
1081   grl_data_set_string (GRL_DATA (media),
1082                        GRL_METADATA_KEY_TITLE,
1083                        title);
1084 }
1085 
1086 /**
1087  * grl_media_set_description:
1088  * @media: the media
1089  * @description: the description
1090  *
1091  * Set the media's description
1092  *
1093  * Since: 0.1.4
1094  */
1095 void
grl_media_set_description(GrlMedia * media,const gchar * description)1096 grl_media_set_description (GrlMedia *media, const gchar *description)
1097 {
1098   g_return_if_fail (GRL_IS_MEDIA (media));
1099 
1100   grl_data_set_string (GRL_DATA (media),
1101                        GRL_METADATA_KEY_DESCRIPTION,
1102                        description);
1103 }
1104 
1105 /**
1106  * grl_media_set_source:
1107  * @media: the media
1108  * @source: the source
1109  *
1110  * Set the media's source
1111  *
1112  * Since: 0.1.4
1113  */
1114 void
grl_media_set_source(GrlMedia * media,const gchar * source)1115 grl_media_set_source (GrlMedia *media, const gchar *source)
1116 {
1117   g_return_if_fail (GRL_IS_MEDIA (media));
1118 
1119   grl_data_set_string (GRL_DATA (media),
1120                        GRL_METADATA_KEY_SOURCE,
1121                        source);
1122 }
1123 
1124 /**
1125  * grl_media_set_thumbnail:
1126  * @media: the media
1127  * @thumbnail: the thumbnail URL
1128  *
1129  * Set the media's thumbnail URL
1130  *
1131  * Since: 0.1.4
1132  */
1133 void
grl_media_set_thumbnail(GrlMedia * media,const gchar * thumbnail)1134 grl_media_set_thumbnail (GrlMedia *media, const gchar *thumbnail)
1135 {
1136   g_return_if_fail (GRL_IS_MEDIA (media));
1137 
1138   grl_data_set_string (GRL_DATA (media),
1139                        GRL_METADATA_KEY_THUMBNAIL,
1140                        thumbnail);
1141 }
1142 
1143 /**
1144  * grl_media_set_thumbnail_binary:
1145  * @media: the media
1146  * @thumbnail: thumbnail buffer
1147  * @size: thumbnail buffer size
1148  *
1149  * Set the media's binary thumbnail
1150  *
1151  * Since: 0.1.9
1152  */
1153 void
grl_media_set_thumbnail_binary(GrlMedia * media,const guint8 * thumbnail,gsize size)1154 grl_media_set_thumbnail_binary (GrlMedia *media,
1155                                 const guint8 *thumbnail,
1156                                 gsize size)
1157 {
1158   g_return_if_fail (GRL_IS_MEDIA (media));
1159   g_return_if_fail (size == 0 || thumbnail != NULL);
1160 
1161   grl_data_set_binary (GRL_DATA (media),
1162                        GRL_METADATA_KEY_THUMBNAIL_BINARY,
1163                        thumbnail,
1164                        size);
1165 }
1166 
1167 /**
1168  * grl_media_set_site:
1169  * @media: the media
1170  * @site: the site
1171  *
1172  * Set the media's site. A site is a website about the media such as a
1173  * studio's promotional website for a movie.
1174  *
1175  * Since: 0.1.4
1176  */
1177 void
grl_media_set_site(GrlMedia * media,const gchar * site)1178 grl_media_set_site (GrlMedia *media, const gchar *site)
1179 {
1180   g_return_if_fail (GRL_IS_MEDIA (media));
1181 
1182   grl_data_set_string (GRL_DATA (media),
1183                        GRL_METADATA_KEY_SITE,
1184                        site);
1185 }
1186 
1187 /**
1188  * grl_media_set_duration:
1189  * @media: the media
1190  * @duration: the duration in seconds
1191  *
1192  * Set the media's duration
1193  *
1194  * Since: 0.1.4
1195  */
1196 void
grl_media_set_duration(GrlMedia * media,gint duration)1197 grl_media_set_duration (GrlMedia *media, gint duration)
1198 {
1199   g_return_if_fail (GRL_IS_MEDIA (media));
1200 
1201   grl_data_set_int (GRL_DATA (media),
1202                     GRL_METADATA_KEY_DURATION,
1203                     duration);
1204 }
1205 
1206 /**
1207  * grl_media_set_publication_date:
1208  * @media: the media
1209  * @date: the date
1210  *
1211  * Set the publication date of @media.
1212  *
1213  * Since: 0.2.0
1214  */
1215 void
grl_media_set_publication_date(GrlMedia * media,const GDateTime * date)1216 grl_media_set_publication_date (GrlMedia *media, const GDateTime *date)
1217 {
1218   g_return_if_fail (GRL_IS_MEDIA (media));
1219 
1220   grl_data_set_boxed (GRL_DATA (media),
1221                       GRL_METADATA_KEY_PUBLICATION_DATE,
1222                       date);
1223 }
1224 
1225 /**
1226  * grl_media_set_region:
1227  * @media: a #GrlMedia
1228  * @region: the region's ISO-3166-1 code
1229  *
1230  * Sets the @region where @media was published.
1231  *
1232  * Since: 0.2.3
1233  */
1234 void
grl_media_set_region(GrlMedia * media,const gchar * region)1235 grl_media_set_region (GrlMedia *media,
1236                       const gchar *region)
1237 {
1238   g_return_if_fail (GRL_IS_MEDIA (media));
1239 
1240   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_REGION, region);
1241 }
1242 
1243 /**
1244  * grl_media_set_region_data:
1245  * @media: a #GrlMedia
1246  * @region: the region's ISO-3166-1 code
1247  * @publication_date: the publication date
1248  * @certificate: the age certification
1249  *
1250  * Sets regional publication and certification information for @region.
1251  *
1252  * Since: 0.2.3
1253  */
1254 void
grl_media_set_region_data(GrlMedia * media,const gchar * region,const GDateTime * publication_date,const gchar * certificate)1255 grl_media_set_region_data (GrlMedia *media,
1256                            const gchar *region,
1257                            const GDateTime *publication_date,
1258                            const gchar *certificate)
1259 {
1260   GrlRelatedKeys *relkeys;
1261 
1262   g_return_if_fail (GRL_IS_MEDIA (media));
1263 
1264   relkeys = grl_related_keys_new ();
1265 
1266   grl_related_keys_set_string (relkeys,
1267                                GRL_METADATA_KEY_REGION,
1268                                region);
1269   grl_related_keys_set_boxed (relkeys,
1270                               GRL_METADATA_KEY_PUBLICATION_DATE,
1271                               publication_date);
1272   grl_related_keys_set_string (relkeys,
1273                                GRL_METADATA_KEY_CERTIFICATE,
1274                                certificate);
1275   grl_data_set_related_keys (GRL_DATA (media), relkeys, 0);
1276 }
1277 
1278 /**
1279  * grl_media_add_region_data:
1280  * @media: a #GrlMedia
1281  * @region: the region's ISO-3166-1 code
1282  * @publication_date: the publication date
1283  * @certificate: the age certification
1284  *
1285  * Adds regional publication and certification information for @region.
1286  *
1287  * Since: 0.2.3
1288  */
1289 void
grl_media_add_region_data(GrlMedia * media,const gchar * region,const GDateTime * publication_date,const gchar * certificate)1290 grl_media_add_region_data (GrlMedia *media,
1291                            const gchar *region,
1292                            const GDateTime *publication_date,
1293                            const gchar *certificate)
1294 {
1295   GrlRelatedKeys *relkeys;
1296 
1297   g_return_if_fail (GRL_IS_MEDIA (media));
1298 
1299   relkeys = grl_related_keys_new ();
1300   grl_related_keys_set_string (relkeys,
1301                                GRL_METADATA_KEY_REGION,
1302                                region);
1303   grl_related_keys_set_boxed (relkeys,
1304                               GRL_METADATA_KEY_PUBLICATION_DATE,
1305                               publication_date);
1306   grl_related_keys_set_string (relkeys,
1307                                GRL_METADATA_KEY_CERTIFICATE,
1308                                certificate);
1309   grl_data_add_related_keys (GRL_DATA (media), relkeys);
1310 }
1311 
1312 /**
1313   * grl_media_set_creation_date:
1314   * @media: the media
1315   * @creation_date: date when media was created
1316   *
1317   * Set the creation_date of the media
1318   *
1319   * Since: 0.2.0
1320   */
1321 void
grl_media_set_creation_date(GrlMedia * media,const GDateTime * creation_date)1322 grl_media_set_creation_date (GrlMedia *media,
1323                              const GDateTime *creation_date)
1324 {
1325   g_return_if_fail (GRL_IS_MEDIA (media));
1326 
1327   grl_data_set_boxed (GRL_DATA (media),
1328                       GRL_METADATA_KEY_CREATION_DATE,
1329                       creation_date);
1330 }
1331 
1332 /**
1333   * grl_media_set_modification_date:
1334   * @media: the media
1335   * @modification_date: date when the media was last modified
1336   *
1337   * Set the modification date of the media
1338   *
1339   * Since: 0.2.0
1340   */
1341 void
grl_media_set_modification_date(GrlMedia * media,const GDateTime * modification_date)1342 grl_media_set_modification_date (GrlMedia *media,
1343                                  const GDateTime *modification_date)
1344 
1345 {
1346   g_return_if_fail (GRL_IS_MEDIA (media));
1347 
1348   grl_data_set_boxed (GRL_DATA (media),
1349                       GRL_METADATA_KEY_MODIFICATION_DATE,
1350                       modification_date);
1351 }
1352 
1353 /**
1354  * grl_media_set_mime:
1355  * @media: the media
1356  * @mime: the mime type
1357  *
1358  * Set the media's mime-type
1359  *
1360  * Since: 0.1.4
1361  */
1362 void
grl_media_set_mime(GrlMedia * media,const gchar * mime)1363 grl_media_set_mime (GrlMedia *media, const gchar *mime)
1364 {
1365   g_return_if_fail (GRL_IS_MEDIA (media));
1366 
1367   grl_data_set_string (GRL_DATA (media),
1368                        GRL_METADATA_KEY_MIME,
1369                        mime);
1370 }
1371 
1372 /**
1373  * grl_media_set_play_count:
1374  * @media: the media
1375  * @play_count: the play count
1376  *
1377  * Set the media play count
1378  *
1379  * Since: 0.1.4
1380  */
1381 void
grl_media_set_play_count(GrlMedia * media,gint play_count)1382 grl_media_set_play_count (GrlMedia *media, gint play_count)
1383 {
1384   g_return_if_fail (GRL_IS_MEDIA (media));
1385 
1386   grl_data_set_int (GRL_DATA (media),
1387                     GRL_METADATA_KEY_PLAY_COUNT,
1388                     play_count);
1389 }
1390 
1391 /**
1392  * grl_media_set_last_played:
1393  * @media: the media
1394  * @last_played: date when the media was last played
1395  *
1396  * Set the media last played date
1397  *
1398  * Since: 0.3.0
1399  */
1400 void
grl_media_set_last_played(GrlMedia * media,const GDateTime * last_played)1401 grl_media_set_last_played (GrlMedia *media, const GDateTime *last_played)
1402 {
1403   g_return_if_fail (GRL_IS_MEDIA (media));
1404 
1405   grl_data_set_boxed (GRL_DATA (media),
1406                       GRL_METADATA_KEY_LAST_PLAYED,
1407                       last_played);
1408 }
1409 
1410 /**
1411  * grl_media_set_last_position:
1412  * @media: the media
1413  * @last_position: second at which the media playback was interrupted
1414  *
1415  * Set the media last played position
1416  *
1417  * Since: 0.1.4
1418  */
1419 void
grl_media_set_last_position(GrlMedia * media,gint last_position)1420 grl_media_set_last_position (GrlMedia *media, gint last_position)
1421 {
1422   g_return_if_fail (GRL_IS_MEDIA (media));
1423 
1424   grl_data_set_int (GRL_DATA (media),
1425                     GRL_METADATA_KEY_LAST_POSITION,
1426                     last_position);
1427 }
1428 
1429 /**
1430  * grl_media_set_external_player:
1431  * @media: the media
1432  * @player: location of an external player for this media
1433  *
1434  * Set the location of a player for the media (usually a flash player)
1435  *
1436  * Since: 0.1.6
1437  */
1438 void
grl_media_set_external_player(GrlMedia * media,const gchar * player)1439 grl_media_set_external_player (GrlMedia *media, const gchar *player)
1440 {
1441   g_return_if_fail (GRL_IS_MEDIA (media));
1442 
1443   grl_data_set_string (GRL_DATA (media),
1444                        GRL_METADATA_KEY_EXTERNAL_PLAYER,
1445                        player);
1446 }
1447 
1448 /**
1449  * grl_media_set_external_url:
1450  * @media: the media
1451  * @url: external location where this media can be played.
1452  *
1453  * Set an external location where users can play the media
1454  *
1455  * Since: 0.1.6
1456  */
1457 void
grl_media_set_external_url(GrlMedia * media,const gchar * url)1458 grl_media_set_external_url (GrlMedia *media, const gchar *url)
1459 {
1460   g_return_if_fail (GRL_IS_MEDIA (media));
1461 
1462   grl_data_set_string (GRL_DATA (media),
1463                        GRL_METADATA_KEY_EXTERNAL_URL,
1464                        url);
1465 }
1466 
1467 /**
1468  * grl_media_set_studio:
1469  * @media: the media
1470  * @studio: The studio the media is from
1471  *
1472  * Set the media studio
1473  *
1474  * Since: 0.1.6
1475  */
1476 void
grl_media_set_studio(GrlMedia * media,const gchar * studio)1477 grl_media_set_studio (GrlMedia *media, const gchar *studio)
1478 {
1479   g_return_if_fail (GRL_IS_MEDIA (media));
1480 
1481   grl_data_set_string (GRL_DATA (media),
1482                        GRL_METADATA_KEY_STUDIO,
1483                        studio);
1484 }
1485 
1486 /**
1487  * grl_media_set_certificate:
1488  * @media: the media
1489  * @certificate: The age certificate of the media
1490  *
1491  * Set the media's first age certification.
1492  * This should usually be the media's most relevant
1493  * age certificate. Use grl_media_set_region_data() to
1494  * set other age certificates.
1495  *
1496  * Since: 0.1.6
1497  */
1498 void
grl_media_set_certificate(GrlMedia * media,const gchar * certificate)1499 grl_media_set_certificate (GrlMedia *media, const gchar *certificate)
1500 {
1501   g_return_if_fail (GRL_IS_MEDIA (media));
1502 
1503   grl_data_set_string (GRL_DATA (media),
1504                        GRL_METADATA_KEY_CERTIFICATE,
1505                        certificate);
1506 }
1507 
1508 /**
1509  * grl_media_set_license:
1510  * @media: the media
1511  * @license: The license of the media
1512  *
1513  * Set the media license
1514  *
1515  * Since: 0.1.6
1516  */
1517 void
grl_media_set_license(GrlMedia * media,const gchar * license)1518 grl_media_set_license (GrlMedia *media, const gchar *license)
1519 {
1520   g_return_if_fail (GRL_IS_MEDIA (media));
1521 
1522   grl_data_set_string (GRL_DATA (media),
1523                        GRL_METADATA_KEY_LICENSE,
1524                        license);
1525 }
1526 
1527 /**
1528  * grl_media_set_favourite:
1529  * @media: a media
1530  * @favourite: whether the item is favourite or not
1531  *
1532  * Set if the media is favourite or not
1533  *
1534  * Since: 0.2.3
1535  */
1536 void
grl_media_set_favourite(GrlMedia * media,gboolean favourite)1537 grl_media_set_favourite (GrlMedia *media, gboolean favourite)
1538 {
1539   g_return_if_fail (GRL_IS_MEDIA (media));
1540 
1541   grl_data_set_boolean (GRL_DATA (media),
1542                         GRL_METADATA_KEY_FAVOURITE,
1543                         favourite);
1544 }
1545 
1546 /**
1547  * grl_media_set_keyword:
1548  * @media: a #GrlMedia
1549  * @keyword: a keyword describing the media
1550  *
1551  * Sets the keyword describing the @media.
1552  *
1553  * Since: 0.2.3
1554  */
1555 void
grl_media_set_keyword(GrlMedia * media,const gchar * keyword)1556 grl_media_set_keyword (GrlMedia *media,
1557                        const gchar *keyword)
1558 {
1559   g_return_if_fail (GRL_IS_MEDIA (media));
1560 
1561   grl_data_set_string (GRL_DATA (media),
1562                        GRL_METADATA_KEY_KEYWORD,
1563                        keyword);
1564 }
1565 
1566 /**
1567  * grl_media_set_size:
1568  * @media: the media
1569  * @size: the size in bytes
1570  *
1571  * Set the size of the media
1572  *
1573  * Since: 0.2.10
1574  */
1575 void
grl_media_set_size(GrlMedia * media,gint64 size)1576 grl_media_set_size (GrlMedia *media, gint64 size)
1577 {
1578   g_return_if_fail (GRL_IS_MEDIA (media));
1579 
1580   grl_data_set_int64 (GRL_DATA (media),
1581                       GRL_METADATA_KEY_SIZE,
1582                       size);
1583 }
1584 
1585 /**
1586  * grl_media_set_track_number:
1587  * @media: the media instance
1588  * @track_number: the audio's track number
1589  *
1590  * Set the track number of the media
1591  *
1592  * Since: 0.3.0
1593  */
1594 void
grl_media_set_track_number(GrlMedia * media,gint track_number)1595 grl_media_set_track_number (GrlMedia *media, gint track_number)
1596 {
1597   g_return_if_fail (GRL_IS_MEDIA (media));
1598   grl_data_set_int (GRL_DATA (media), GRL_METADATA_KEY_TRACK_NUMBER,
1599                     track_number);
1600 }
1601 
1602 /**
1603  * grl_media_set_bitrate:
1604  * @media: the media instance
1605  * @bitrate: the audio's bitrate
1606  *
1607  * Set the bitrate of the media
1608  *
1609  * Since: 0.3.0
1610  */
1611 void
grl_media_set_bitrate(GrlMedia * media,gint bitrate)1612 grl_media_set_bitrate (GrlMedia *media, gint bitrate)
1613 {
1614   g_return_if_fail (GRL_IS_MEDIA (media));
1615   grl_data_set_int (GRL_DATA (media), GRL_METADATA_KEY_BITRATE,
1616                     bitrate);
1617 }
1618 
1619 /**
1620  * grl_media_set_mb_track_id:
1621  * @media: the media instance
1622  * @mb_track_id: the MusicBrainz track identifier
1623  *
1624  * Set the MusicBrainz track identifier of the media
1625  *
1626  * Since: 0.3.0
1627  */
1628 void
grl_media_set_mb_track_id(GrlMedia * media,const gchar * mb_track_id)1629 grl_media_set_mb_track_id (GrlMedia *media, const gchar *mb_track_id)
1630 {
1631   g_return_if_fail (GRL_IS_MEDIA (media));
1632   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_TRACK_ID,
1633                        mb_track_id);
1634 }
1635 
1636 /**
1637  * grl_media_set_mb_recording_id:
1638  * @media: the media instance
1639  * @mb_recording_id: the MusicBrainz recording identifier
1640  *
1641  * Set the MusicBrainz recording identifier of the media
1642  *
1643  * Since: 0.3.0
1644  */
1645 void
grl_media_set_mb_recording_id(GrlMedia * media,const gchar * mb_recording_id)1646 grl_media_set_mb_recording_id (GrlMedia *media,
1647                                const gchar *mb_recording_id)
1648 {
1649   g_return_if_fail (GRL_IS_MEDIA (media));
1650   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RECORDING_ID,
1651                        mb_recording_id);
1652 }
1653 
1654 /**
1655  * grl_media_set_mb_artist_id:
1656  * @media: the media instance
1657  * @mb_artist_id: the MusicBrainz artist identifier
1658  *
1659  * Set the MusicBrainz artist identifier of the media
1660  *
1661  * Since: 0.3.0
1662  */
1663 void
grl_media_set_mb_artist_id(GrlMedia * media,const gchar * mb_artist_id)1664 grl_media_set_mb_artist_id (GrlMedia *media, const gchar *mb_artist_id)
1665 {
1666   g_return_if_fail (GRL_IS_MEDIA (media));
1667   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ARTIST_ID,
1668                        mb_artist_id);
1669 }
1670 
1671 /**
1672  * grl_media_set_mb_album_id:
1673  * @media: the media instance
1674  * @mb_album_id: the MusicBrainz album identifier
1675  *
1676  * Set the MusicBrainz album identifier of the media
1677  *
1678  * Since: 0.3.0
1679  *
1680  * Deprecated: 0.3.8 in favor of more specific metadata-keys
1681  * GRL_METADATA_KEY_MB_RELEASE_ID and GRL_METADATA_KEY_MB_RELEASE_GROUP_ID
1682  */
1683 void
grl_media_set_mb_album_id(GrlMedia * media,const gchar * mb_album_id)1684 grl_media_set_mb_album_id (GrlMedia *media, const gchar *mb_album_id)
1685 {
1686   g_return_if_fail (GRL_IS_MEDIA (media));
1687   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ALBUM_ID,
1688                        mb_album_id);
1689 }
1690 
1691 /**
1692  * grl_media_set_mb_release_id:
1693  * @media: the media instance
1694  * @mb_release_id: Album release identifier in MusicBrainz
1695  *
1696  * Set the MusicBrainz release identifier of the media
1697  *
1698  * Since: 0.3.8
1699  */
1700 void
grl_media_set_mb_release_id(GrlMedia * media,const gchar * mb_release_id)1701 grl_media_set_mb_release_id (GrlMedia *media, const gchar *mb_release_id)
1702 {
1703   g_return_if_fail (GRL_IS_MEDIA (media));
1704   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RELEASE_ID,
1705                        mb_release_id);
1706 }
1707 
1708 /**
1709  * grl_media_set_mb_release_group_id:
1710  * @media: the media instance
1711  * @mb_release_group_id:  Album group release identifier in MusicBrainz
1712  *
1713  * Set the MusicBrainz Release Group identifier of the media
1714  *
1715  * Since: 0.3.8
1716  */
1717 void
grl_media_set_mb_release_group_id(GrlMedia * media,const gchar * mb_release_group_id)1718 grl_media_set_mb_release_group_id (GrlMedia *media, const gchar *mb_release_group_id)
1719 {
1720   g_return_if_fail (GRL_IS_MEDIA (media));
1721   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RELEASE_GROUP_ID,
1722                        mb_release_group_id);
1723 }
1724 
1725 /**
1726  * grl_media_set_lyrics:
1727  * @media: the media instance
1728  * @lyrics: the audio's lyrics
1729  *
1730  * Set the lyrics of the media
1731  *
1732  * Since: 0.3.0
1733  */
1734 void
grl_media_set_lyrics(GrlMedia * media,const gchar * lyrics)1735 grl_media_set_lyrics (GrlMedia *media, const gchar *lyrics)
1736 {
1737   g_return_if_fail (GRL_IS_MEDIA (media));
1738   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_LYRICS,
1739                        lyrics);
1740 }
1741 
1742 /**
1743  * grl_media_set_genre:
1744  * @media: the media instance
1745  * @genre: the audio's genre
1746  *
1747  * Set the genre of the media
1748  *
1749  * Since: 0.3.0
1750  */
1751 void
grl_media_set_genre(GrlMedia * media,const gchar * genre)1752 grl_media_set_genre (GrlMedia *media, const gchar *genre)
1753 {
1754   g_return_if_fail (GRL_IS_MEDIA (media));
1755   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE,
1756                        genre);
1757 }
1758 
1759 /**
1760  * grl_media_set_album:
1761  * @media: the media instance
1762  * @album: the audio's album
1763  *
1764  * Set the album of the media
1765  *
1766  * Since: 0.3.0
1767  */
1768 void
grl_media_set_album(GrlMedia * media,const gchar * album)1769 grl_media_set_album (GrlMedia *media, const gchar *album)
1770 {
1771   g_return_if_fail (GRL_IS_MEDIA (media));
1772   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM,
1773                        album);
1774 }
1775 
1776 /**
1777  * grl_media_set_album_artist:
1778  * @media: the media instance
1779  * @album_artist: the audio's album main artist
1780  *
1781  * Set the main artist of the album of the media
1782  *
1783  * Since: 0.3.1
1784  */
1785 void
grl_media_set_album_artist(GrlMedia * media,const gchar * album_artist)1786 grl_media_set_album_artist (GrlMedia *media, const gchar *album_artist)
1787 {
1788   g_return_if_fail (GRL_IS_MEDIA (media));
1789   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM_ARTIST,
1790                        album_artist);
1791 }
1792 
1793 /**
1794  * grl_media_set_album_disc_number:
1795  * @media: the media instance
1796  * @disc_number: the disc number within an album
1797  *
1798  * Set the disc number of the media for multi-disc album sets.
1799  *
1800  * Since: 0.3.1
1801  */
1802 void
grl_media_set_album_disc_number(GrlMedia * media,gint disc_number)1803 grl_media_set_album_disc_number (GrlMedia *media, gint disc_number)
1804 {
1805   g_return_if_fail (GRL_IS_MEDIA (media));
1806   grl_data_set_int (GRL_DATA (media),
1807                     GRL_METADATA_KEY_ALBUM_DISC_NUMBER,
1808                     disc_number);
1809 }
1810 
1811 /**
1812  * grl_media_set_artist:
1813  * @media: the media instance
1814  * @artist: the audio's artist
1815  *
1816  * Set the artist of the media
1817  *
1818  * Since: 0.3.0
1819  */
1820 void
grl_media_set_artist(GrlMedia * media,const gchar * artist)1821 grl_media_set_artist (GrlMedia *media, const gchar *artist)
1822 {
1823   g_return_if_fail (GRL_IS_MEDIA (media));
1824   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST,
1825                        artist);
1826 }
1827 
1828 /**
1829  * grl_media_set_composer:
1830  * @media: the media instance
1831  * @composer: the audio's composer
1832  *
1833  * Set the composer of the media
1834  *
1835  * Since: 0.3.1
1836  */
1837 void
grl_media_set_composer(GrlMedia * media,const gchar * composer)1838 grl_media_set_composer (GrlMedia *media, const gchar *composer)
1839 {
1840   g_return_if_fail (GRL_IS_MEDIA (media));
1841   grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_COMPOSER,
1842                        composer);
1843 }
1844 
1845 /**
1846  * grl_media_set_width:
1847  * @media: the media instance
1848  * @width: the video's width
1849  *
1850  * Set the width of the media
1851  *
1852  * Since: 0.3.0
1853  */
1854 void
grl_media_set_width(GrlMedia * media,gint width)1855 grl_media_set_width (GrlMedia *media, gint width)
1856 {
1857   g_return_if_fail (GRL_IS_MEDIA (media));
1858   grl_data_set_int (GRL_DATA (media),
1859                     GRL_METADATA_KEY_WIDTH,
1860                     width);
1861 }
1862 
1863 /**
1864  * grl_media_set_height:
1865  * @media: the media instance
1866  * @height: the video's height
1867  *
1868  * Set the height of the media
1869  *
1870  * Since: 0.3.0
1871  */
1872 void
grl_media_set_height(GrlMedia * media,gint height)1873 grl_media_set_height (GrlMedia *media, gint height)
1874 {
1875   g_return_if_fail (GRL_IS_MEDIA (media));
1876   grl_data_set_int (GRL_DATA (media),
1877                     GRL_METADATA_KEY_HEIGHT,
1878                     height);
1879 }
1880 
1881 /**
1882  * grl_media_set_framerate:
1883  * @media: the media instance
1884  * @framerate: the video's framerate
1885  *
1886  * Set the framerate of the media
1887  *
1888  * Since: 0.3.0
1889  */
1890 void
grl_media_set_framerate(GrlMedia * media,gfloat framerate)1891 grl_media_set_framerate (GrlMedia *media, gfloat framerate)
1892 {
1893   g_return_if_fail (GRL_IS_MEDIA (media));
1894   grl_data_set_float (GRL_DATA (media),
1895                       GRL_METADATA_KEY_FRAMERATE,
1896                       framerate);
1897 }
1898 
1899 /**
1900  * grl_media_set_season:
1901  * @media: the media instance
1902  * @season: the video's season
1903  *
1904  * Sets the season number of the media
1905  *
1906  * Since: 0.3.0
1907  */
1908 void
grl_media_set_season(GrlMedia * media,gint season)1909 grl_media_set_season (GrlMedia *media, gint season)
1910 {
1911   g_return_if_fail (GRL_IS_MEDIA (media));
1912   grl_data_set_int (GRL_DATA (media),
1913                     GRL_METADATA_KEY_SEASON,
1914                     season);
1915 }
1916 
1917 /**
1918  * grl_media_set_episode:
1919  * @media: the media instance
1920  * @episode: the video's episode
1921  *
1922  * Sets the episode number of the media
1923  *
1924  * Since: 0.3.0
1925  */
1926 void
grl_media_set_episode(GrlMedia * media,gint episode)1927 grl_media_set_episode (GrlMedia *media, gint episode)
1928 {
1929   g_return_if_fail (GRL_IS_MEDIA (media));
1930   grl_data_set_int (GRL_DATA (media),
1931                     GRL_METADATA_KEY_EPISODE,
1932                     episode);
1933 }
1934 
1935 /**
1936  * grl_media_set_episode_title:
1937  * @media: the media instance
1938  * @episode_title: the title of the episode
1939  *
1940  * Sets the title of an media
1941  *
1942  * Since: 0.3.0
1943  */
1944 void
grl_media_set_episode_title(GrlMedia * media,const gchar * episode_title)1945 grl_media_set_episode_title (GrlMedia *media,
1946                              const gchar *episode_title)
1947 {
1948   g_return_if_fail (GRL_IS_MEDIA (media));
1949 
1950   grl_data_set_string (GRL_DATA (media),
1951                        GRL_METADATA_KEY_EPISODE_TITLE,
1952                        episode_title);
1953 }
1954 
1955 /**
1956  * grl_media_set_show:
1957  * @media: the media instance
1958  * @show: the video's show name
1959  *
1960  * Sets the show title of the media
1961  *
1962  * Since: 0.3.0
1963  */
1964 void
grl_media_set_show(GrlMedia * media,const gchar * show)1965 grl_media_set_show (GrlMedia *media, const gchar *show)
1966 {
1967   g_return_if_fail (GRL_IS_MEDIA (media));
1968   grl_data_set_string (GRL_DATA (media),
1969                        GRL_METADATA_KEY_SHOW,
1970                        show);
1971 }
1972 
1973 /**
1974  * grl_media_set_performer:
1975  * @media: a #GrlMedia
1976  * @performer: an actor performing in the movie
1977  *
1978  * Sets the actor performing in the movie.
1979  *
1980  * Since: 0.3.0
1981  */
1982 void
grl_media_set_performer(GrlMedia * media,const gchar * performer)1983 grl_media_set_performer (GrlMedia *media,
1984                          const gchar *performer)
1985 {
1986   g_return_if_fail (GRL_IS_MEDIA (media));
1987   grl_data_set_string (GRL_DATA (media),
1988                        GRL_METADATA_KEY_PERFORMER,
1989                        performer);
1990 }
1991 
1992 /**
1993  * grl_media_set_producer:
1994  * @media: a #GrlMedia
1995  * @producer: producer of the movie
1996  *
1997  * Sets the producer of the media.
1998  *
1999  * Since: 0.3.0
2000  */
2001 void
grl_media_set_producer(GrlMedia * media,const gchar * producer)2002 grl_media_set_producer (GrlMedia *media, const gchar *producer)
2003 {
2004   g_return_if_fail (GRL_IS_MEDIA (media));
2005   grl_data_set_string (GRL_DATA (media),
2006                        GRL_METADATA_KEY_PRODUCER,
2007                        producer);
2008 }
2009 
2010 /**
2011  * grl_media_set_director:
2012  * @media: a #GrlMedia
2013  * @director: director of the movie
2014  *
2015  * Sets the director of the media.
2016  *
2017  * Since: 0.3.0
2018  */
2019 void
grl_media_set_director(GrlMedia * media,const gchar * director)2020 grl_media_set_director (GrlMedia *media,
2021                         const gchar *director)
2022 {
2023   g_return_if_fail (GRL_IS_MEDIA (media));
2024   grl_data_set_string (GRL_DATA (media),
2025                        GRL_METADATA_KEY_DIRECTOR,
2026                        director);
2027 }
2028 
2029 /**
2030  * grl_media_set_original_title:
2031  * @media: a #GrlMedia
2032  * @original_title: original, untranslated title of the movie
2033  *
2034  * Sets the original, untranslated title of the media.
2035  *
2036  * Since: 0.3.0
2037  */
2038 void
grl_media_set_original_title(GrlMedia * media,const gchar * original_title)2039 grl_media_set_original_title (GrlMedia *media,
2040                               const gchar *original_title)
2041 {
2042   g_return_if_fail (GRL_IS_MEDIA (media));
2043   grl_data_set_string (GRL_DATA (media),
2044                        GRL_METADATA_KEY_ORIGINAL_TITLE,
2045                        original_title);
2046 }
2047 
2048 /**
2049   * grl_media_set_camera_model:
2050   * @media: the media instance
2051   * @camera_model: model of camera used to take picture
2052   *
2053   * Set the camera_model of the media
2054   *
2055   * Since: 0.3.0
2056   */
2057 void
grl_media_set_camera_model(GrlMedia * media,const gchar * camera_model)2058 grl_media_set_camera_model (GrlMedia *media,
2059                             const gchar *camera_model)
2060 {
2061   g_return_if_fail (GRL_IS_MEDIA (media));
2062   grl_data_set_string (GRL_DATA (media),
2063                        GRL_METADATA_KEY_CAMERA_MODEL,
2064                        camera_model);
2065 }
2066 
2067 /**
2068   * grl_media_set_flash_used:
2069   * @media: the media instance
2070   * @flash_used: whether the flash was used
2071   *
2072   * Set the flash_used of the media
2073   * See
2074   * http://library.gnome.org/devel/ontology/unstable/nmm-classes.html#nmm-Flash
2075   *
2076   * Since: 0.3.0
2077   */
2078 void
grl_media_set_flash_used(GrlMedia * media,const gchar * flash_used)2079 grl_media_set_flash_used (GrlMedia *media,
2080                           const gchar *flash_used)
2081 {
2082   g_return_if_fail (GRL_IS_MEDIA (media));
2083   grl_data_set_string (GRL_DATA (media),
2084                        GRL_METADATA_KEY_FLASH_USED,
2085                        flash_used);
2086 }
2087 
2088 /**
2089   * grl_media_set_exposure_time:
2090   * @media: the media instance
2091   * @exposure_time: picture's exposure time
2092   *
2093   * Set the exposure_time of the media
2094   *
2095   * Since: 0.3.0
2096   */
2097 void
grl_media_set_exposure_time(GrlMedia * media,gfloat exposure_time)2098 grl_media_set_exposure_time (GrlMedia *media,
2099                              gfloat exposure_time)
2100 {
2101   g_return_if_fail (GRL_IS_MEDIA (media));
2102   grl_data_set_float (GRL_DATA (media),
2103                       GRL_METADATA_KEY_EXPOSURE_TIME,
2104                       exposure_time);
2105 }
2106 
2107 /**
2108   * grl_media_set_iso_speed:
2109   * @media: the media instance
2110   * @iso_speed: picture's iso speed
2111   *
2112   * Set the iso_speed of the media
2113   *
2114   * Since: 0.3.0
2115   */
2116 void
grl_media_set_iso_speed(GrlMedia * media,gfloat iso_speed)2117 grl_media_set_iso_speed (GrlMedia *media,
2118                          gfloat iso_speed)
2119 {
2120   g_return_if_fail (GRL_IS_MEDIA (media));
2121   grl_data_set_float (GRL_DATA (media),
2122                       GRL_METADATA_KEY_ISO_SPEED,
2123                       iso_speed);
2124 }
2125 
2126 /**
2127   * grl_media_set_orientation:
2128   * @media: the media instance
2129   * @orientation: degrees clockwise orientation of the picture
2130   *
2131   * Set the orientation of the media
2132   *
2133   * Since: 0.3.0
2134   */
2135 void
grl_media_set_orientation(GrlMedia * media,gint orientation)2136 grl_media_set_orientation (GrlMedia *media,
2137                            gint orientation)
2138 {
2139   g_return_if_fail (GRL_IS_MEDIA (media));
2140   grl_data_set_int (GRL_DATA (media),
2141                     GRL_METADATA_KEY_ORIENTATION,
2142                     orientation % 360);
2143 }
2144 
2145 /**
2146  * grl_media_set_childcount:
2147  * @media: the media container instance
2148  * @childcount: number of children
2149  *
2150  * Sets the number of children of this container. Use
2151  * #GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN if it is unknown.
2152  *
2153  * Since: 0.3.0
2154  */
2155 void
grl_media_set_childcount(GrlMedia * media,gint childcount)2156 grl_media_set_childcount (GrlMedia *media,
2157                           gint childcount)
2158 {
2159   g_return_if_fail (GRL_IS_MEDIA (media));
2160   g_return_if_fail (grl_media_is_container (media));
2161 
2162   if (childcount != GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN) {
2163     grl_data_set_int (GRL_DATA (media),
2164                       GRL_METADATA_KEY_CHILDCOUNT,
2165                       childcount);
2166   }
2167 }
2168 
2169 /**
2170  * grl_media_get_id:
2171  * @media: the media object
2172  *
2173  * Returns: the media's identifier
2174  *
2175  * Since: 0.1.4
2176  */
2177 const gchar *
grl_media_get_id(GrlMedia * media)2178 grl_media_get_id (GrlMedia *media)
2179 {
2180   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2181 
2182   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ID);
2183 }
2184 
2185 /**
2186  * grl_media_get_url:
2187  * @media: the media object
2188  *
2189  * Returns: the media's URL
2190  *
2191  * Since: 0.1.4
2192  */
2193 const gchar *
grl_media_get_url(GrlMedia * media)2194 grl_media_get_url (GrlMedia *media)
2195 {
2196   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2197 
2198   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_URL);
2199 }
2200 
2201 /**
2202  * grl_media_get_url_data:
2203  * @media: the media object
2204  * @mime: (out) (transfer none): the mime-type, or %NULL to ignore.
2205  * @bitrate: (out): the url bitrate, or %NULL to ignore
2206  * @framerate: the url framerate, or %NULL to ignore
2207  * @width: the url width, or %NULL to ignore
2208  * @height: the url height, or %NULL to ignore
2209  *
2210  * Returns: the media's URL and its related properties.
2211  *
2212  * Since: 0.3.0
2213  */
2214 const gchar *
grl_media_get_url_data(GrlMedia * media,gchar ** mime,gint * bitrate,gfloat * framerate,gint * width,gint * height)2215 grl_media_get_url_data (GrlMedia *media,
2216                         gchar **mime,
2217                         gint *bitrate,
2218                         gfloat *framerate,
2219                         gint *width,
2220                         gint *height)
2221 
2222 {
2223   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2224 
2225   return grl_media_get_url_data_nth (media,
2226                                      0,
2227                                      mime,
2228                                      bitrate,
2229                                      framerate,
2230                                      width,
2231                                      height);
2232 }
2233 
2234 /**
2235  * grl_media_get_url_data_nth:
2236  * @media: the media object
2237  * @index: element to retrieve
2238  * @mime: (out) (transfer none): the mime-type, or %NULL to ignore.
2239  * @bitrate: (out): the url bitrate, or %NULL to ignore
2240  * @framerate: the url framerate, or %NULL to ignore
2241  * @width: the url width, or %NULL to ignore
2242  * @height: the url height, or %NULL to ignore
2243  *
2244  * Returns: the n-th media's URL and its related properties.
2245  *
2246  * Since: 0.3.0
2247  */
2248 const gchar *
grl_media_get_url_data_nth(GrlMedia * media,guint index,gchar ** mime,gint * bitrate,gfloat * framerate,gint * width,gint * height)2249 grl_media_get_url_data_nth (GrlMedia *media,
2250                             guint index,
2251                             gchar **mime,
2252                             gint *bitrate,
2253                             gfloat *framerate,
2254                             gint *width,
2255                             gint *height)
2256 {
2257   GrlRelatedKeys *relkeys;
2258 
2259   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2260 
2261   relkeys = grl_data_get_related_keys (GRL_DATA (media), GRL_METADATA_KEY_URL, index);
2262 
2263   if (!relkeys) {
2264     return NULL;
2265   }
2266 
2267   if (mime) {
2268     *mime = (gchar *) grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_MIME);
2269   }
2270 
2271   if (bitrate) {
2272     *bitrate = grl_related_keys_get_int (relkeys, GRL_METADATA_KEY_BITRATE);
2273   }
2274 
2275   if (framerate) {
2276     *framerate = grl_related_keys_get_float (relkeys, GRL_METADATA_KEY_FRAMERATE);
2277   }
2278 
2279   if (width) {
2280     *width = grl_related_keys_get_int (relkeys, GRL_METADATA_KEY_WIDTH);
2281   }
2282 
2283   if (height) {
2284     *height = grl_related_keys_get_int (relkeys, GRL_METADATA_KEY_HEIGHT);
2285   }
2286 
2287   return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_URL);
2288 }
2289 
2290 /**
2291  * grl_media_get_author:
2292  * @media: the media object
2293  *
2294  * Returns: the media's author
2295  *
2296  * Since: 0.1.4
2297  */
2298 const gchar *
grl_media_get_author(GrlMedia * media)2299 grl_media_get_author (GrlMedia *media)
2300 {
2301   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2302 
2303   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_AUTHOR);
2304 }
2305 
2306 /**
2307  * grl_media_get_author_nth:
2308  * @media: the media object
2309  * @index: element to retrieve
2310  *
2311  * Returns: the n-th media's author.
2312  *
2313  * Since: 0.1.10
2314  */
2315 const gchar *
grl_media_get_author_nth(GrlMedia * media,guint index)2316 grl_media_get_author_nth (GrlMedia *media, guint index)
2317 {
2318   GrlRelatedKeys *relkeys;
2319 
2320   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2321 
2322   relkeys =
2323     grl_data_get_related_keys (GRL_DATA (media),
2324                                GRL_METADATA_KEY_AUTHOR,
2325                                index);
2326 
2327   if (!relkeys) {
2328     return NULL;
2329   } else {
2330     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_AUTHOR);
2331   }
2332 }
2333 
2334 /**
2335  * grl_media_get_title:
2336  * @media: the media object
2337  *
2338  * Returns: the media's title
2339  *
2340  * Since: 0.1.4
2341  */
2342 const gchar *
grl_media_get_title(GrlMedia * media)2343 grl_media_get_title (GrlMedia *media)
2344 {
2345   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2346 
2347   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_TITLE);
2348 }
2349 
2350 /**
2351  * grl_media_get_description:
2352  * @media: the media object
2353  *
2354  * Returns: the media's description
2355  *
2356  * Since: 0.1.4
2357  */
2358 const gchar *
grl_media_get_description(GrlMedia * media)2359 grl_media_get_description (GrlMedia *media)
2360 {
2361   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2362 
2363   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_DESCRIPTION);
2364 }
2365 
2366 /**
2367  * grl_media_get_source:
2368  * @media: the media object source
2369  *
2370  * Returns: the media's source
2371  *
2372  * Since: 0.1.4
2373  */
2374 const gchar *
grl_media_get_source(GrlMedia * media)2375 grl_media_get_source (GrlMedia *media)
2376 {
2377   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2378 
2379   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_SOURCE);
2380 }
2381 
2382 /**
2383  * grl_media_get_thumbnail:
2384  * @media: the media object
2385  *
2386  * Returns: the media's thumbnail URL
2387  *
2388  * Since: 0.1.4
2389  */
2390 const gchar *
grl_media_get_thumbnail(GrlMedia * media)2391 grl_media_get_thumbnail (GrlMedia *media)
2392 {
2393   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2394 
2395   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
2396 }
2397 
2398 /**
2399  * grl_media_get_thumbnail_nth:
2400  * @media: the media object
2401  * @index: element to retrieve
2402  *
2403  * Returns: the n-th media's thumbnail.
2404  *
2405  * Since: 0.1.10
2406  */
2407 const gchar *
grl_media_get_thumbnail_nth(GrlMedia * media,guint index)2408 grl_media_get_thumbnail_nth (GrlMedia *media, guint index)
2409 {
2410   GrlRelatedKeys *relkeys;
2411 
2412   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2413 
2414   relkeys =
2415     grl_data_get_related_keys (GRL_DATA (media),
2416                                GRL_METADATA_KEY_THUMBNAIL,
2417                                index);
2418 
2419   if (!relkeys) {
2420     return NULL;
2421   } else {
2422     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_THUMBNAIL);
2423   }
2424 }
2425 
2426 /**
2427  * grl_media_get_thumbnail_binary:
2428  * @media: the media object
2429  * @size: pointer to storing the thumbnail buffer size
2430  *
2431  * Returns: the media's thumbnail data and set size to the thumbnail buffer size
2432  *
2433  * Since: 0.1.9
2434  */
2435 const guint8 *
grl_media_get_thumbnail_binary(GrlMedia * media,gsize * size)2436 grl_media_get_thumbnail_binary (GrlMedia *media, gsize *size)
2437 {
2438   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2439   g_return_val_if_fail (size != NULL, NULL);
2440 
2441   return grl_data_get_binary (GRL_DATA (media),
2442                               GRL_METADATA_KEY_THUMBNAIL_BINARY,
2443                               size);
2444 }
2445 
2446 /**
2447  * grl_media_get_thumbnail_binary_nth:
2448  * @media: the media object
2449  * @size: pointer to store the thumbnail buffer size
2450  * @index: element to retrieve
2451  *
2452  * Returns: the n-th media's thumbnail binary and sets size to the thumbnail
2453  * buffer size.
2454  *
2455  * Since: 0.1.10
2456  */
2457 const guint8 *
grl_media_get_thumbnail_binary_nth(GrlMedia * media,gsize * size,guint index)2458 grl_media_get_thumbnail_binary_nth (GrlMedia *media, gsize *size, guint index)
2459 {
2460   GrlRelatedKeys *relkeys;
2461 
2462   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2463   g_return_val_if_fail (size != NULL, NULL);
2464 
2465   relkeys =
2466     grl_data_get_related_keys (GRL_DATA (media),
2467                                GRL_METADATA_KEY_THUMBNAIL,
2468                                index);
2469 
2470   if (!relkeys) {
2471     return NULL;
2472   } else {
2473     return grl_related_keys_get_binary (relkeys,
2474                                         GRL_METADATA_KEY_THUMBNAIL,
2475                                         size);
2476   }
2477 }
2478 
2479 /**
2480  * grl_media_get_site:
2481  * @media: the media object
2482  *
2483  * Returns: the media's site
2484  *
2485  * Since: 0.1.4
2486  */
2487 const gchar *
grl_media_get_site(GrlMedia * media)2488 grl_media_get_site (GrlMedia *media)
2489 {
2490   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2491 
2492   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_SITE);
2493 }
2494 
2495 /**
2496  * grl_media_get_duration:
2497  * @media: the media object
2498  *
2499  * Returns: the media's duration in seconds
2500  *
2501  * Since: 0.1.4
2502  */
2503 gint
grl_media_get_duration(GrlMedia * media)2504 grl_media_get_duration (GrlMedia *media)
2505 {
2506   g_return_val_if_fail (GRL_IS_MEDIA (media), 0);
2507 
2508   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_DURATION);
2509 }
2510 
2511 /**
2512  * grl_media_get_publication_date:
2513  * @media: the media object
2514  *
2515  * Returns: (transfer none): the publication date of @media (owned by @media).
2516  *
2517  * Since: 0.2.0
2518  */
2519 GDateTime *
grl_media_get_publication_date(GrlMedia * media)2520 grl_media_get_publication_date (GrlMedia *media)
2521 {
2522   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2523 
2524   return grl_data_get_boxed (GRL_DATA (media),
2525                              GRL_METADATA_KEY_PUBLICATION_DATE);
2526 }
2527 
2528 /**
2529  * grl_media_get_region:
2530  * @media: the media object
2531  *
2532  * Returns: (transfer none): the ISO-3166-1 of the region where the media was
2533  * published (owned by @media).
2534  *
2535  * Since: 0.2.3
2536  */
2537 const gchar *
grl_media_get_region(GrlMedia * media)2538 grl_media_get_region (GrlMedia *media)
2539 {
2540   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2541 
2542   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_REGION);
2543 }
2544 
2545 /**
2546  * grl_media_get_region_data:
2547  * @media: the media object
2548  * @publication_date: (out) (transfer none): the publication date, or %NULL to ignore.
2549  * @certificate: (out) (transfer none): the age certification, or %NULL to ignore.
2550  *
2551  * Returns the media's age certificate and publication date for the first region.
2552  * This should usually be the media's most relevant region.
2553  * Use grl_media_get_region_data_nth() to get the age certificate and
2554  * publication date for other regions.
2555  *
2556  * Returns: (transfer none): the ISO-3166-1 of the region where the media was
2557  * published (owned by @media).
2558  *
2559  * Since: 0.2.3
2560  */
2561 const gchar *
grl_media_get_region_data(GrlMedia * media,const GDateTime ** publication_date,const gchar ** certificate)2562 grl_media_get_region_data (GrlMedia *media,
2563                            const GDateTime **publication_date,
2564                            const gchar **certificate)
2565 {
2566   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2567 
2568   return grl_media_get_region_data_nth (media, 0, publication_date,  certificate);
2569 }
2570 
2571 /**
2572  * grl_media_get_region_data_nth:
2573  * @media: the media object
2574  * @index: element to retrieve
2575  * @publication_date: (out) (transfer none): the publication date, or %NULL to ignore.
2576  * @certificate: (out) (transfer none): the age certification, or %NULL to ignore.
2577  *
2578  * Returns the media's age certificate and publication date for one region.
2579  * Use grl_data_length() with GRL_METADATA_KEY_REGION to discover
2580  * how many regions are available. For instance:
2581  * <informalexample>
2582  * <programlisting role="C"><![CDATA[
2583  * guint count = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_REGION);
2584  * guint i;
2585  * for (i = 0; i < count; ++i) {
2586  *   const GDateTime* publication_date = NULL;
2587  *   const gchar* certificate = NULL;
2588  *   const gchar* region =
2589  *     grl_media_get_region_data_nth (media, i,
2590  *       &publication_date, &certificate);
2591  *   ...
2592  * }
2593  * ]]></programlisting>
2594  * </informalexample>
2595  *
2596  * Returns: (transfer none): the ISO-3166-1 of the region where the media was
2597  * published (owned by @media).
2598  *
2599  * Since: 0.2.3
2600  */
2601 const gchar *
grl_media_get_region_data_nth(GrlMedia * media,guint index,const GDateTime ** publication_date,const gchar ** certificate)2602 grl_media_get_region_data_nth (GrlMedia *media,
2603                                guint index,
2604                                const GDateTime **publication_date,
2605                                const gchar **certificate)
2606 {
2607   GrlRelatedKeys *relkeys;
2608 
2609   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2610 
2611   relkeys =
2612     grl_data_get_related_keys (GRL_DATA (media),
2613                                GRL_METADATA_KEY_PUBLICATION_DATE,
2614                                index);
2615 
2616   if (!relkeys) {
2617     return NULL;
2618   }
2619 
2620   if (publication_date) {
2621     *publication_date = grl_related_keys_get_boxed
2622               (relkeys, GRL_METADATA_KEY_PUBLICATION_DATE);
2623   }
2624 
2625   if (certificate) {
2626     *certificate = grl_related_keys_get_string
2627               (relkeys, GRL_METADATA_KEY_CERTIFICATE);
2628   }
2629 
2630   return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_REGION);
2631 }
2632 
2633 /**
2634  * grl_media_get_creation_date:
2635  * @media: the media
2636  *
2637  * Returns: (transfer none): date when media was created (owned by @media).
2638  *
2639  * Since: 0.2.0
2640  */
2641 GDateTime *
grl_media_get_creation_date(GrlMedia * media)2642 grl_media_get_creation_date (GrlMedia *media)
2643 {
2644   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2645 
2646   return grl_data_get_boxed (GRL_DATA (media), GRL_METADATA_KEY_CREATION_DATE);
2647 }
2648 
2649 /**
2650  * grl_media_get_modification_date:
2651  * @media: the media
2652  *
2653  * Returns: (transfer none):date when the media was last modified (owned by @media).
2654  *
2655  * Since: 0.2.0
2656  */
2657 GDateTime *
grl_media_get_modification_date(GrlMedia * media)2658 grl_media_get_modification_date (GrlMedia *media)
2659 {
2660   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2661 
2662   return grl_data_get_boxed (GRL_DATA (media),
2663                              GRL_METADATA_KEY_MODIFICATION_DATE);
2664 }
2665 
2666 /**
2667  * grl_media_get_mime:
2668  * @media: the media object
2669  *
2670  * Returns: the media's mime-type
2671  *
2672  * Since: 0.1.4
2673  */
2674 const gchar *
grl_media_get_mime(GrlMedia * media)2675 grl_media_get_mime (GrlMedia *media)
2676 {
2677   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2678 
2679   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MIME);
2680 }
2681 
2682 /**
2683  * grl_media_get_rating:
2684  * @media: the media object
2685  *
2686  * Returns: the media's rating
2687  *
2688  * Since: 0.1.5
2689  */
2690 gfloat
grl_media_get_rating(GrlMedia * media)2691 grl_media_get_rating (GrlMedia *media)
2692 {
2693   g_return_val_if_fail (GRL_IS_MEDIA (media), 0.0);
2694 
2695   return grl_data_get_float (GRL_DATA (media), GRL_METADATA_KEY_RATING);
2696 }
2697 
2698 /**
2699  * grl_media_get_play_count:
2700  * @media: the media object
2701  *
2702  * Returns: the media's play count
2703  *
2704  * Since: 0.1.4
2705  */
2706 gint
grl_media_get_play_count(GrlMedia * media)2707 grl_media_get_play_count (GrlMedia *media)
2708 {
2709   g_return_val_if_fail (GRL_IS_MEDIA (media), 0);
2710 
2711   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_PLAY_COUNT);
2712 }
2713 
2714 /**
2715  * grl_media_get_last_position:
2716  * @media: the media object
2717  *
2718  * Returns: the media's last_played position (in seconds)
2719  *
2720  * Since: 0.1.4
2721  */
2722 gint
grl_media_get_last_position(GrlMedia * media)2723 grl_media_get_last_position (GrlMedia *media)
2724 {
2725   g_return_val_if_fail (GRL_IS_MEDIA (media), 0);
2726 
2727   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_LAST_POSITION);
2728 }
2729 
2730 /**
2731  * grl_media_get_last_played:
2732  * @media: the media object
2733  *
2734  * Returns: (transfer none): the media's last played time
2735  *
2736  * Since: 0.3.0
2737  */
2738 GDateTime *
grl_media_get_last_played(GrlMedia * media)2739 grl_media_get_last_played (GrlMedia *media)
2740 {
2741   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2742 
2743   return grl_data_get_boxed (GRL_DATA (media), GRL_METADATA_KEY_LAST_PLAYED);
2744 }
2745 
2746 /**
2747  * grl_media_get_player:
2748  * @media: the media object
2749  *
2750  * Returns: URL of an external player
2751  * object for this media
2752  *
2753  * Since: 0.1.6
2754  */
2755 const gchar *
grl_media_get_player(GrlMedia * media)2756 grl_media_get_player(GrlMedia *media)
2757 {
2758   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2759 
2760   return grl_data_get_string (GRL_DATA (media),
2761                               GRL_METADATA_KEY_EXTERNAL_PLAYER);
2762 }
2763 
2764 /**
2765  * grl_media_get_player_nth:
2766  * @media: the media object
2767  * @index: element to retrieve
2768  *
2769  * Returns: the n-th media's external player object.
2770  *
2771  * Since: 0.1.10
2772  */
2773 const gchar *
grl_media_get_player_nth(GrlMedia * media,guint index)2774 grl_media_get_player_nth (GrlMedia *media, guint index)
2775 {
2776   GrlRelatedKeys *relkeys;
2777 
2778   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2779 
2780   relkeys =
2781     grl_data_get_related_keys (GRL_DATA (media),
2782                                GRL_METADATA_KEY_EXTERNAL_PLAYER,
2783                                index);
2784 
2785   if (!relkeys) {
2786     return NULL;
2787   } else {
2788     return grl_related_keys_get_string (relkeys,
2789                                         GRL_METADATA_KEY_EXTERNAL_PLAYER);
2790   }
2791 }
2792 
2793 /**
2794  * grl_media_get_external_url:
2795  * @media: the media object
2796  *
2797  * Returns: URL of an external location
2798  * where the user play the media.
2799  *
2800  * Since: 0.1.6
2801  */
2802 const gchar *
grl_media_get_external_url(GrlMedia * media)2803 grl_media_get_external_url (GrlMedia *media)
2804 {
2805   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2806 
2807   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_EXTERNAL_URL);
2808 }
2809 
2810 /**
2811  * grl_media_get_external_url_nth:
2812  * @media: the media object
2813  * @index: element to retrieve
2814  *
2815  * Returns: the n-th media's external location where the user can play it.
2816  *
2817  * Since: 0.1.10
2818  */
2819 const gchar *
grl_media_get_external_url_nth(GrlMedia * media,guint index)2820 grl_media_get_external_url_nth (GrlMedia *media, guint index)
2821 {
2822   GrlRelatedKeys *relkeys;
2823 
2824   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2825 
2826   relkeys =
2827     grl_data_get_related_keys (GRL_DATA (media),
2828                                GRL_METADATA_KEY_EXTERNAL_URL,
2829                                index);
2830 
2831   if (!relkeys) {
2832     return NULL;
2833   } else {
2834     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_EXTERNAL_URL);
2835   }
2836 }
2837 
2838 /**
2839  * grl_media_get_studio:
2840  * @media: the media object
2841  *
2842  * Returns: the studio the media is from
2843  *
2844  * Since: 0.1.6
2845  */
2846 const gchar *
grl_media_get_studio(GrlMedia * media)2847 grl_media_get_studio(GrlMedia *media)
2848 {
2849   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2850 
2851   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_STUDIO);
2852 }
2853 
2854 /**
2855  * grl_media_get_certificate:
2856  * @media: the media object
2857  *
2858  * Returns the media's first age certificate.
2859  * This should usually be the media's most relevant
2860  * age certificate. Use grl_media_get_region_data_nth() to
2861  * get other age certificates.
2862  *
2863  * Returns: the media's age certification
2864  *
2865  * Since: 0.1.6
2866  */
2867 const gchar *
grl_media_get_certificate(GrlMedia * media)2868 grl_media_get_certificate (GrlMedia *media)
2869 {
2870   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2871 
2872   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_CERTIFICATE);
2873 }
2874 
2875 /**
2876  * grl_media_get_license:
2877  * @media: the media object
2878  *
2879  * Returns: the license the media is under
2880  *
2881  * Since: 0.1.6
2882  */
2883 const gchar *
grl_media_get_license(GrlMedia * media)2884 grl_media_get_license (GrlMedia *media)
2885 {
2886   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2887 
2888   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_LICENSE);
2889 }
2890 
2891 /**
2892  * grl_media_get_start_time:
2893  * @media: the media object
2894  *
2895  * Returns: the start time of the logical media resource inside the
2896  *          file containing it, in seconds.
2897  *
2898  * Since: 0.1.19
2899  */
2900 gfloat
grl_media_get_start_time(GrlMedia * media)2901 grl_media_get_start_time (GrlMedia *media)
2902 {
2903   g_return_val_if_fail (GRL_IS_MEDIA (media), 0.0);
2904 
2905   return grl_data_get_float (GRL_DATA (media), GRL_METADATA_KEY_START_TIME);
2906 }
2907 
2908 /**
2909  * grl_media_get_favourite:
2910  * @media: the media object
2911  *
2912  * Returns: whether the media is favourite or not
2913  *
2914  * Since: 0.2.3
2915  */
2916 gboolean
grl_media_get_favourite(GrlMedia * media)2917 grl_media_get_favourite (GrlMedia *media)
2918 {
2919   g_return_val_if_fail (GRL_IS_MEDIA (media), FALSE);
2920 
2921   return grl_data_get_boolean (GRL_DATA (media), GRL_METADATA_KEY_FAVOURITE);
2922 }
2923 
2924 /**
2925  * grl_media_get_keyword:
2926  * @media: a #GrlMedia
2927  *
2928  * Returns: (transfer none): the keyword describing the @media (owned by @media).
2929  *
2930  * Since: 0.2.3
2931  */
2932 const gchar *
grl_media_get_keyword(GrlMedia * media)2933 grl_media_get_keyword (GrlMedia *media)
2934 {
2935   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2936 
2937   return grl_data_get_string (GRL_DATA (media),
2938                               GRL_METADATA_KEY_KEYWORD);
2939 }
2940 
2941 /**
2942  * grl_media_get_keyword_nth:
2943  * @media: a #GrlMedia
2944  * @index: element to retrieve
2945  *
2946  * Returns: (transfer none): the keyword describing the @media (owned by @media).
2947  *
2948  * Since: 0.2.3
2949  */
2950 const gchar *
grl_media_get_keyword_nth(GrlMedia * media,guint index)2951 grl_media_get_keyword_nth (GrlMedia *media,
2952                            guint index)
2953 {
2954   GrlRelatedKeys *relkeys;
2955 
2956   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
2957 
2958   relkeys =
2959     grl_data_get_related_keys (GRL_DATA (media),
2960                                GRL_METADATA_KEY_KEYWORD,
2961                                index);
2962 
2963   if (!relkeys) {
2964     return NULL;
2965   }
2966 
2967   return grl_related_keys_get_string (relkeys,
2968                                       GRL_METADATA_KEY_KEYWORD);
2969 }
2970 
2971 /**
2972  * grl_media_get_size:
2973  * @media: the media object
2974  *
2975  * Returns: the media's size, in bytes or -1 if unknown.
2976  *
2977  * since: 0.2.10
2978  */
2979 gint64
grl_media_get_size(GrlMedia * media)2980 grl_media_get_size (GrlMedia *media)
2981 {
2982   g_return_val_if_fail (GRL_IS_MEDIA (media), -1);
2983   return grl_data_get_int64 (GRL_DATA (media), GRL_METADATA_KEY_SIZE);
2984 }
2985 
2986 /**
2987  * grl_media_get_track_number:
2988  * @media: the media instance
2989  *
2990  * Returns: the track number of the media
2991  *
2992  * Since: 0.3.0
2993  */
2994 gint
grl_media_get_track_number(GrlMedia * media)2995 grl_media_get_track_number (GrlMedia *media)
2996 {
2997   g_return_val_if_fail (GRL_IS_MEDIA (media), 0);
2998   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_TRACK_NUMBER);
2999 }
3000 
3001 /**
3002  * grl_media_get_bitrate:
3003  * @media: the media instance
3004  *
3005  * Returns: the bitrate of the media
3006  *
3007  * Since: 0.3.0
3008  */
3009 gint
grl_media_get_bitrate(GrlMedia * media)3010 grl_media_get_bitrate (GrlMedia *media)
3011 {
3012   g_return_val_if_fail (GRL_IS_MEDIA (media), 0);
3013   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_BITRATE);
3014 }
3015 
3016 /**
3017  * grl_media_get_mb_album_id:
3018  * @media: the media instance
3019  *
3020  * Returns: the MusicBrainz album identifier
3021  *
3022  * Since: 0.3.0
3023  *
3024  * Deprecated: 0.3.8 in favor of more specific metadata-keys
3025  * GRL_METADATA_KEY_MB_RELEASE_ID and GRL_METADATA_KEY_MB_RELEASE_GROUP_ID
3026  */
3027 const gchar *
grl_media_get_mb_album_id(GrlMedia * media)3028 grl_media_get_mb_album_id (GrlMedia *media)
3029 {
3030   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3031   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ALBUM_ID);
3032 }
3033 
3034 /**
3035  * grl_media_get_mb_artist_id:
3036  * @media: the media instance
3037  *
3038  * Returns: the MusicBrainz artist identifier
3039  *
3040  * Since: 0.3.0
3041  */
3042 const gchar *
grl_media_get_mb_artist_id(GrlMedia * media)3043 grl_media_get_mb_artist_id (GrlMedia *media)
3044 {
3045   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3046   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_ARTIST_ID);
3047 }
3048 
3049 /**
3050  * grl_media_get_mb_artist_id_nth:
3051  * @media: the media instance
3052  * @index: element to retrieve, starting at 0
3053  *
3054  * Returns: the n-th MusicBrainz artist identifier of the media
3055  *
3056  * Since: 0.3.0
3057  */
3058 const gchar *
grl_media_get_mb_artist_id_nth(GrlMedia * media,guint index)3059 grl_media_get_mb_artist_id_nth (GrlMedia *media, guint index)
3060 {
3061   GrlRelatedKeys *relkeys;
3062 
3063   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3064 
3065   relkeys =
3066     grl_data_get_related_keys (GRL_DATA (media),
3067                                GRL_METADATA_KEY_MB_ARTIST_ID,
3068                                index);
3069 
3070   if (!relkeys) {
3071     return NULL;
3072   } else {
3073     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_MB_ARTIST_ID);
3074   }
3075 }
3076 
3077 /**
3078  * grl_media_get_mb_recording_id:
3079  * @media: the media instance
3080  *
3081  * Returns: the MusicBrainz recording identifier
3082  *
3083  * Since: 0.3.0
3084  */
3085 const gchar *
grl_media_get_mb_recording_id(GrlMedia * media)3086 grl_media_get_mb_recording_id (GrlMedia *media)
3087 {
3088   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3089   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RECORDING_ID);
3090 }
3091 
3092 /**
3093  * grl_media_get_mb_track_id:
3094  * @media: the media instance
3095  *
3096  * Returns: the MusicBrainz track identifier
3097  *
3098  * Since: 0.3.0
3099  */
3100 const gchar *
grl_media_get_mb_track_id(GrlMedia * media)3101 grl_media_get_mb_track_id (GrlMedia *media)
3102 {
3103   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3104   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_TRACK_ID);
3105 }
3106 
3107 /**
3108  * grl_media_get_mb_release_id:
3109  * @media: the media instance
3110  *
3111  * Returns: the MusicBrainz release identifier of the media
3112  *
3113  * Since: 0.3.8
3114  */
3115 const gchar *
grl_media_get_mb_release_id(GrlMedia * media)3116 grl_media_get_mb_release_id (GrlMedia *media)
3117 {
3118   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3119   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RELEASE_ID);
3120 }
3121 
3122 /**
3123  * grl_media_get_mb_release_group_id:
3124  * @media: the media instance
3125  *
3126  * Returns: the MusicBrainz release group identifier of the media
3127  *
3128  * Since: 0.3.8
3129  */
3130 const gchar *
grl_media_get_mb_release_group_id(GrlMedia * media)3131 grl_media_get_mb_release_group_id (GrlMedia *media)
3132 {
3133   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3134   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_MB_RELEASE_GROUP_ID);
3135 }
3136 
3137 /**
3138  * grl_media_get_lyrics:
3139  * @media: the media instance
3140  *
3141  * Returns: the lyrics of the media
3142  *
3143  * Since: 0.3.0
3144  */
3145 const gchar *
grl_media_get_lyrics(GrlMedia * media)3146 grl_media_get_lyrics (GrlMedia *media)
3147 {
3148   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3149   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_LYRICS);
3150 }
3151 
3152 /**
3153  * grl_media_get_lyrics_nth:
3154  * @media: the media instance
3155  * @index: element to retrieve, starting at 0
3156  *
3157  * Returns: the n-th lyrics of the media
3158  *
3159  * Since: 0.3.0
3160  */
3161 const gchar *
grl_media_get_lyrics_nth(GrlMedia * media,guint index)3162 grl_media_get_lyrics_nth (GrlMedia *media, guint index)
3163 {
3164   GrlRelatedKeys *relkeys;
3165 
3166   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3167 
3168   relkeys =
3169     grl_data_get_related_keys (GRL_DATA (media),
3170                                GRL_METADATA_KEY_LYRICS,
3171                                index);
3172 
3173   if (!relkeys) {
3174     return NULL;
3175   } else {
3176     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_LYRICS);
3177   }
3178 }
3179 
3180 /**
3181  * grl_media_get_genre:
3182  * @media: the media instance
3183  *
3184  * Returns: the genre of the media
3185  *
3186  * Since: 0.3.0
3187  */
3188 const gchar *
grl_media_get_genre(GrlMedia * media)3189 grl_media_get_genre (GrlMedia *media)
3190 {
3191   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3192   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_GENRE);
3193 }
3194 
3195 /**
3196  * grl_media_get_genre_nth:
3197  * @media: the media instance
3198  * @index: element to retrieve, starting at 0
3199  *
3200  * Returns: the n-th genre of the media
3201  *
3202  * Since: 0.3.0
3203  */
3204 const gchar *
grl_media_get_genre_nth(GrlMedia * media,guint index)3205 grl_media_get_genre_nth (GrlMedia *media, guint index)
3206 {
3207   GrlRelatedKeys *relkeys;
3208 
3209   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3210 
3211   relkeys =
3212     grl_data_get_related_keys (GRL_DATA (media), GRL_METADATA_KEY_GENRE, index);
3213 
3214   if (!relkeys) {
3215     return NULL;
3216   } else {
3217     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_GENRE);
3218   }
3219 }
3220 
3221 /**
3222  * grl_media_get_album:
3223  * @media: the media instance
3224  *
3225  * Returns: the album of the media
3226  *
3227  * Since: 0.3.0
3228  */
3229 const gchar *
grl_media_get_album(GrlMedia * media)3230 grl_media_get_album (GrlMedia *media)
3231 {
3232   g_return_val_if_fail (GRL_MEDIA (media), NULL);
3233   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM);
3234 }
3235 
3236 /**
3237  * grl_media_get_album_artist:
3238  * @media: the media instance
3239  *
3240  * Returns: the main artist of the album of the media
3241  *
3242  * Since: 0.3.1
3243  */
3244 const gchar *
grl_media_get_album_artist(GrlMedia * media)3245 grl_media_get_album_artist (GrlMedia *media)
3246 {
3247   g_return_val_if_fail (GRL_MEDIA (media), NULL);
3248   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ALBUM_ARTIST);
3249 }
3250 
3251 /**
3252  * grl_media_get_album_disc_number:
3253  * @media: the media instance
3254  *
3255  * Returns: the disc number of the media for multi-disc album sets.
3256  *
3257  * Since: 0.3.1
3258  */
3259 gint
grl_media_get_album_disc_number(GrlMedia * media)3260 grl_media_get_album_disc_number (GrlMedia *media)
3261 {
3262   g_return_val_if_fail (GRL_MEDIA (media), 0);
3263   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_ALBUM_DISC_NUMBER);
3264 }
3265 
3266 /**
3267  * grl_media_get_artist:
3268  * @media: the media instance
3269  *
3270  * Returns: the artist of the media
3271  *
3272  * Since: 0.3.0
3273  */
3274 const gchar *
grl_media_get_artist(GrlMedia * media)3275 grl_media_get_artist (GrlMedia *media)
3276 {
3277   g_return_val_if_fail (GRL_MEDIA (media), NULL);
3278   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST);
3279 }
3280 
3281 /**
3282  * grl_media_get_artist_nth:
3283  * @media: the media instance
3284  * @index: element to retrieve, starting at 0
3285  *
3286  * Returns: the n-th artist of the media
3287  *
3288  * Since: 0.3.0
3289  */
3290 const gchar *
grl_media_get_artist_nth(GrlMedia * media,guint index)3291 grl_media_get_artist_nth (GrlMedia *media, guint index)
3292 {
3293   GrlRelatedKeys *relkeys;
3294 
3295   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3296 
3297   relkeys =
3298     grl_data_get_related_keys (GRL_DATA (media),
3299                                GRL_METADATA_KEY_ARTIST,
3300                                index);
3301 
3302   if (!relkeys) {
3303     return NULL;
3304   } else {
3305     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_ARTIST);
3306   }
3307 }
3308 
3309 /**
3310  * grl_media_get_composer:
3311  * @media: the media instance
3312  *
3313  * Returns: the composer of the media
3314  *
3315  * Since: 0.3.1
3316  */
3317 const gchar *
grl_media_get_composer(GrlMedia * media)3318 grl_media_get_composer (GrlMedia *media)
3319 {
3320   g_return_val_if_fail (GRL_MEDIA (media), NULL);
3321   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_COMPOSER);
3322 }
3323 
3324 /**
3325  * grl_media_get_composer_nth:
3326  * @media: the media instance
3327  * @index: element to retrieve, starting at 0
3328  *
3329  * Returns: the n-th composer of the media
3330  *
3331  * Since: 0.3.1
3332  */
3333 const gchar *
grl_media_get_composer_nth(GrlMedia * media,guint index)3334 grl_media_get_composer_nth (GrlMedia *media, guint index)
3335 {
3336   GrlRelatedKeys *relkeys;
3337 
3338   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3339 
3340   relkeys =
3341     grl_data_get_related_keys (GRL_DATA (media),
3342                                GRL_METADATA_KEY_COMPOSER,
3343                                index);
3344 
3345   if (!relkeys) {
3346     return NULL;
3347   } else {
3348     return grl_related_keys_get_string (relkeys, GRL_METADATA_KEY_COMPOSER);
3349   }
3350 }
3351 
3352 /**
3353  * grl_media_get_media_type:
3354  * @media: the media instance
3355  *
3356  * Gets the "media-type" property.
3357  *
3358  * Returns: media type
3359  *
3360  * Since: 0.3.0
3361  */
3362 GrlMediaType
grl_media_get_media_type(GrlMedia * media)3363 grl_media_get_media_type (GrlMedia *media)
3364 {
3365   g_return_val_if_fail (GRL_IS_MEDIA (media), GRL_MEDIA_TYPE_UNKNOWN);
3366 
3367   return media->priv->media_type;
3368 }
3369 
3370 /**
3371  * grl_media_get_width:
3372  * @media: the media instance
3373  *
3374  * Returns: the width of the media
3375  *
3376  * Since: 0.3.0
3377  */
3378 gint
grl_media_get_width(GrlMedia * media)3379 grl_media_get_width (GrlMedia *media)
3380 {
3381   g_return_val_if_fail (GRL_MEDIA (media), 0);
3382   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_WIDTH);
3383 }
3384 
3385 /**
3386  * grl_media_get_height:
3387  * @media: the media instance
3388  *
3389  * Returns: the height of the media
3390  *
3391  * Since: 0.3.0
3392  */
3393 gint
grl_media_get_height(GrlMedia * media)3394 grl_media_get_height (GrlMedia *media)
3395 {
3396   g_return_val_if_fail (GRL_MEDIA (media), 0);
3397   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_HEIGHT);
3398 }
3399 
3400 /**
3401  * grl_media_get_framerate:
3402  * @media: the media instance
3403  *
3404  * Returns: the framerate of the media
3405  *
3406  * Since: 0.3.0
3407  */
3408 gfloat
grl_media_get_framerate(GrlMedia * media)3409 grl_media_get_framerate (GrlMedia *media)
3410 {
3411   g_return_val_if_fail (GRL_MEDIA (media), 0);
3412   return grl_data_get_float (GRL_DATA (media), GRL_METADATA_KEY_FRAMERATE);
3413 }
3414 
3415 /**
3416  * grl_media_get_season:
3417  * @media: the media instance
3418  *
3419  * Returns: the season number of the media
3420  *
3421  * Since: 0.3.0
3422  */
3423 gint
grl_media_get_season(GrlMedia * media)3424 grl_media_get_season (GrlMedia *media)
3425 {
3426   g_return_val_if_fail (GRL_MEDIA (media), 0);
3427   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_SEASON);
3428 }
3429 
3430 /**
3431  * grl_media_get_episode:
3432  * @media: the media instance
3433  *
3434  * Returns: the episode number of the media
3435  *
3436  * Since: 0.3.0
3437  */
3438 gint
grl_media_get_episode(GrlMedia * media)3439 grl_media_get_episode (GrlMedia *media)
3440 {
3441   g_return_val_if_fail (GRL_MEDIA (media), 0);
3442   return grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_EPISODE);
3443 }
3444 
3445 /**
3446  * grl_media_get_episode_title:
3447  * @media: the media instance
3448  *
3449  * Returns: the title of the episode
3450  *
3451  * Since: 0.3.0
3452  */
3453 const gchar *
grl_media_get_episode_title(GrlMedia * media)3454 grl_media_get_episode_title (GrlMedia *media)
3455 {
3456   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3457 
3458   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_EPISODE_TITLE);
3459 }
3460 
3461 /**
3462  * grl_media_get_show:
3463  * @media: the media instance
3464  *
3465  * Returns: the show title of the media
3466  *
3467  * Since: 0.3.0
3468  */
3469 const gchar *
grl_media_get_show(GrlMedia * media)3470 grl_media_get_show (GrlMedia *media)
3471 {
3472   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3473 
3474   return grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_SHOW);
3475 }
3476 
3477 /**
3478  * grl_media_get_performer:
3479  * @media: a #GrlMedia
3480  *
3481  * Returns: (transfer none): the actor performing in the movie (owned by @media).
3482  *
3483  * Since: 0.3.0
3484  */
3485 const gchar *
grl_media_get_performer(GrlMedia * media)3486 grl_media_get_performer (GrlMedia *media)
3487 {
3488   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3489   return grl_data_get_string (GRL_DATA (media),
3490                               GRL_METADATA_KEY_PERFORMER);
3491 }
3492 
3493 /**
3494  * grl_media_get_performer_nth:
3495  * @media: a #GrlMedia
3496  * @index: element to retrieve
3497  *
3498  * Returns: (transfer none): the actor performing in the movie (owned by @medi).
3499  *
3500  * Since: 0.3.0
3501  */
3502 const gchar *
grl_media_get_performer_nth(GrlMedia * media,guint index)3503 grl_media_get_performer_nth (GrlMedia *media,
3504                              guint index)
3505 {
3506   GrlRelatedKeys *relkeys;
3507 
3508   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3509 
3510   relkeys =
3511     grl_data_get_related_keys (GRL_DATA (media),
3512                                GRL_METADATA_KEY_PERFORMER,
3513                                index);
3514 
3515   if (!relkeys) {
3516     return NULL;
3517   }
3518 
3519   return grl_related_keys_get_string (relkeys,
3520                                       GRL_METADATA_KEY_PERFORMER);
3521 }
3522 
3523 /**
3524  * grl_media_get_producer:
3525  * @media: a #GrlMedia
3526  *
3527  * Returns: (transfer none): the producer of the movie (owned by @media).
3528  *
3529  * Since: 0.3.0
3530  */
3531 const gchar *
grl_media_get_producer(GrlMedia * media)3532 grl_media_get_producer (GrlMedia *media)
3533 {
3534   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3535   return grl_data_get_string (GRL_DATA (media),
3536                               GRL_METADATA_KEY_PRODUCER);
3537 }
3538 
3539 /**
3540  * grl_media_get_producer_nth:
3541  * @media: a #GrlMedia
3542  * @index: element to retrieve
3543  *
3544  * Returns: (transfer none): the producer of the movie (owned by @media).
3545  *
3546  * Since: 0.3.0
3547  */
3548 const gchar *
grl_media_get_producer_nth(GrlMedia * media,guint index)3549 grl_media_get_producer_nth (GrlMedia *media,
3550                             guint index)
3551 {
3552   GrlRelatedKeys *relkeys;
3553 
3554   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3555 
3556   relkeys =
3557     grl_data_get_related_keys (GRL_DATA (media),
3558                                GRL_METADATA_KEY_PRODUCER,
3559                                index);
3560 
3561   if (!relkeys) {
3562     return NULL;
3563   }
3564 
3565   return grl_related_keys_get_string (relkeys,
3566                                       GRL_METADATA_KEY_PRODUCER);
3567 }
3568 
3569 /**
3570  * grl_media_get_director:
3571  * @media: a #GrlMedia
3572  *
3573  * Returns: (transfer none): the director of the movie (owned by @media).
3574  *
3575  * Since: 0.3.0
3576  */
3577 const gchar *
grl_media_get_director(GrlMedia * media)3578 grl_media_get_director (GrlMedia *media)
3579 {
3580   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3581   return grl_data_get_string (GRL_DATA (media),
3582                               GRL_METADATA_KEY_DIRECTOR);
3583 }
3584 
3585 /**
3586  * grl_media_get_director_nth:
3587  * @media: a #GrlMedia
3588  * @index: element to retrieve
3589  *
3590  * Returns: (transfer none): the director of the movie (owned by @media).
3591  *
3592  * Since: 0.3.0
3593  */
3594 const gchar *
grl_media_get_director_nth(GrlMedia * media,guint index)3595 grl_media_get_director_nth (GrlMedia *media,
3596                             guint index)
3597 {
3598   GrlRelatedKeys *relkeys;
3599 
3600   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3601 
3602   relkeys =
3603     grl_data_get_related_keys (GRL_DATA (media),
3604                                GRL_METADATA_KEY_DIRECTOR,
3605                                index);
3606 
3607   if (!relkeys) {
3608     return NULL;
3609   }
3610 
3611   return grl_related_keys_get_string (relkeys,
3612                                       GRL_METADATA_KEY_DIRECTOR);
3613 }
3614 
3615 /**
3616  * grl_media_get_original_title:
3617  * @media: a #GrlMedia
3618  *
3619  * Returns: (transfer none): the original, untranslated title of the movie (owned by @media).
3620  *
3621  * Since: 0.3.0
3622  */
3623 const gchar *
grl_media_get_original_title(GrlMedia * media)3624 grl_media_get_original_title (GrlMedia *media)
3625 {
3626   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3627   return grl_data_get_string (GRL_DATA (media),
3628                               GRL_METADATA_KEY_ORIGINAL_TITLE);
3629 }
3630 
3631 /**
3632  * grl_media_get_camera_model:
3633  * @media: the media instance
3634  *
3635  * Returns: model of camera used to take picture
3636  *
3637  * Since: 0.3.0
3638  */
3639 const gchar *
grl_media_get_camera_model(GrlMedia * media)3640 grl_media_get_camera_model (GrlMedia *media)
3641 {
3642   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3643   return grl_data_get_string (GRL_DATA (media),
3644                               GRL_METADATA_KEY_CAMERA_MODEL);
3645 }
3646 
3647 /**
3648  * grl_media_get_flash_used:
3649  * @media: the media instance
3650  *
3651  * Returns: whether the flash was used.
3652  *
3653  * See
3654  * http://library.gnome.org/devel/ontology/unstable/nmm-classes.html#nmm-Flash
3655  *
3656  * Since: 0.3.0
3657  */
3658 const gchar *
grl_media_get_flash_used(GrlMedia * media)3659 grl_media_get_flash_used (GrlMedia *media)
3660 {
3661   g_return_val_if_fail (GRL_IS_MEDIA (media), NULL);
3662   return grl_data_get_string (GRL_DATA (media),
3663                               GRL_METADATA_KEY_FLASH_USED);
3664 }
3665 
3666 /**
3667  * grl_media_get_exposure_time:
3668  * @media: the media instance
3669  *
3670  * Returns: picture's exposure time
3671  *
3672  * Since: 0.3.0
3673  */
3674 gfloat
grl_media_get_exposure_time(GrlMedia * media)3675 grl_media_get_exposure_time (GrlMedia *media)
3676 {
3677   g_return_val_if_fail (GRL_IS_MEDIA (media), 0.0);
3678   return grl_data_get_float (GRL_DATA (media),
3679                              GRL_METADATA_KEY_EXPOSURE_TIME);
3680 }
3681 
3682 /**
3683  * grl_media_get_iso_speed:
3684  * @media: the media instance
3685  *
3686  * Returns: picture's iso speed
3687  *
3688  * Since: 0.3.0
3689  */
3690 gfloat
grl_media_get_iso_speed(GrlMedia * media)3691 grl_media_get_iso_speed (GrlMedia *media)
3692 {
3693   g_return_val_if_fail (GRL_IS_MEDIA (media), 0.0);
3694   return grl_data_get_float (GRL_DATA (media),
3695                              GRL_METADATA_KEY_ISO_SPEED);
3696 }
3697 
3698 /**
3699  * grl_media_get_orientation:
3700  * @media: the image instance
3701  *
3702  * Returns: degrees clockwise orientation of the picture
3703  *
3704  * Since: 0.3.0
3705  */
3706 gint
grl_media_get_orientation(GrlMedia * media)3707 grl_media_get_orientation (GrlMedia *media)
3708 {
3709   g_return_val_if_fail (GRL_IS_MEDIA (media), 0.0);
3710   return grl_data_get_int (GRL_DATA (media),
3711                            GRL_METADATA_KEY_ORIENTATION);
3712 }
3713 
3714 /**
3715  * grl_media_get_childcount:
3716  * @media: the media container instance
3717  *
3718  * Number of children of this container.
3719  *
3720  * Returns: number of children, or #GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN if
3721  * unknown.
3722  *
3723  * Since: 0.3.0
3724  */
3725 gint
grl_media_get_childcount(GrlMedia * media)3726 grl_media_get_childcount (GrlMedia *media)
3727 {
3728   const GValue *value;
3729 
3730   g_return_val_if_fail (GRL_IS_MEDIA (media), GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN);
3731   g_return_val_if_fail (grl_media_is_container (media), GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN);
3732 
3733   value = grl_data_get (GRL_DATA (media),
3734                         GRL_METADATA_KEY_CHILDCOUNT);
3735 
3736   if (value) {
3737     return g_value_get_int (value);
3738   } else {
3739     return GRL_METADATA_KEY_CHILDCOUNT_UNKNOWN;
3740   }
3741 }
3742