summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <pwithnall@svn.gnome.org>2007-10-24 19:17:45 +0000
committerPhilip Withnall <pwithnall@src.gnome.org>2007-10-24 19:17:45 +0000
commit9633b37987967ce8564ef7c9d3d855beac55905c (patch)
tree2c6352a1786d1860f0123b847537f05564bcc95c
parent03eb7599ece6f79570dfab854d54475e2df18612 (diff)
downloadtotem-9633b37987967ce8564ef7c9d3d855beac55905c.tar.gz
Add a signal to TotemVideoList to allow users of it to set the MRL just
2007-10-24 Philip Withnall <pwithnall@svn.gnome.org> * src/Makefile.am: * src/plugins/youtube/youtube.py: * src/totem-video-list.c: (totem_video_list_class_init), (query_tooltip_cb), (row_activated_cb), (default_starting_video_cb): * src/totem-video-list.h: * src/totemvideolist-marshal.list: Add a signal to TotemVideoList to allow users of it to set the MRL just before a video is played, which solves YouTube's slowness problem. Also, display the MRL as part of the tooltips on the TotemVideoList. svn path=/trunk/; revision=4815
-rw-r--r--ChangeLog13
-rw-r--r--src/Makefile.am13
-rw-r--r--src/plugins/youtube/youtube.py43
-rw-r--r--src/totem-video-list.c60
-rw-r--r--src/totem-video-list.h1
-rw-r--r--src/totemvideolist-marshal.list1
6 files changed, 108 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 59f1d63f6..c7e1dd9cb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-10-24 Philip Withnall <pwithnall@svn.gnome.org>
+
+ * src/Makefile.am:
+ * src/plugins/youtube/youtube.py:
+ * src/totem-video-list.c: (totem_video_list_class_init),
+ (query_tooltip_cb), (row_activated_cb),
+ (default_starting_video_cb):
+ * src/totem-video-list.h:
+ * src/totemvideolist-marshal.list: Add a signal to TotemVideoList
+ to allow users of it to set the MRL just before a video is played,
+ which solves YouTube's slowness problem. Also, display the MRL as part
+ of the tooltips on the TotemVideoList.
+
2007-10-24 Bastien Nocera <hadess@hadess.net>
* src/plparse/totem-pl-parser-podcast.c:
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d5d88a72..7d1873c49 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -77,7 +77,9 @@ libtotem_player_la_LDFLAGS = \
# Totem
-TOTEMMARSHALFILES = totemobject-marshal.c totemobject-marshal.h
+TOTEMMARSHALFILES = \
+ totemobject-marshal.c totemobject-marshal.h \
+ totemvideolist-marshal.c totemvideolist-marshal.h
GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
BUILT_SOURCES = $(TOTEMMARSHALFILES)
@@ -85,6 +87,10 @@ totemobject-marshal.h: totemobject-marshal.list Makefile
( $(GLIB_GENMARSHAL) --prefix=totemobject_marshal $(srcdir)/totemobject-marshal.list --header > totemobject-marshal.h )
totemobject-marshal.c: totemobject-marshal.h Makefile
( $(GLIB_GENMARSHAL) --prefix=totemobject_marshal $(srcdir)/totemobject-marshal.list --header --body > totemobject-marshal.c )
+totemvideolist-marshal.h: totemvideolist-marshal.list Makefile
+ ( $(GLIB_GENMARSHAL) --prefix=totemvideolist_marshal $(srcdir)/totemvideolist-marshal.list --header > totemvideolist-marshal.h )
+totemvideolist-marshal.c: totemvideolist-marshal.h Makefile
+ ( $(GLIB_GENMARSHAL) --prefix=totemvideolist_marshal $(srcdir)/totemvideolist-marshal.list --header --body > totemvideolist-marshal.c )
totem_SOURCES = \
totem.c totem.h \
@@ -358,4 +364,7 @@ CLEANFILES = \
$(desktop_DATA) \
$(BUILT_SOURCES)
-EXTRA_DIST = totemobject-marshal.list
+EXTRA_DIST = \
+ totemobject-marshal.list \
+ totemvideolist-marshal.list
+
diff --git a/src/plugins/youtube/youtube.py b/src/plugins/youtube/youtube.py
index 17bd797e0..ce88c7019 100644
--- a/src/plugins/youtube/youtube.py
+++ b/src/plugins/youtube/youtube.py
@@ -42,6 +42,7 @@ class YouTube (totem.Plugin):
self.treeview = self.builder.get_object ("yt_treeview")
self.treeview.set_property ("totem", totem_object)
self.treeview.connect ("row-activated", self.on_row_activated)
+ self.treeview.connect ("starting-video", self.on_starting_video)
self.treeview.insert_column_with_attributes (0, _("Videos"), self.renderer, thumbnail=0, title=1)
self.vadjust = self.treeview.get_vadjustment ()
@@ -72,6 +73,29 @@ class YouTube (totem.Plugin):
self.start_index = 1
self.results = 0
self.get_results ("/feeds/videos/" + urllib.quote (youtube_id) + "/related?max-results=" + str (self.max_results), _("Related Videos:"))
+ def on_starting_video (self, treeview, path, user_data):
+ model, iter = treeview.get_selection ().get_selected ()
+ youtube_id = model.get_value (iter, 3)
+
+ """Get the video stream MRL"""
+ try:
+ conn = httplib.HTTPConnection ("www.youtube.com")
+ conn.request ("GET", "/v/" + urllib.quote (youtube_id))
+ response = conn.getresponse ()
+ except:
+ print "Could not resolve stream MRL for YouTube video \"" + youtube_id + "\"."
+ return True
+
+ if response.status == 303:
+ location = response.getheader("location")
+ mrl = "http://www.youtube.com/get_video?video_id=" + urllib.quote (youtube_id) + "&t=" + urllib.quote (re.match (".*[?&]t=([^&]+)", location).groups ()[0])
+ else:
+ mrl = "http://www.youtube.com/v/" + urllib.quote (youtube_id)
+ conn.close ()
+
+ model.set_value (iter, 2, mrl)
+
+ return True
def on_button_press_event (self, widget, event):
self.button_down = True
def on_button_release_event (self, widget, event):
@@ -95,27 +119,12 @@ class YouTube (totem.Plugin):
if self.entry == None or len (self.entry) == 0:
return True
- """Only do one result at a time, as the thumbnail has to be downloaded"""
+ """Only do one result at a time, as the thumbnail has to be downloaded; give them a temporary MRL until the real one is resolved before playing"""
entry = self.entry.pop (0)
self.results += 1
self.start_index += 1
youtube_id = self.convert_url_to_id (entry.id.text)
-
- """Get the video stream MRL"""
- try:
- conn = httplib.HTTPConnection ("www.youtube.com")
- conn.request ("GET", "/v/" + urllib.quote (youtube_id))
- response = conn.getresponse ()
- except:
- print "Could not resolve stream MRL for YouTube video \"" + youtube_id + "\"."
- return True
-
- if response.status == 303:
- location = response.getheader("location")
- mrl = "http://www.youtube.com/get_video?video_id=" + urllib.quote (youtube_id) + "&t=" + urllib.quote (re.match (".*[?&]t=([^&]+)", location).groups ()[0])
- else:
- mrl = "http://www.youtube.com/v/" + urllib.quote (youtube_id)
- conn.close ()
+ mrl = "http://www.youtube.com/v/" + urllib.quote (youtube_id)
"""Find the thumbnail tag"""
for _element in entry.extension_elements:
diff --git a/src/totem-video-list.c b/src/totem-video-list.c
index 8328a4aa5..6506be885 100644
--- a/src/totem-video-list.c
+++ b/src/totem-video-list.c
@@ -30,11 +30,13 @@
#include <glib.h>
#include <glib/gi18n.h>
+#include <glib/gprintf.h>
#include "totem.h"
#include "totem-video-list.h"
#include "totem-private.h"
#include "totem-playlist.h"
+#include "totemvideolist-marshal.h"
struct _TotemVideoListPrivate {
gboolean dispose_has_run;
@@ -51,11 +53,19 @@ enum {
PROP_TOTEM
};
+enum {
+ STARTING_VIDEO,
+ LAST_SIGNAL
+};
+
static void totem_video_list_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void totem_video_list_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static gboolean query_tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data);
static void selection_changed_cb (GtkTreeSelection *selection, GtkWidget *tree_view);
static void row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
+static gboolean default_starting_video_cb (TotemVideoList *video_list, GtkTreePath *path);
+
+static gint totem_video_list_table_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (TotemVideoList, totem_video_list, GTK_TYPE_TREE_VIEW)
@@ -84,6 +94,16 @@ totem_video_list_class_init (TotemVideoListClass *klass)
g_object_class_install_property (object_class, PROP_TOTEM,
g_param_spec_object ("totem", NULL, NULL,
TOTEM_TYPE_OBJECT, G_PARAM_READWRITE));
+
+ klass->starting_video = default_starting_video_cb;
+ totem_video_list_table_signals[STARTING_VIDEO] = g_signal_new ("starting-video",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (TotemVideoListClass, starting_video),
+ NULL, NULL,
+ totemvideolist_marshal_BOOLEAN__OBJECT_OBJECT,
+ G_TYPE_BOOLEAN, 2,
+ TOTEM_TYPE_VIDEO_LIST, GTK_TYPE_TREE_PATH);
}
static void
@@ -152,6 +172,8 @@ query_tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk
TotemVideoList *self = TOTEM_VIDEO_LIST (widget);
GtkTreeIter iter;
gchar *tooltip_text;
+ gchar *mrl_text;
+ gchar *final_text;
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
GtkTreePath *path = NULL;
@@ -164,12 +186,25 @@ query_tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard_mode, Gtk
&model, &path, &iter))
return FALSE;
- gtk_tree_model_get (model, &iter, self->priv->tooltip_column, &tooltip_text, -1);
- gtk_tooltip_set_text (tooltip, tooltip_text);
- gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
+ if (self->priv->mrl_column == -1) {
+ gtk_tree_model_get (model, &iter, self->priv->tooltip_column, &tooltip_text, -1);
+ gtk_tooltip_set_text (tooltip, tooltip_text);
+ g_free (tooltip_text);
+ } else {
+ gtk_tree_model_get (model, &iter,
+ self->priv->tooltip_column, &tooltip_text,
+ self->priv->mrl_column, &mrl_text,
+ -1);
+ final_text = g_strdup_printf ("%s\n%s", tooltip_text, mrl_text);
+ gtk_tooltip_set_text (tooltip, final_text);
+
+ g_free (tooltip_text);
+ g_free (mrl_text);
+ g_free (final_text);
+ }
+ gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
gtk_tree_path_free (path);
- g_free (tooltip_text);
return TRUE;
}
@@ -185,15 +220,32 @@ row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *
{
GtkTreeIter iter;
gchar *mrl;
+ gboolean play_video = TRUE;
TotemVideoList *self = TOTEM_VIDEO_LIST (tree_view);
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
if (self->priv->mrl_column == -1)
return;
+ g_signal_emit (G_OBJECT (tree_view), totem_video_list_table_signals[STARTING_VIDEO], 0,
+ self,
+ path,
+ &play_video);
+
+ if (play_video == FALSE)
+ return;
+
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, self->priv->mrl_column, &mrl, -1);
totem_action_set_mrl_and_play (self->priv->totem, mrl);
g_free (mrl);
}
+
+static gboolean
+default_starting_video_cb (TotemVideoList *video_list, GtkTreePath *path)
+{
+ /* Play the video by default */
+ return TRUE;
+}
+
diff --git a/src/totem-video-list.h b/src/totem-video-list.h
index d5069b8a8..8b860a947 100644
--- a/src/totem-video-list.h
+++ b/src/totem-video-list.h
@@ -50,6 +50,7 @@ typedef struct {
typedef struct {
GtkTreeViewClass parent;
+ gboolean (*starting_video) (TotemVideoList *video_list, GtkTreePath *path);
} TotemVideoListClass;
GType totem_video_list_get_type (void);
diff --git a/src/totemvideolist-marshal.list b/src/totemvideolist-marshal.list
new file mode 100644
index 000000000..1d1280d87
--- /dev/null
+++ b/src/totemvideolist-marshal.list
@@ -0,0 +1 @@
+BOOLEAN:OBJECT,OBJECT