[totem] grilo: Handle series episodes better



commit 30edc54a43f460b3d3393a55e073cf6a1cfff112
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jan 23 18:51:45 2014 +0100

    grilo: Handle series episodes better
    
    Use show name, season and episode numbers when available.

 src/plugins/grilo/totem-grilo.c |   59 +++++++++++++++++++++++++++++++++++---
 1 files changed, 54 insertions(+), 5 deletions(-)
---
diff --git a/src/plugins/grilo/totem-grilo.c b/src/plugins/grilo/totem-grilo.c
index 87775d5..cf53dfb 100644
--- a/src/plugins/grilo/totem-grilo.c
+++ b/src/plugins/grilo/totem-grilo.c
@@ -160,6 +160,15 @@ get_secondary_text (GrlMedia *media)
        const char *artist;
        int duration;
 
+       if (grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_SHOW) != NULL) {
+               int season, episode;
+
+               season = grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_SEASON);
+               episode = grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_EPISODE);
+               if (season != 0 && episode != 0)
+                       return g_strdup_printf (_("Season %d Episode %d"), season, episode);
+       }
+
        artist = grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ARTIST);
        if (artist != NULL)
                return g_strdup (artist);
@@ -169,6 +178,38 @@ get_secondary_text (GrlMedia *media)
        return NULL;
 }
 
+static const char *
+get_primary_text (GrlMedia *media)
+{
+       const char *show;
+
+       show = grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_SHOW);
+       if (show)
+               return show;
+       return grl_media_get_title (media);
+}
+
+static char *
+get_title (GrlMedia *media)
+{
+       const char *show;
+
+       show = grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_SHOW);
+       if (show != NULL) {
+               int season, episode;
+
+               season = grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_SEASON);
+               episode = grl_data_get_int (GRL_DATA (media), GRL_METADATA_KEY_EPISODE);
+               if (season != 0 && episode != 0) {
+                       /* translators: The first item is the show name, for example:
+                        * Boardwalk Empire (Season 1 Episode 1) */
+                       return g_strdup_printf (_("%s (Season %d Episode %d)"), show, season, episode);
+               }
+       }
+
+       return g_strdup (grl_media_get_title (media));
+}
+
 static void
 get_thumbnail_cb (GObject *source_object,
                  GAsyncResult *res,
@@ -368,7 +409,7 @@ update_media (GtkTreeStore *model,
                            MODEL_RESULTS_CONTENT, media,
                            GD_MAIN_COLUMN_ICON, thumbnail,
                            MODEL_RESULTS_IS_PRETHUMBNAIL, thumbnailing,
-                           GD_MAIN_COLUMN_PRIMARY_TEXT, grl_media_get_title (media),
+                           GD_MAIN_COLUMN_PRIMARY_TEXT, get_primary_text (media),
                            GD_MAIN_COLUMN_SECONDARY_TEXT, secondary,
                            GD_MAIN_COLUMN_MTIME, mtime ? g_date_time_to_unix (mtime) : 0,
                            -1);
@@ -437,7 +478,7 @@ add_media_to_model (GtkTreeStore *model,
                                           MODEL_RESULTS_CONTENT, media,
                                           GD_MAIN_COLUMN_ICON, thumbnail,
                                           MODEL_RESULTS_IS_PRETHUMBNAIL, thumbnailing,
-                                          GD_MAIN_COLUMN_PRIMARY_TEXT, grl_media_get_title (media),
+                                          GD_MAIN_COLUMN_PRIMARY_TEXT, get_primary_text (media),
                                           GD_MAIN_COLUMN_SECONDARY_TEXT, secondary,
                                           GD_MAIN_COLUMN_MTIME, mtime ? g_date_time_to_unix (mtime) : 0,
                                           MODEL_RESULTS_SORT_PRIORITY, prio,
@@ -562,6 +603,7 @@ play (TotemGriloPlugin *self,
       gboolean resolve_url)
 {
        const gchar *url;
+       char *title;
 
        url = grl_media_get_url (media);
        if (!url)
@@ -574,9 +616,11 @@ play (TotemGriloPlugin *self,
        }
 
        totem_object_clear_playlist (self->priv->totem);
+       title = get_title (media);
        totem_object_add_to_playlist (self->priv->totem, url,
-                                     grl_media_get_title (media),
+                                     title,
                                      TRUE);
+       g_free (title);
 }
 
 static void
@@ -1585,6 +1629,7 @@ play_selection (TotemGriloPlugin *self,
                GtkTreeIter iter;
                GrlMedia *media;
                const gchar *url;
+               char *title;
 
                gtk_tree_model_get_iter (model, &iter, path);
                gtk_tree_model_get (model, &iter,
@@ -1601,9 +1646,10 @@ play_selection (TotemGriloPlugin *self,
                        goto next_item;
                }
 
+               title = get_title (media);
                totem_object_add_to_playlist (self->priv->totem, url,
-                                             grl_media_get_title (media),
-                                             first);
+                                             title, first);
+               g_free (title);
                first = FALSE;
 
 next_item:
@@ -1906,6 +1952,9 @@ impl_activate (PeasActivatable *plugin)
                                                         GRL_METADATA_KEY_THUMBNAIL,
                                                         GRL_METADATA_KEY_URL,
                                                         GRL_METADATA_KEY_TITLE,
+                                                        GRL_METADATA_KEY_SHOW,
+                                                        GRL_METADATA_KEY_SEASON,
+                                                        GRL_METADATA_KEY_EPISODE,
                                                         NULL);
 
        builder = gtk_builder_new_from_resource ("/org/totem/grilo/grilo.ui");


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