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

[plamo:30704] Re: totem youtubeプラグイン



From: KOJIMA Mitsuhiro <kojima@xxxxxxxxxxx>
Subject: [plamo:30703] Re: totem youtube プラグイン
Date: Mon, 26 Jul 2010 22:19:32 +0900 (JST)

> YouTube plugin の python 版は 2.26 で打ち止めで,以降は C 版になっているから,
> 今さら古い python 版に backport してくれる人もいないだろうなぁ..
> 

ということで,とりあえず quick hack してみました.

ざっとC版のパッチをなぞって URL を拾っているだけで,エラー時の処理とか
は無視しているけど,まぁ次のメジャーリリースまでのつなぎになればいいかと.

# その前にまた YouTube の API が変りそうだけど :-P


--- ./src/plugins/youtube/youtube.py	2009-11-19 23:42:24.000000000 +0900
+++ /usr/lib/totem/plugins/youtube/youtube.py	2010-07-27 12:38:18.004810389 +0900
@@ -60,6 +60,7 @@
 	def __init__ (self):
 		totem.Plugin.__init__ (self)
 		self.debug = False
+		# self.debug = True
 		self.gstreamer_plugins_present = True
 
 		"""Search counters (per search type)"""
@@ -183,6 +184,8 @@
 		model, rows = treeview.get_selection ().get_selected_rows ()
 		iter = model.get_iter (rows[0])
 		youtube_id = model.get_value (iter, 3)
+		if self.debug:
+			print "debug:youtube_id",youtube_id
 
 		"""Get related videos"""
 		self.youtube_id = youtube_id
@@ -204,13 +207,18 @@
 	def resolve_t_param (self, youtube_id):
 		"""We have to get the t parameter from the actual video page, since Google changed how their URLs work"""
 		stream = urllib.urlopen ("http://youtube.com/watch?v="; + urllib.quote (youtube_id))
-		regexp1 = re.compile ("swfArgs.*\"t\": \"([^\"]+)\"")
+		# regexp1 = re.compile ("swfHTML = .*&t=([^&]+)&")
+		regexp1 = re.compile ("fmt_stream_map=([^&]+)&")
 		regexp2 = re.compile ("</head>")
 
 		contents = stream.read ()
+		if self.debug:
+			print "debug: contents:",contents
 		if contents != "":
 			"""Check for the t parameter, which is now in a JavaScript array on the video page"""
 			matches = regexp1.search (contents)
+			if self.debug:
+				print "debug: matches.group(1):", matches.group(1)
 			if (matches != None):
 				stream.close ()
 				return matches.group (1)
@@ -331,10 +339,23 @@
 		os.unlink (filename)
 
 		"""Get the video stream MRL"""
-		t_param = self.resolve_t_param (youtube_id)
+		quoted_param = self.resolve_t_param(youtube_id)
+		
+		fmt_stream_param = urllib.unquote(quoted_param)
+		param_list = fmt_stream_param.split(',')
+		tmp_param = param_list[0]
+		fmt_list =  tmp_param.split('|')
+		t_param = fmt_list[1]
+		if self.debug:
+			print "debug: quoted_param:", quoted_param
+			print "debug: fmt_stream_param:", fmt_stream_param
+			print "debug: param_list:", param_list
+			print "debug: tmp_param:", tmp_param
+			print "debug: fmt_list:",fmt_list
 
 		if t_param != "":
-			mrl = "http://www.youtube.com/get_video?video_id="; + urllib.quote (youtube_id) + "&t=" + t_param + self.get_fmt_string ()
+			# mrl = "http://www.youtube.com/get_video?video_id="; + urllib.quote (youtube_id) + "&t=" + t_param + self.get_fmt_string ()
+			mrl = t_param
 
 		gobject.idle_add (self._append_to_liststore, treeview_name, pixbuf, entry.title.text, mrl, youtube_id, search_token)
 


Follow-Ups
[plamo:30706] Re: totem youtube プラグイン, M.H
References
[plamo:30697] Re: totem youtubeプラグイン, KOJIMA Mitsuhiro
[plamo:30700] Re: totem youtube プラグイン, M.H
[plamo:30703] Re: totem youtubeプラグイン, KOJIMA Mitsuhiro

[検索ページ] [メール一覧]
Plamo ML 公開システム