Skip to content

Instantly share code, notes, and snippets.

@yanbe
Created April 24, 2009 05:23
Show Gist options
  • Save yanbe/100963 to your computer and use it in GitHub Desktop.
Save yanbe/100963 to your computer and use it in GitHub Desktop.
patch for Totem YouTube plugin that enables HD movies a.k.a &fmt=22.
--- youtube.py.orig 2009-04-24 12:40:50.861929605 +0900
+++ youtube.py 2009-04-25 02:35:27.190928256 +0900
@@ -3,6 +3,7 @@
gobject.threads_init()
import gdata.service
import urllib
+import urllib2
import httplib
import atom
import threading
@@ -195,9 +196,15 @@
if self.debug:
print "Done activating row"
- def get_fmt_string (self):
+ def get_fmt_string (self, url_without_fmt):
if self.gconf_client.get_int ("/apps/totem/connection_speed") >= 10:
- return "&fmt=18"
+ try:
+ c = urllib2.urlopen(url_without_fmt + "&fmt=22")
+ except IOError:
+ return "&fmt=18"
+ else:
+ c.close()
+ return "&fmt=22"
else:
return ""
@@ -241,7 +248,8 @@
youtube_id = model.get_value (iter, 3)
"""Open the video in the browser"""
- os.spawnlp (os.P_NOWAIT, "xdg-open", "xdg-open", "http://www.youtube.com/watch?v=" + urllib.quote (youtube_id) + self.get_fmt_string ())
+ url_without_fmt="http://www.youtube.com/watch?v=" + urllib.quote (youtube_id)
+ os.spawnlp (os.P_NOWAIT, "xdg-open", "xdg-open", url_without_fmt + self.get_fmt_string (url_without_fmt))
def on_button_press_event (self, widget, event):
self.button_down = True
@@ -334,7 +342,8 @@
t_param = self.resolve_t_param (youtube_id)
if t_param != "":
- mrl = "http://www.youtube.com/get_video?video_id=" + urllib.quote (youtube_id) + "&t=" + urllib.quote (t_param) + self.get_fmt_string ()
+ mrl = "http://www.youtube.com/get_video?video_id=" + urllib.quote (youtube_id) + "&t=" + urllib.quote (t_param)
+ mrl += self.get_fmt_string (mrl)
gobject.idle_add (self._append_to_liststore, treeview_name, pixbuf, entry.title.text, mrl, youtube_id, search_token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment