summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJaime Marquínez Ferrándiz <[email protected]>2013-07-19 20:43:44 +0200
committerJaime Marquínez Ferrándiz <[email protected]>2013-07-19 20:43:44 +0200
commitde7a91bfe3f761940bf7697653c505dbc229ce6b (patch)
tree818580c6b6dd6296c9b54909f5cfc7485c93483b
parenta4358cbabd6b9e6b4bd4f26210c9db1960c21d52 (diff)
downloadyoutube-dl-de7a91bfe3f761940bf7697653c505dbc229ce6b.tar.gz
youtube-dl-de7a91bfe3f761940bf7697653c505dbc229ce6b.zip
WeiboIE: extract the player urls from a json webpage
Also extract a Sina url that doesn't require to follow a redirection.
-rw-r--r--youtube_dl/extractor/weibo.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/youtube_dl/extractor/weibo.py b/youtube_dl/extractor/weibo.py
index efcb5912b..0757495bd 100644
--- a/youtube_dl/extractor/weibo.py
+++ b/youtube_dl/extractor/weibo.py
@@ -1,6 +1,7 @@
# coding: utf-8
import re
+import json
from .common import InfoExtractor
@@ -30,8 +31,18 @@ class WeiboIE(InfoExtractor):
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
video_id = mobj.group('id')
- webpage = self._download_webpage(url, video_id)
- player_url = self._search_regex(r'var defaultPlayer="(.+?)"', webpage,
- u'player url')
+ info_url = 'http://video.weibo.com/?s=v&a=play_list&format=json&mix_video_id=t_%s' % video_id
+ info_page = self._download_webpage(info_url, video_id)
+ info = json.loads(info_page)
+
+ videos_urls = map(lambda v: v['play_page_url'], info['result']['data'])
+ #Prefer sina video since they have thumbnails
+ videos_urls = sorted(videos_urls, key=lambda u: u'video.sina.com' in u)
+ player_url = videos_urls[-1]
+ m_sina = re.match(r'https?://video.sina.com.cn/v/b/(\d+)-\d+.html', player_url)
+ if m_sina is not None:
+ self.to_screen('Sina video detected')
+ sina_id = m_sina.group(1)
+ player_url = 'http://you.video.sina.com.cn/swf/quotePlayer.swf?vid=%s' % sina_id
return self.url_result(player_url)