From 0ac22e4f5a652f1b470f9daff06c1361e8f93c16 Mon Sep 17 00:00:00 2001
From: Philipp Hagemeister <phihag@phihag.de>
Date: Thu, 4 Aug 2011 00:04:55 +0200
Subject: [PATCH] Fix youtube downloads (Closes #135)

---
 youtube-dl | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/youtube-dl b/youtube-dl
index 27ae816e0..0d77585a8 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -1248,14 +1248,11 @@ class YoutubeIE(InfoExtractor):
 		# Decide which formats to download
 		req_format = self._downloader.params.get('format', None)
 
-		raw_map = None
-		if 'fmt_url_map' in video_info and len(video_info['fmt_url_map']) >= 1:
-			raw_map = video_info['fmt_url_map'][0]
-		elif 'fmt_stream_map' in video_info and len(video_info['fmt_stream_map']) >= 1:
-			raw_map = video_info['fmt_stream_map'][0]
-
-		if raw_map is not None:
-			url_map = dict(tuple(pair.split('|')[:2]) for pair in raw_map.split(','))
+		if 'url_encoded_fmt_stream_map' in video_info and len(video_info['url_encoded_fmt_stream_map']) >= 1:
+			url_data_strs = video_info['url_encoded_fmt_stream_map'][0].split(',')
+			url_data = [dict(pairStr.split('=') for pairStr in uds.split('&')) for uds in url_data_strs]
+			url_map = dict((ud['itag'], urllib.unquote(ud['url'])) for ud in url_data)
+			
 			format_limit = self._downloader.params.get('format_limit', None)
 			if format_limit is not None and format_limit in self._available_formats:
 				format_list = self._available_formats[self._available_formats.index(format_limit):]