You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class WeiboIE(InfoExtractor):
  6. """
  7. The videos in Weibo come from different sites, this IE just finds the link
  8. to the external video and returns it.
  9. """
  10. _VALID_URL = r'https?://video\.weibo\.com/v/weishipin/t_(?P<id>.+?)\.htm'
  11. _TEST = {
  12. 'url': 'http://video.weibo.com/v/weishipin/t_zjUw2kZ.htm',
  13. 'info_dict': {
  14. 'id': '98322879',
  15. 'ext': 'flv',
  16. 'title': '魔声耳机最新广告“All Eyes On Us”',
  17. },
  18. 'params': {
  19. 'skip_download': True,
  20. },
  21. 'add_ie': ['Sina'],
  22. }
  23. # Additional example videos from different sites
  24. # Youku: http://video.weibo.com/v/weishipin/t_zQGDWQ8.htm
  25. # 56.com: http://video.weibo.com/v/weishipin/t_zQ44HxN.htm
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
  28. video_id = mobj.group('id')
  29. info_url = 'http://video.weibo.com/?s=v&a=play_list&format=json&mix_video_id=t_%s' % video_id
  30. info = self._download_json(info_url, video_id)
  31. videos_urls = map(lambda v: v['play_page_url'], info['result']['data'])
  32. # Prefer sina video since they have thumbnails
  33. videos_urls = sorted(videos_urls, key=lambda u: 'video.sina.com' in u)
  34. player_url = videos_urls[-1]
  35. m_sina = re.match(r'https?://video\.sina\.com\.cn/v/b/(\d+)-\d+\.html',
  36. player_url)
  37. if m_sina is not None:
  38. self.to_screen('Sina video detected')
  39. sina_id = m_sina.group(1)
  40. player_url = 'http://you.video.sina.com.cn/swf/quotePlayer.swf?vid=%s' % sina_id
  41. return self.url_result(player_url)