2 from __future__ import unicode_literals
4 from .common import InfoExtractor
10 from ..compat import (
20 class WeiboIE(InfoExtractor):
21 _VALID_URL = r'https?://weibo\.com/[0-9]+/(?P<id>[a-zA-Z0-9]+)'
23 'url': 'https://weibo.com/6275294458/Fp6RGfbff?type=comment',
27 'title': 'You should have servants to massage you,... 来自Hosico_猫 - 微博',
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33 # to get Referer url for genvisitor
34 webpage, urlh = self._download_webpage_handle(url, video_id, note="first visit the page")
36 visitor_url = urlh.geturl()
38 'Referer': visitor_url
43 "browser": "Gecko57,0,0,0",
45 "screenInfo": "1440*900*24",
48 data = urlencode_postdata({
53 genvisitor_url = 'https://passport.weibo.com/visitor/genvisitor'
54 webpage, _ = self._download_webpage_handle(genvisitor_url, video_id, data=data, headers=headers, note="gen visitor")
56 p = strip_jsonp(webpage)
59 j = p[i1:i2 + 1] # get JSON object
61 tid = d["data"]["tid"]
62 cnfd = "%03d" % d["data"]["confidence"]
71 '_rand': random.random()
73 gencallback_url = "https://passport.weibo.com/visitor/visitor"
74 self._download_webpage_handle(gencallback_url, video_id, note="gen callback", query=query)
76 webpage, _ = self._download_webpage_handle(url, video_id, note="retry to visit the page")
78 title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title')
80 video_sources_text = self._search_regex(r'video-sources=\\\"(.+?)\"', webpage, 'video_sources')
82 video_formats = compat_urlparse.parse_qs(video_sources_text)
85 supported_resolutions = ('720', '480')
86 for res in supported_resolutions:
87 f = video_formats.get(res)
88 if isinstance(f, list):
96 self._sort_formats(formats)
97 uploader = self._og_search_property('nick-name', webpage, 'uploader', default=None)
101 'uploader': uploader,
106 class WeiboMobileIE(InfoExtractor):
107 _VALID_URL = r'https?://m\.weibo\.cn/status/(?P<id>[0-9]+)(\?.+)?'
109 'url': 'https://m.weibo.cn/status/4189191225395228?wm=3333_2001&sourcetype=weixin&featurecode=newtitle&from=singlemessage&isappinstalled=0',
111 'id': '4189191225395228',
113 'title': '午睡当然是要甜甜蜜蜜的啦',
118 def _real_extract(self, url):
119 video_id = self._match_id(url)
120 # to get Referer url for genvisitor
121 webpage, _ = self._download_webpage_handle(url, video_id, note="visit the page")
122 js_code = self._search_regex(r'var\s+\$render_data\s*=\s*\[({.*})\]\[0\] \|\| {};', webpage, 'js_code', flags=re.DOTALL)
123 weibo_info = self._parse_json(js_code, video_id, transform_source=js_to_json)
124 page_info = weibo_info['status']['page_info']
125 title = weibo_info.get('status').get('status_title')
126 uploader = weibo_info.get('status').get('user').get('screen_name')
131 'uploader': uploader,
132 'url': page_info['media_info']['stream_url']