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.

48 lines
1.7 KiB

  1. # coding: utf-8
  2. import re
  3. import json
  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. u'url': u'http://video.weibo.com/v/weishipin/t_zjUw2kZ.htm',
  13. u'file': u'98322879.flv',
  14. u'info_dict': {
  15. u'title': u'魔声耳机最新广告“All Eyes On Us”',
  16. },
  17. u'note': u'Sina video',
  18. u'params': {
  19. u'skip_download': True,
  20. },
  21. }
  22. # Additional example videos from different sites
  23. # Youku: http://video.weibo.com/v/weishipin/t_zQGDWQ8.htm
  24. # 56.com: http://video.weibo.com/v/weishipin/t_zQ44HxN.htm
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url, flags=re.VERBOSE)
  27. video_id = mobj.group('id')
  28. info_url = 'http://video.weibo.com/?s=v&a=play_list&format=json&mix_video_id=t_%s' % video_id
  29. info_page = self._download_webpage(info_url, video_id)
  30. info = json.loads(info_page)
  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: 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', player_url)
  36. if m_sina is not None:
  37. self.to_screen('Sina video detected')
  38. sina_id = m_sina.group(1)
  39. player_url = 'http://you.video.sina.com.cn/swf/quotePlayer.swf?vid=%s' % sina_id
  40. return self.url_result(player_url)